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

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 run file .bat from job or sp
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

nord
Posting Yak Master

126 Posts

Posted - 11/29/2013 :  12:06:47  Show Profile  Reply with Quote
Hi,
I have batch file,how I can run this file from sp or sql job?
I have sp but doesnt run file:

ALTER PROCEDURE [dbo].[Active_bat]

AS
BEGIN
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
SET NOCOUNT ON;

DECLARE @myfile varchar(200)
SET @myfile = 'C:\Users\echepeleutser\Desktop\arhiv\a.bat'
EXEC master..xp_cmdshell @myfile


END
go

Thanks

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 11/29/2013 :  12:23:04  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
In a job you can run an operating system command.

What you have there should work if xp_cmdshell is enabled, the user running the command has permission to execute it and the file is on the server in that path.

try
exec master..xp_cmdshell 'dir C:\Users\echepeleutser\Desktop\arhiv\a.bat'

I suspect this will run under the sql server service account (if you are sa) and that doesn't have access to this folder?

Why are you setting the transaction isolation level? What do you expect that to do?

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nord
Posting Yak Master

126 Posts

Posted - 11/29/2013 :  12:37:15  Show Profile  Reply with Quote
I tried to run but error:
The job failed. Unable to determine if the owner (MAILSERVER\echepeleutser) of job execute has server access (reason: Could not obtain information about Windows NT group/user 'MAILSERVER\echepeleutser', error code 0x5. [SQLSTATE 42000] (Error 15404)).
I would like run .bat ,.bat run txt file download from sftp data
Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 11/30/2013 :  01:51:22  Show Profile  Reply with Quote
you can define a proxy account giving it required permissions and then configure it to execute xp_cmdshell
see this kb article

http://support.microsoft.com/kb/890775

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

nord
Posting Yak Master

126 Posts

Posted - 12/02/2013 :  13:24:17  Show Profile  Reply with Quote
Thanks
Go to Top of Page

nord
Posting Yak Master

126 Posts

Posted - 12/03/2013 :  17:25:20  Show Profile  Reply with Quote
Hi,
I have another ussue:
Tip: Enclose command names that contain spaces in quotation marks. For example: "command name" <arguments>.

what this mean?
Thanks
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.59 seconds. Powered By: Snitz Forums 2000