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

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 run file .bat from job or sp

Author  Topic 

nord
Posting Yak Master

126 Posts

Posted - 2013-11-29 : 12:06:47
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
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-11-29 : 12:23:04
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 - 2013-11-29 : 12:37:15
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

52326 Posts

Posted - 2013-11-30 : 01:51:22
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 - 2013-12-02 : 13:24:17
Thanks
Go to Top of Page

nord
Posting Yak Master

126 Posts

Posted - 2013-12-03 : 17:25:20
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
   

- Advertisement -