Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 running T-SQLquery in batch file
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

gangadhara.ms
Aged Yak Warrior

India
549 Posts

Posted - 01/31/2013 :  03:13:39  Show Profile  Reply with Quote
Hi All,

I am using below query to send email from batch

DECLARE @CMD_loop varchar(8000)
set @CMD_loop='ftp -i -s:E:\Tune\AT\cmds.txt ftp.XYZ.com
if %ERRORLEVEL%==0
EXEC master..xp_cmdshell 'SQLCMD -S Server\GANGA-i"C:\FTP\mail.SQL"'

where mail.sql consist of email sendign code which works perfectly in SSMS.

Please help i am getting below error

Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote c


Thanks,
Gangadhara MS
SQL Developer and DBA

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 01/31/2013 :  08:34:39  Show Profile  Reply with Quote
See if remote connections are indeed enabled on your server. In SQL 2005, it is in the Surface Are Configuration utility (under the SQL 2005 program group).
Go to Top of Page

gangadhara.ms
Aged Yak Warrior

India
549 Posts

Posted - 02/01/2013 :  02:21:13  Show Profile  Reply with Quote
Yes its enabled for Local and Remote connections -->using both TCP/IP and named pipes.

Thanks,
Gangadhara MS
SQL Developer and DBA
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/01/2013 :  07:49:17  Show Profile  Reply with Quote
Couple of thoughts/comments:

1. I assume that Server is server name and GANGA is the named instance.
2. The file C:\FTP\mail.SQL is on the local machine.

Are able to run any commands at all? For example:
xp_cmdshell 'sqlcmd -S Server\GANGA -Q "SELECT getdate()"'
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000