Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
At my job, I occasionally have to perform the following tasks:
Use Remote Desktop Connection to log on to a server.
Copy a set of files from a specific folder on my computer to a specific folder on the server.
Execute an SQL query on the server in SQL Server Management Studio, copied from a text file on my computer.
Log out of the server.
And then repeat for a whole bunch of other servers. This adds up to more than an hour, and I'm trying to figure out a way to automate it. What's the best way to go about doing this? I don't think Windows is as feature-rich as Linux when it comes to the command line, and I'm inexperienced with network protocols as it is.
You can automate this kind of behavior using batch files and scheduled tasks.
You can install the Command Line Utilities 11 for SQL Server from here:
http://www.microsoft.com/en-us/download/details.aspx?id=36433
And find reference material for the utilities it offers here:
http://technet.microsoft.com/en-us/library/ms162816.aspx
You will want to write a batch file that executes your actions in order. I recommend running a non-lethal SQL query against a test database while you develop your batch file, but it will be something like this:
::Copy the files
xcopy "\\server\c$\Source\*.*" "\\server\c$\Destination\"
::Set your MS SQL variables
set /p SName="Server Name"
set /p UName="User Name"
set /p Pwd="Password"
set /p DbName="Database Name"
::Execute your SQL query
sqlcmd -S %SName% -U %UName% -P %Pwd% -d %DbName% -i "c:\sqlCommand.sql"
Then you'll want to set it up to run as a Windows scheduled task by a user account (or service account) that has access to both of these network locations.
That should do the trick.
Related
This question already has answers here:
Run all SQL files in a directory
(14 answers)
Closed 1 year ago.
In the directory 'C:\scripts' I am having script files in '.sql' format.How to execute all these files at the time using sql query from my SQL SERVER MANAGEMENT STUDIO.
If this linked post contains the info you need then I suggest marking your post as duplicate of the linked one: Run all SQL files in a directory
Otherwise, check if this helps: http://www.sql-server-helper.com/tips/execute-sql-scripts-batch.aspx
make a batch file with anyname.bat and save it in the same directory, save it and run it.
this sample of mysql
#ECHO OFF
ECHO Running scripts
FOR %%i IN (*.sql) DO mysql -uroot -proot databasename< %%i
ECHO Finished!
pause
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
How can I backup my sybase tables and restore using command line?
please help me with the command using bcp
I have tried using sybase central GUI
Thanks.
Since you didn't specify whether you are running on Windows or Unix I'll try to cover both.
Unix
bcp is located in $SYBASE/$SYBASE_OCS/bin/
Windows
bcp is located in %SYBASE%\%SYBASE_OCS%\bin
Export
bcp DB_NAME..TABLE_NAME out TABLE_NAME.bcp -Sservername -Uusername -Ppassword -[c or n]
Choose either -c or -n depending if you want the file to be human readable or not. I recommend using -n unless you have a compelling need to use -c TABLE_NAME.bcp can be any filename, with any extension.
Import
$SYBASE/$SYBASE_OCS/bin/bcp DB_NAME..TABLE_NAME in TABLE_NAME.bcp -Sservername -Uusername -Ppassword -[c or n]
There are many more options and flags available, but these are the basics to get it to work.
More information abou the bcp utility can be found here:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc30191.1570/html/utilityguide/BABGCCIC.htm
and
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc30191.1570/html/utilityguide/X14951.htm
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
In SqlServer Management Studio, if we click on data database there is menu task > export data.
This help me to export this database to another server.
However, I need to run this wizard to complete this task and need to specify source and destination sever information every time that I want to use it.
I think it would be convenient if I could use command line to do the same task and write batch file to automate it.
Please could you help me give some suggestion or introduce me a command line program that can do this task since I googled search but not found any useful information.
Thank you so much.
U can use BCP Utility
BCP Out
BCP server.schema.TableName out c:\TableName.txt -c -t -T –SServerName -UUsername -Password
BCP In
BCP server.schema.TableName In c:\TableName.txt -c -t -T –SServerName -UUsername -Password
The 1st statement is to export the data to a csv file and BCP IN is used to import the data from csv file to Destination table
Here
-T stands for Trusted connection and -t represents field delimeter
You can write these BCP commands in batch file
Or you can create a simple ssis package for exporting the data
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm using VS2010 as a client for a TFS instance. I created a workspace, and need to map a TFS directory to a local directory - let's call the local directory "D:\aaa\bbb\ccc\ddd". When I navigate to "Manage Workspaces" and click "edit" to change the local directory to this path, I am presented with the following error: 1
This error occurs when I try to map: "D:\aaa", "D:\aaa\bbb", "D:\aaa\bbb\ccc".
Now, if I create a folder called: "D:\aaa\bbb\ccc1\ddd", the mapping works, and I do not receive this error.
Can anyone help? I've been pulling my hair out for about a day over this.
Thank you.
[EDIT01: I tried mapping all other folders under the D:\ drive, and only one other folder fails the mapping. I receive the same error as with "D:\aaa\bbb\ccc\ddd" ]
SQL Errors
First of all, you should not be receiving SQL Error 18054 (or any SQL errors) from TFS.
You should have your TFS administrator connect to the SQL server that hosts the master DB for your TFS server and run the following query:
select * from master.dbo.sysmessages where error > 50000
If this is a TFS2010 server, your TFS administrator may be able to use TFSConfig PrepSql to re-install the error messages.
If this is a TFS2008 server, your TFS administrator will need to open Add/Remove programs and run a repair on TFS.
Your actual problem
This sounds obvious at first, two
local paths cannot point to the same
place in the repository for the same
workspace. However, the one that
catches a lot of folks un-aware is
that you cannot have two repository
paths mapped to one local path on the
same computer.
In TFS, you cannot have two folders with overlapping mappings. Since D:\aaa\bbb\ccc\ddd is a sub-folder of D:\aaa, then you cannot add it.
One thing you can do though, is cloak folders so that they aren't part of the workspace mappings. In your case, you might want to map D:\aaa and add a cloak for all the other subfolders in that directory, except for D:\aaa\bbb.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a batch file on a Windows 2008 server that, when invoked from command line works fine. However, when I set a scheduled task to run this job, it does not work properly.
The task scheduler does show that that the task is getting run at regular intervals, it does not show any error. But, the batch file does not process what it is supposed to process.
Any ideas on how to fix this issue is most welcome
Windows Server 2008 will not run any batch file with quotation marks " inside the batch file.
See http://technet.microsoft.com/en-us/library/dd851678.aspx
I had a similar problem, my .bat file wouldn't correctly execute when I had the full file path in the "Program/script" field.
"D:\path\to\file\somebat.bat" didn't execute. (with quotes)
When I put D:\path\to\file\ (without quotes) in the Start in (optional): field and somebat.bat in Program/script: field somebat.bat executed correctly.
Go figure... not exactly sure why having "D:\path\to\file\somebat.bat" in the Program/script: won't work.
Maybe someone could shed some light on that?
In my case, I had 'Run whether user is logged on or not'. When I changed to 'Run only when user is logged on' it worked OK.
Make sure the task is running under an account with the necessary privileges. When you run a batch script from the command-line directly, it is running under your user account, which may have different permissions than the default account used for scheduled tasks.