If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Running an SQL Script from ASP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-28-04, 07:38
timfoster timfoster is offline
Registered User
 
Join Date: May 2004
Posts: 3
Running an SQL Script from ASP

Hi,

I've a complete mental block on this, I need to run a SQL Server script file from within an asp page.

Basically, I'm trying to create a series of tables/sp's. If I've got the script file (createtables.sql) how can I run it through asp?

I could copy the contents into my page and execute an ado command object, but I'd rather read and process the script in one go.
Reply With Quote
  #2 (permalink)  
Old 05-29-04, 00:04
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Not sure what your hangup is.... anything you want to do with SQL Server requires an ado connection. Then just execute an appropriate SQL statement.

Tim
__________________
Tim
Reply With Quote
  #3 (permalink)  
Old 05-29-04, 06:39
timfoster timfoster is offline
Registered User
 
Join Date: May 2004
Posts: 3
I've got a script saved as a text file that builds approx 20 tables and 100 stored procedures. What I want to do is execute the script file as one rather than write each CREATE TABLE statement as an ado command.

My text file is about 4000 lines long and so I want to open the text file and execute the contents. Is it just a case of reading each line of the text file and executing them in turn?

All the web hosting sites allow you to create a database script and upload the text file. It then runs the statements in the script and builds the tables etc. Thats what I'm after.
Reply With Quote
  #4 (permalink)  
Old 05-29-04, 13:37
MrWizard MrWizard is offline
Registered User
 
Join Date: Mar 2003
Location: Atlanta, GA
Posts: 191
Maybe you should post this question in the SQL Server forum. It seems to me perhaps you could put your textfile into a stored procedure, and then execute the stored procedure.... but that's just a guess.

Tim
__________________
Tim
Reply With Quote
  #5 (permalink)  
Old 05-30-04, 18:57
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
You open and read the file using the file system object. You can then build sql statements based on what your have read and execute them using ADO.

The problem would be identifying the different indivudal statements. I suspect that within your sql script file you have go's between the various statements, if this is the case you can break you commands up using that...

Read the file, if the line does not say "go" then add it to the previous ADO Command text. If it does say "go" execute the command and upon successful execution wipe the contents of the command text and go back to the start.....

Make sense? Does it answer your question??
Reply With Quote
  #6 (permalink)  
Old 06-02-04, 04:02
timfoster timfoster is offline
Registered User
 
Join Date: May 2004
Posts: 3
I was hoping there was a method to simply specify the script file and have ado run that file. I guess not. Looks like I'll have to read the file the way you say, rokslide.

Thanks anyway.

Tim
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On