Re: "exclusive access could not be obtained.." while restoring
From: Jim Young (thorium48_at_hotmail.com)
Date: 06/01/04
- Previous message: Jim Young: "Re: backing up to network share issue."
- In reply to: newbie: ""exclusive access could not be obtained.." while restoring"
- Next in thread: newbie: "Re: "exclusive access could not be obtained.." while restoring"
- Reply: newbie: "Re: "exclusive access could not be obtained.." while restoring"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 1 Jun 2004 13:32:52 -0700
What is probably happening is that you're application user is defaulting to
the database that your are attemping to restore. You can't restore a
database that is in use. You will need to find some way of changing the
database in use to the master database before performing the restore. One
way is to change the Initial Catalog value of your connection string to be
the master database.
Jim
"newbie" <anonymous@discussions.microsoft.com> wrote in message
news:7D202145-B997-4690-AFBB-CC02F3242106@microsoft.com...
> Hello,
>
> I am using MSDE with my application and providing our users UI to
backup/restore the database. My app has just 1 database and 1 login mapped
to 1 user (MyAppUser). Backup and restore functionality is using inline sql
commands. Backup works fine with something like this:
>
> Private Sub Backup()
> Dim cn As New SqlConnection(MyConnectionString)
>
> Try
> cn.Open()
> Dim cm As New SqlCommand
> With cm
> .Connection = cn
> .CommandType = CommandType.Text
>
> .CommandText = "BACKUP DATABASE MyDB TO DISK =
'D:\Backup\a.bak' WITH INIT"
> .ExecuteNonQuery()
> End With
> MsgBox("Database backed up successfully!")
> Catch ex As Exception
> MsgBox(ex.Message)
> Finally
> cn.Close()
> End Try
> End Sub
>
> but when I do restore using something like this:
> Private Sub Restore()
> Dim cn As New SqlConnection(MyConnectionString)
>
> Try
> cn.Open()
> Dim cm As New SqlCommand
>
> With cm
> .Connection = cn
> .CommandType = CommandType.Text
> .CommandText = "RESTORE DATABASE MyDB FROM DISK =
'D:\Backup\a.bak' WITH RECOVERY"
> .ExecuteNonQuery()
> End With
> MsgBox("Database restored successfully!")
> Catch ex As Exception
> MsgBox(ex.Message)
> Finally
> cn.Close()
> End Try
> End Sub
>
> I get the "exclusive access could not be obtained.. .. database is in use"
error message.
> I did "Use Master" in query analyser and ran the same restore sql command
and it worked fine. I do not know how to use "Use master" here in ado.net.
I know it has something to do with sp_Who but not sure how the syntax will
fit in.
>
> Note MyConnectionString is something like:
> "data source=(local)\MyCompany;initial catalog=MyDB;User ID = MyAppUser ;
Password = MyPassword"
>
> Please help. What should I do so that this works in my vb.net app.
>
- Previous message: Jim Young: "Re: backing up to network share issue."
- In reply to: newbie: ""exclusive access could not be obtained.." while restoring"
- Next in thread: newbie: "Re: "exclusive access could not be obtained.." while restoring"
- Reply: newbie: "Re: "exclusive access could not be obtained.." while restoring"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|