running script in mssql local server group via batch file - sql-server

A created a mssql local server group containing all our production server. And now i am planning to automate running the script via batch file, is there a way to connect/run my script in my local server group via batch file?

Yes, you can use the sqlcmd command line utility in your batch file to connect and execute queries and / or SQL script files.

Related

How do I configure Snowsql to automatically run a sql script as soon as it connects Snowflake?

I setup my snowsql in mac and it works fine for general sql commands. What I'm trying to achieve here is to config the snowsql automatically run a pre-configured sql script upon the connection is established.
It's similar to Aginity's pre-execute script configuration in the connection property page.
Appreciate any advice.
Create batch file , to wrap up snowsql run which will connect to SNowflake and subsequent run command to run the default sql script.

Running a batch file from SQL Server Agent Job

I have the following file placed directly in the C drive on my SQL server:
The job is configured as below
But when i run the job it just loops and loops. If I run the file manually it works perfectly. What am I doing wrong?
I had the same issue. I did resolve it by using below command and giving permissions to the .bat file for this user NT Service\SQLSERVERAGENT
cmd.exe /c E:\tools\test.bat

How to open .sql file at startup in SQL Server Management Studio?

I'm looking to open specific .sql files that have multiple select statements on specific servers at startup in SQL Server Management Studio 2014.
For example, I want to open file 'EmQueries.sql' when I open server sqlemdata9. When I open server sqlplant2, I would like to see file 'PlantQueries.sql' open at startup.
How can I accomplish something like this?
You can achieve the following procedure with Command Line Process, will help you connect to different databases related to specific files and user credentials.
This is Easy with command line (cmd)
ssms "C:\Users\Wizard\Documents\SQL Server Management Studio\query.sql" -S ServerAddressOrIP -d Database -U Username -P Passwordhere
Copy the following line to (.bat) batch file format and run it.

How to run batch file on remote server

I am using 2 machine one local and other remote from local I have used SSIS package to execute batch file on remote server using wmi process but my problem is that batch file is executing locally instead of remote
Check out System Internals which was bought by Microsoft in the mid 200X.
I used the psexec command to run remote batch files via VB script. I am sure you can do the same with SSIS.
http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
You need rights of course on the remote machine (RM1) and a local copy of psexec.
psexec \\RM1 cmd
This test code runs a command prompt on the remote machine. Parameters like user/pwd will have to be passed.
Good luck in you coding efforts.

Script MSSQL query on remote server

I have a bit of an odd requirement to script some MSSQL queries on a remote host.
I need to be able to run these queries via an Enterprise Scheduler, in this case TIDAL 6.1, and save the output of the query as a CSV or XML file.
I'm assuming I would have to set up a local SQL server to act as a bridge to the remote host, and I'm hoping there is a way to tell the script/query to output the results as a file on the local host.
You need to have SQL Client in the machine where you will be running this query. You can run the SQLCMD command below to run the query and save output to file.
sqlcmd -S(servername) -E -i(sql file) -o(output filename) -d(databasename) -s,
-E option is for trusted connection
Hope this helps.

Resources