Saps said:
Hi all. Can anyone help me here. I have loads of .sql files and i need
a way to call these from my asp page so the user can run them from the
browser. Meaning i have a page with a list of all scripts. each when
clicked i am able to run the script. so HOW and what do i do to call
and run the .sql
Thanks
You would probably be better off if you encapsulated the T-SQL in those
script files into stored procedures which can easily be executed from an ASP
file via ADO.
CREATE PROCEDURE RunMySQL1 AS
<copy and paste your sql script file contents here>
Run the above script on your server, grant the appropriate permissions to
the users that need to run it, and, in your ASP page:
dim cn, proc
proc = request.form("selectedscript")
set cn=createobject("adodb.connection")
cn.open <your connection string>
'
http://www.aspfaq.com/show.asp?id=2126
select case proc
case "1": cn.RunMySQL1
...
case else:
end select
cn.close: set cn=nothing
What is your perceived advantage in using script files instead of stored
procedures?
If you are stuck with script files, you have several options:
1. As stated by MFedatto, you can use FSO to read the sql from the file
(
http://www.aspfaq.com/show.asp?id=2039) and execute it using an ADO
connection object. With this approach, you need to take care to strip out
non-T-SQL words like "GO"
2. Depending on your version of SQL Server, you can install either isql or
osql (look them up in SQL Books Online ... BOL) on your web server and use
wscript.shell to run the script files using the appropriate tool for your
sql server.
3. Again, depending on your version of SQL Server, install either SQL-DMO or
SMO (if using SQL 2005) and use them to run your script files (look them up
in BOL)