Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running SQL Attach Stored Procedure from ASP

Status
Not open for further replies.

wbwillson

Technical User
Oct 7, 2002
52
GB
I'm fairly new to both ASP and SQL Server 2000, but heres my problem. I have a developer PC which is not on our network, I have SQL Server installed on this machine. I want to be able to Detach the SQL database files (.mdf & .ldf) and then copy them to a CD-RW, move them to my networked PC and then have my ASP script run the SQL attach stored procedure to re-attach the database. (note: I do not have SQL Server installed on my network PC, nor do I have administrator rights, just basic user rights which is why I need to use ASP to run the stored procedure remotely) Here what I'm thinking I should use:
[blue]
<%
Dim objConn, objDBConn, objCmd, rs, strSQL, strServer, strUID, strPWD

set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)

strServer = Application(&quot;WebApps&quot;)
strUID = Application(&quot;Webuser&quot;)
strPWD = Application(&quot;Webuser&quot;)

objDBConn= &quot;DRIVER={SQL Server};SERVER=&quot; & strServer & &quot;;UID=&quot; & strUID & &quot;;PWD=&quot; & strPWD
objConn.Open objDBConn

[red]'** THIS IS WHERE I'M LOST HOW CAN I RUN THE BELOW T-SQL COMMAND FROM ASP?[/red]

[green]EXEC sp_attach_db @dbname = 'Test',
@filename1 = 'C:\TempData\Data\Test_data.mdf',
@filename2 = 'C:\TempData\Data\Test_log.ldf'[/green]


Set rs = objCmd.Execute

set objCmd = nothing
%>[/blue]


Bill
 
strSQL = &quot;EXEC sp_attach_db @dbname = 'Test', @filename1 = 'C:\TempData\Data\Test_data.mdf', @filename2 = 'C:\TempData\Data\Test_log.ldf'&quot;
objConn.Execute(strSQL)
 
Thanks, I'll give that a try! Basically I just wrap then entire procedure in quotes like standard SQL statement.

Bill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top