Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Attach and detach a database programmatically
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01097394
Message ID:
01097397
Views:
15
Hi Boris,
Works like a charm!
Thanks for your help.

>>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;])
>
>*** Detach Database
>TEXT TO lcSql2 NOSHOW
>     USE [master]
>     EXEC master.dbo.sp_detach_db @dbname = N'Test', @keepfulltextindexfile=N'true'
>ENDTEXT
>
>? SQLEXEC(sqlh, lcSql2)
>
>*** Wait here just to check with Enterprise manager that the DB is detached
>WAIT WINDOW "Stop"
>
>
>*** Attach DB again
>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
>     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)
>
_______________________________________________________________
Testing displays the presence, not the absence of bugs.
If a software application has to be designed, it has to be designed correctly!
_______________________________________________________________
Vladimir Zografski
Systems Analyst
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform