Solved

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

Posted on 2015-01-23
7
94 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 45

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 45

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

743 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

12 Experts available now in Live!

Get 1:1 Help Now