How To Execute A Sql Script File From ADO.NET Using VB.NET

S

SqlJunkies User

I have a sql script file containing a number of batch commands to create a new database with 50 tables. Is there anyway i can use ado.net to open this file and execute the sql command in side in a batch format. Basically I would like to execute the myscriptfile.sql from vb.net using ado.net
 
L

Lloyd Sheen

You will have to break up the script into it's portions. Remember that GO
is not a T-SQL word. If you know that each GO is on its own line then you
can split the text. Then execute each set of commands within the batch. If
you are expecting no results then use the SQLCommand.ExecuteNonQuery, this
will return the row count.

Ensure that you wrap the execution to ensure that errors are caught. If you
have PRINT statements you will have to capture the InfoMessage event of the
open connection.

Lloyd Sheen


SqlJunkies User said:
I have a sql script file containing a number of batch commands to create a
new database with 50 tables. Is there anyway i can use ado.net to open this
file and execute the sql command in side in a batch format. Basically I
would like to execute the myscriptfile.sql from vb.net using ado.netsupports Post Alerts, Ratings, and Searching.
 
W

William Ryan eMVP

http://www.knowdotnet.com/articles/ddl.html

Good luck,

Bill

www.devbuzz.com
www.knowdotnet.com

SqlJunkies User said:
I have a sql script file containing a number of batch commands to create a
new database with 50 tables. Is there anyway i can use ado.net to open this
file and execute the sql command in side in a batch format. Basically I
would like to execute the myscriptfile.sql from vb.net using ado.netsupports Post Alerts, Ratings, and Searching.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top