473,325 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Using sql to execute a batch file

Is it possible to use sql to execute a batch file? I would like to
execute the following "C:\BTW\bartend.exe /f=C:\BTW\Toolbox\Formats
\carnum.btw /p", 6

Thanks,

Matt

Aug 9 '07 #1
6 5320
You can look at xp_cmdshell. Note that no program run that way can
open any sort of window, or prompt the "user" for anything at all.

You may also want to look into running it as a job.

Roy Harvey
Beacon Falls, CT

On Thu, 09 Aug 2007 15:44:36 -0000, mcolson <mc*********@gmail.com>
wrote:
>Is it possible to use sql to execute a batch file? I would like to
execute the following "C:\BTW\bartend.exe /f=C:\BTW\Toolbox\Formats
\carnum.btw /p", 6

Thanks,

Matt
Aug 9 '07 #2
On Aug 9, 1:26 pm, Roy Harvey <roy_har...@snet.netwrote:
You can look at xp_cmdshell. Note that no program run that way can
open any sort of window, or prompt the "user" for anything at all.

You may also want to look into running it as a job.

Roy Harvey
Beacon Falls, CT

On Thu, 09 Aug 2007 15:44:36 -0000, mcolson <mcolson1...@gmail.com>
wrote:
Is it possible to use sql to execute a batch file? I would like to
execute the following "C:\BTW\bartend.exe /f=C:\BTW\Toolbox\Formats
\carnum.btw /p", 6
Thanks,
Matt
When I use the xp_cmdshell to try and run the bat file, i get an
output saying access denied. It should be noted that I am using sql
server 2005 express. Is this why. When I try to copy the file to
another location, i get 0 copied. I am able to dir the directory just
fine.

Aug 9 '07 #3
On Thu, 09 Aug 2007 21:23:07 -0000, mcolson <mc*********@gmail.com>
wrote:
>When I use the xp_cmdshell to try and run the bat file, i get an
output saying access denied. It should be noted that I am using sql
server 2005 express. Is this why. When I try to copy the file to
another location, i get 0 copied. I am able to dir the directory just
fine.
I am not familiar with Express, but I don't think it is any different
in this area. What is important to remember is that any command run
through xp_cmdshell is running under the account designated for that,
and that is the account that needs the permissions. Running
xp_cmdshell 'set' and inspecting the results should tell you the
account being used.

While it does not appear to be your problem it is worth noting also
that xp_cmdshell runs in a context without any mapped drives, so any
files on a network drive must be referenced using a UNC path of the
form \\servername\sharename\folder...

Roy Harvey
Beacon Falls, CT
Aug 10 '07 #4
On Aug 10, 3:23 pm, Roy Harvey <roy_har...@snet.netwrote:
On Thu, 09 Aug 2007 21:23:07 -0000, mcolson <mcolson1...@gmail.com>
wrote:
When I use the xp_cmdshell to try and run the bat file, i get an
output saying access denied. It should be noted that I am using sql
server 2005 express. Is this why. When I try to copy the file to
another location, i get 0 copied. I am able to dir the directory just
fine.

I am not familiar with Express, but I don't think it is any different
in this area. What is important to remember is that any command run
through xp_cmdshell is running under the account designated for that,
and that is the account that needs the permissions. Running
xp_cmdshell 'set' and inspecting the results should tell you the
account being used.

While it does not appear to be your problem it is worth noting also
that xp_cmdshell runs in a context without any mapped drives, so any
files on a network drive must be referenced using a UNC path of the
form \\servername\sharename\folder...

Roy Harvey
Beacon Falls, CT
Sql is setup as a Network Service. I could change it to a local user,
but would prefer not to. I'm trying to setup a credentials named
"Matt". In here I have entered the login and password for an accepted
user of the file. How do I tell the stored procedure to use this
credential when I am running the bath file?

Thanks,

Matt

Aug 15 '07 #5
On Wed, 15 Aug 2007 17:28:16 -0000, mcolson <mc*********@gmail.com>
wrote:
>Sql is setup as a Network Service. I could change it to a local user,
but would prefer not to. I'm trying to setup a credentials named
"Matt". In here I have entered the login and password for an accepted
user of the file. How do I tell the stored procedure to use this
credential when I am running the bath file?
I have no idea, sorry.

Roy Harvey
Beacon Falls, CT
Aug 15 '07 #6
mcolson (mc*********@gmail.com) writes:
Sql is setup as a Network Service. I could change it to a local user,
but would prefer not to. I'm trying to setup a credentials named
"Matt". In here I have entered the login and password for an accepted
user of the file. How do I tell the stored procedure to use this
credential when I am running the bath file?
Have a look at xp_cmdshell and sp_xp_cmdshell_proxy_account in Books
Online. By setting up a proxy account and not run as sysadmin, you may
be able to work around the issue.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Aug 15 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: den 2005 | last post by:
Hi Everybody, Is anybody knows how to Hide Execution of batch file at background? I mean without displaying the DOS Prompt window while batch file is being executed. I used code below to execute...
4
by: Bill | last post by:
I need help closing a CMD window when it is executed from Access. 1) The batch file is called from Access. 2) Access closes, 3) the batch runs a copy of the access database (creating a backup)...
3
by: KRK | last post by:
I am having one batch file and using this I can start my Server. It will execute all exes while starting. Now my question is how to debug my exe using this batch file?? Is it possible to execute this...
2
by: DB | last post by:
Hi All, I have to execute dos command containing batch file using asp.net application. Code for batch file execution is working properly when I tried it with console application but same code...
3
by: Chris | last post by:
Hi, How can I execute a batch file form asp.net app. I have a form which a user uploads a text file. after the file is uploaded I want a batch file to then execute and do some work. Thanks
0
by: Elroyskimms | last post by:
I need to execute a batch file via ASP.Net. In my VB.Net code, I'm using System.Diagnostics.Process to call the batch file and its appropriate command line arguments. I'm using...
2
by: RaviRajhulk | last post by:
I have tried executing executing a batch file from a perl code using system("start c:\\temp\\sample.bat") but it is not executing ,Is there any way to execute batch file from a perl code
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
1
by: Ira Sinha | last post by:
I have created a batch file, which is using 7z command to encrypt and compress a file. The command in the batch file is 7za -TZIP a -p I am able to run the batch file successfully from the...
2
by: huiling25 | last post by:
I tried for several days, but none can work. IE keep showing yellow exclamation mark at the status bar after clicking "Submit" and batch file cannot be executed. The HTML file and batch file is in...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.