Link to home
Start Free TrialLog in
Avatar of itmtsn
itmtsn

asked on

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

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.
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itmtsn
itmtsn

ASKER

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?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itmtsn

ASKER

I tried the same command without the instance name and it worked fine. Thanks for the help all.