Solved

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

Posted on 2015-01-23
7
100 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 51

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
Myth Busting: MongoDB Scalability (it scales!)

I was talking with one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. He mentioned to me that several customers have been telling him that “MongoDB doesn’t scale!” MongoDB’s scalability was in question?

My response was, “Is that a joke?"

 
LVL 51

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

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

631 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