running sql script from ASPx page

L

LIN

Is it possible to run a big .sql file - SQL script to create a database from
a ASPx page? If yes, please advice how can I achieve this?

Thanks!

LIN
 
J

James Hokes

LIN,

0.) Write your SQL Script, and save to disk.
1.) Create the aspx page.
2.) Create an ADO connection in the aspx page.
3.) Open the ADO connection.
4.) Load the SQL Script from disk using FSO & TextStream.
5.) Run the script using the ADO connection's Execute method.
6.) Close connection
7.) End Script
8.) Lather, rinse, repeat

James Hokes
 
L

LIN

great. good idea. But how do I exactly use the textstream object to read
line by line and execute.
Do I need to put a for loop or something? Please advice.

Thanks a ton for the help. Its much appreciated.

LIN
 
L

LIN

I figured how to read all the lines but not sure how to execute it.. i
stored it in a variable called STR and passed it to execute statement.

Please advice.

Thanks
LIN
 
D

Dan Boylett

LIN said:
I figured how to read all the lines but not sure how to execute it.. i
stored it in a variable called STR and passed it to execute statement.

Please advice.

Create a command object, set it's commandtext to be your variable, Execute
it.

MSDN has lots (and lots and lots) of examples of ADO.NET commands, datasets
and connections.
 
L

LIN

yes I am using CommandText only .. the problem is I am reading from a .SQL
file and hence I need to execute multiple lines. Using FSO i am storing the
string in a variable - however the string concatinates the whole SQL script
and code doesn't seem to work.

What am I doing wrong?

LIN
 
D

Dan Boylett

LIN said:
yes I am using CommandText only .. the problem is I am reading from a .SQL
file and hence I need to execute multiple lines. Using FSO i am storing the
string in a variable - however the string concatinates the whole SQL script
and code doesn't seem to work.

What am I doing wrong?

LIN

Have you tried debugging what you're pulling in from the file, before you
execute it?

Also, are you reading the file one line at a time, or the whole lot? If it's
one line at a time, you will need to add in spaces after each line,
otherwise you'll get syntax problems.
 
V

Vlad Vissoultchev

try to split the script on each vbCrLf & "GO". execute each split part
separately.

HTH,
</wqw>
 

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

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,105
Latest member
sheetaldubay7750ync
Top