Solved

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

Posted on 2015-01-23
7
99 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 50

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 50

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
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.

734 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