Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Attach and detach a database programmatically
Message
De
19/02/2006 10:14:15
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01097394
Message ID:
01097396
Vues:
17
This message has been marked as the solution to the initial question of the thread.
>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)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform