Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Attach and detach a database programmatically
Message
 
À
19/02/2006 10:14:15
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01097394
Message ID:
01097397
Vues:
16
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform