Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I executing a .SQL file from a specific PC

Posted on 2015-01-23
7
Medium Priority
?
104 Views
Last Modified: 2015-01-26
Hi,

I have a .SQL query that queries a couple of tables and emails the results to an email address. This works fine from within SQL Management Studio 2012.

I have saved this query as a .SQL file and would like to run it from a specific workstation on our domain.

What is the best way to go about this? VBS, BAT, another?

Also what security rights will the end user/Station need in order to run this command and will they also need the Management Tools installed so that they can run SQLCMD.exe?

Many thanks in advance.
0
Comment
Question by:itmtsn
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 52

Accepted Solution

by:
Vitor Montalvão earned 600 total points
ID: 40566170
If your SQL Server instance IS NOT Express Edition, you can create a job and schedule the execution of the script.
Or else you can create a schedule task and run the script using the sqlcmd utility:
sqlcmd -S ServerName\InstanceName -i PathAndScriptName.sql

Open in new window

0
 
LVL 14

Assisted Solution

by:nishant joshi
nishant joshi earned 600 total points
ID: 40566171
You can use SSIS. It will be best suited for you.

User for each file enumerator for .sql files.kept .sql files at your domain nework location.

use execute sql task with connection to execute received file in for each file enumerator.


Thanks,
Nishant
0
 
LVL 25

Assisted Solution

by:Lee Savidge
Lee Savidge earned 300 total points
ID: 40566187
I'd set up a SQL job and get it to run on a schedule. If you wanted to run it from a specific computer, you'd need to install SQL Express so you could have the correct software on the machine.

What are you hoping to acheive? Is this something that is run adhoc or regularly?
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 52

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 600 total points
ID: 40566195
If you wanted to run it from a specific computer, you'd need to install SQL Express so you could have the correct software on the machine.
No need to. It will need MSODBC for SQL Server and SQLCmdLnUtil and then schedule the sqlcmd utility as I mentioned above.
0
 

Author Comment

by:itmtsn
ID: 40570374
Thanks for the suggestions. If I execute from the command line with the command:

sqlcmd -E -S SERVER\MSSQLSERVER -i P:\path\test.sql

I get the following error:

Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : SQL Server Network Interfaces: Connection string is not valid [87]. .
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login timeout expired.
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and i
f SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

I've followed various guides to make sure firewall is open, tested with it off, have enable the TCP connections. Any ideas?
0
 
LVL 14

Assisted Solution

by:nishant joshi
nishant joshi earned 600 total points
ID: 40570397
Hey,
Here only three check required:
1.check server name correctly supplied.if you are pointing to local server.you can write localhost\mssqlserver.
2.file path correction.
3.user has access on sql server.you are using Windows authentication so make sure that user has permission. Or try to run cmd using administrator account.
0
 

Author Comment

by:itmtsn
ID: 40570407
I tried the same command without the instance name and it worked fine. Thanks for the help all.
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question