anhnguyen1999
Programmer
Hi all,
I tried to detach a current database so that I can attach it with different set of database file (.mdf and .ldf). But it gave me the error
"Cannot detach the database 'TESTING' because it it currently in use"
Anyone know how to fix the problem?
Here is my code
Set goSQLServer = New SQLDMO.SQLServer
goSQLServer.LoginTimeout = -1 '-1 default (60) seconds
' Connect to the Server
' Use NT Authentication
goSQLServer.LoginSecure = True
goSQLServer.AutoReConnect = False
' Now Connect
goSQLServer.Connect "(local)"
'after login success msg, then I try to detach database 'TESTING' that current attached to "c:\testing1.mdf" and "c:\testing1.ldf"
goSQLServer.DetachDB "TESTING"
'planning to attach database file after detaching
goSQLServer.AttachDB "TESTING", "c:\testing2.mdf"
goSQLServer.AttachDB "TESTING", "c:\testing2.ldf"
Thanks a lot
I tried to detach a current database so that I can attach it with different set of database file (.mdf and .ldf). But it gave me the error
"Cannot detach the database 'TESTING' because it it currently in use"
Anyone know how to fix the problem?
Here is my code
Set goSQLServer = New SQLDMO.SQLServer
goSQLServer.LoginTimeout = -1 '-1 default (60) seconds
' Connect to the Server
' Use NT Authentication
goSQLServer.LoginSecure = True
goSQLServer.AutoReConnect = False
' Now Connect
goSQLServer.Connect "(local)"
'after login success msg, then I try to detach database 'TESTING' that current attached to "c:\testing1.mdf" and "c:\testing1.ldf"
goSQLServer.DetachDB "TESTING"
'planning to attach database file after detaching
goSQLServer.AttachDB "TESTING", "c:\testing2.mdf"
goSQLServer.AttachDB "TESTING", "c:\testing2.ldf"
Thanks a lot