Results 1 to 6 of 6
  1. #1
    Join Date
    May 2004
    Posts
    3

    Unanswered: 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.

  2. #2
    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

  3. #3
    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.

  4. #4
    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

  5. #5
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    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??

  6. #6
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •