Solved

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

Posted on 2015-01-23
7
95 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 46

Accepted Solution

by:
Vitor Montalvão earned 200 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 200 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 100 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 46

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 200 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 200 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now