Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Attach and detach a database programmatically
Message
From
19/02/2006 10:07:22
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01097394
Message ID:
01097395
Views:
15
>I want to attach and detach a database in SQL SERVER 2000 programmatically with VFP 9 SP1.
>Is it possible?
>
>TIA
sqlh = SQLSTRINGCONNECT([Driver={SQL Server};Server=Boris;Trusted_Connection=yes;])
TEXT TO lcSql NOSHOW
     USE [master]
     CREATE DATABASE [Test] ON 
       ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test.mdf' ),
       ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Test_log.ldf' )
     FOR ATTACH
ENDTEXT
TEXT TO lcSql2 NOSHOW
     if not exists (select name from master.sys.databases sd where name = N'Test' and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [Test].dbo.sp_changedbowner @loginame=N'BORIS\Boris1', @map=false
ENDTEXT
? SQLEXEC(sqlh, lcSql)
? SQLEXEC(sqlh, lcSql2)
:-)

no error handling included
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform