Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 restore database using vb.net

Author  Topic 

meenasoni
Starting Member

2 Posts

Posted - 2009-03-23 : 06:11:47
Hi Everyone,

Using SQL Server 200 and VB.Net 2005

I am trying to use SQLDMO dll to back up and restore a database. The backup side seems to work OK as I can back up to a device or file. When I try to restore then I hit a problem.

The code..

Dim MySQLServer As New SQLDMO.SQLServer
Dim MyRestore As New SQLDMO.Restore

With MyRestore

.Files = "C:\SQLBackup\Contacts.bkp"
.Database = "Contacts"
.ReplaceDatabase = True

MySQLServer.LoginSecure = True
MySQLServer.Connect(MyLocal.SQLServer, _ADMINLOGIN, _ADMINPASS)

.SQLRestore(MySQLServer) (ERROR HERE)

End With

The error I am geting is -
[Microsoft][ODBC SQL Server Driver][SQL Server]Exclusive access could not be obtained because the database is in use.
[Microsoft][ODBC SQL Server Driver][SQL Server]RESTORE DATABASE is terminating abnormally.

The database I am trying to restore is on another PC on my LAN and I have checked and there is only one user in the database at the time of the error
Your help would be most appreciated.

meena soni

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-03-23 : 07:46:51
Maybe the Database Contacts is the default database for your connect?
Then you have to connect to the master database so Contacts is not in use...

Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -