running sql script from ASPx page

  • Thread starter Thread starter LIN
  • Start date Start date
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
 
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
 
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
 
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
 
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.
 
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
 
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.
 
try to split the script on each vbCrLf & "GO". execute each split part
separately.

HTH,
</wqw>
 
Back
Top