Wednesday, March 28, 2012

Restore DB Failed

SQL server 2005
Try to restore database,
Can not restore it because Do not have exclusive access.
Have .DLL constantly connect to the database.
How could I restore database without stop SQL service
Thanks in advance
JeffWhat database you are trying to restore. If it is a user database probably
the database name which you are trying to restore is already in the same
server and used by some users.
If you want to overwrite the database then use the below command to set the
database to single user mode and then try restoring.
ALTER DATABASE <DBNAME> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
Thanks
Hari
"jeff" wrote:

> SQL server 2005
> Try to restore database,
> Can not restore it because Do not have exclusive access.
> Have .DLL constantly connect to the database.
> How could I restore database without stop SQL service
> Thanks in advance
> Jeff
>|||On Feb 21, 12:40 pm, Hari Prasad
<HariPra...@.discussions.microsoft.com> wrote:
> What database you are trying to restore. If it is a user database probably
> the database name which you are trying to restore is already in the same
> server and used by some users.
> If you want to overwrite the database then use the below command to set th
e
> database to single user mode and then try restoring.
> ALTER DATABASE <DBNAME> SET SINGLE_USER WITH ROLLBACK IMMEDIATE
> Thanks
> Hari
>
>
It is a user database, and the name is already being used. Trying to
restore by overwrite the existing one.
But if set to single_user mode, will that affect later connection? How
to find out if it is already in single mode?
Thanks|||Hello,
select databaseproperty('Master','IsSingleUser'
)
If it return 1 then database is in single user mode. Change the DBname to
yours.
Thanks
Hari
"jeff" wrote:

> On Feb 21, 12:40 pm, Hari Prasad
> <HariPra...@.discussions.microsoft.com> wrote:
> It is a user database, and the name is already being used. Trying to
> restore by overwrite the existing one.
> But if set to single_user mode, will that affect later connection? How
> to find out if it is already in single mode?
> Thanks
>|||be sure your own connection is not using the db. do 'use master' to switch
db context for your own connection before initiating the restore.
-oj
"jeff" <jeffzhang44@.gmail.com> wrote in message
news:1172080049.968263.170350@.q2g2000cwa.googlegroups.com...
> On Feb 21, 12:40 pm, Hari Prasad
> <HariPra...@.discussions.microsoft.com> wrote:
> It is a user database, and the name is already being used. Trying to
> restore by overwrite the existing one.
> But if set to single_user mode, will that affect later connection? How
> to find out if it is already in single mode?
> Thanks
>|||On Feb 21, 3:23 pm, "oj" <nospam_oj...@.home.com> wrote:
> be sure your own connection is not using the db. do 'use master' to switch
> db context for your own connection before initiating the restore.
> --
> -oj
>
What does this mean? Could you be more specific? Thanks|||"jeff" <jeffzhang44@.gmail.com> wrote in message
news:1172091728.199686.230500@.s48g2000cws.googlegroups.com...
> On Feb 21, 3:23 pm, "oj" <nospam_oj...@.home.com> wrote:
> What does this mean? Could you be more specific? Thanks
>
Common mistake (I'm sure all the regulars have done it at least once) is to
be currently in the database you want to restore.
So you are effectively the user blocking your restore.
do a USE MASTER before the restore statement to eliminate this. (and make
sure enterprise manager isn't using the database in question.)
Greg Moore
SQL Server DBA Consulting
sql (at) greenms.com http://www.greenms.com

No comments:

Post a Comment