Re: Creating a VBScript to execute .SQL file
From: Bob Barrows [MVP] (reb01501_at_NOyahoo.SPAMcom)
Date: 12/24/04
- Next message: Ole Rasmussen: "What's wrong here"
- Previous message: Bob Barrows [MVP]: "Re: OLE /COM programming"
- In reply to: htran: "Re: Creating a VBScript to execute .SQL file"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 24 Dec 2004 07:45:26 -0500
htran wrote:
> As you have indicated, I have read that you can connect to a data
> source and then open the SQL file to process the SQL commands. If
> this is possible, I would greatly appreciate some sample VBScript
> codes. Thank you.
If the SQL client tools are installed on the machine that is running the
script, you can use the WshShell object to shell out and run external
programs using the Run method. You can find sample code for using this
object in the WSH (Windows Scripting Host) documentation. If you don't have
the documentation, you can read it online at msdn.microsoft.com/library
(drill down into Web Development to Tools and Scripting). Alternatively you
can download and install the doc umentation from http://tinyurl.com/7rk6 .
Using WshShell, you can run the osql utility included with the SQL Server
client tools installation to run your script file. More details about osql
can be found in SQL Books Online (BOL). If you don't have BOL installed, you
can get a downloadable version of them from
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Alternatively, you can use FSO (FileScriptiingObject) to open your script
file and read its contents into a variable, and then use the ADO Connection
object's Execute method to execute the script contained in the varaible. You
need to be careful and use Replace to remove any GO statements in the
script.
Bob Barrows
-- Microsoft MVP - ASP/ASP.NET Please reply to the newsgroup. This email account is my spam trap so I don't check it very often. If you must reply off-line, then remove the "NO SPAM"
- Next message: Ole Rasmussen: "What's wrong here"
- Previous message: Bob Barrows [MVP]: "Re: OLE /COM programming"
- In reply to: htran: "Re: Creating a VBScript to execute .SQL file"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|