Groups | Blog | Home
all groups > sql server clients > november 2004 >

sql server clients : osql or isql to run a batch remotely


Stewart Saathoff
11/30/2004 3:35:22 PM
Hello,

I have a collection of SQL Scripts that I would like to execute using a
batch file from a remote machine. Does anyone have any suggestions? I
think that I could use osql or isql, but I have never done that before. I
would appreciate any assistance.

Stewart

David Gugick
11/30/2004 4:52:07 PM
[quoted text, click to view]

I'm unclear about what is where...

Where is the file you want to execute located?
Do you want to run this file from a remote client or do you want to run
the file as though it were running directly on the server?

You can kick off OSQL from a stored procedure or a SQL Agent job on the
server. You could kick off OSQL from a client PC and execute a script
file that resides on the client PC. I would say that if the script file
is large, you'll get better performance running it from the server.


--
David Gugick
Imceda Software
www.imceda.com
Stewart Saathoff
11/30/2004 4:58:10 PM
ok, Let me be more clear.

I have a very large SQL Statement that needs to be run on the server.

Ideally the client will sit on their workstation and double-click on a file.
That file should execute the SQL statement on the server. I am pretty
positive that I can do all of this using osql, however I am unclear how I
can do this using a batch file. I don't want the users to have to type a
considerable amount and I definately do not want them to have to learn osql
or sql commands to do this...

Stewart


[quoted text, click to view]

David Gugick
11/30/2004 6:20:45 PM
[quoted text, click to view]


If you have to run the SQL batch from a client PC, you can use OSQL.
There's an option for submitting a file to run. The command-line
interface is fairly straightforward and documented in BOL.

--
David Gugick
Imceda Software
www.imceda.com
Craig Kelly
12/1/2004 2:25:34 AM
<snip>

[quoted text, click to view]

<snip>

Stewart,

Assuming you get this to work at the command prompt...

osql -SBigBox -Uuser -Ppwd -ddbname -i somefile.sql -o somefile.log

You can just paste it into a BAT file: that's it. You can use @ECHO OFF,
print out message, etc to pretty it up but that's pretty much all you need.

You would need a file with your SQL statement where the BAT file runs
(ideally the same folder). If that's not acceptable, then you could put the
statement in a stored proc and call the proc by name instead of using the
input file.

Craig

Stewart Saathoff
12/2/2004 1:15:48 PM
Thank you all for your help. Everything works great.


[quoted text, click to view]

AddThis Social Bookmark Button