Saturday, July 11, 2015

Error: Restore failed for Server 'ServerName\InstanceName'. System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use.

Hello Guys..!

Some times while restoring Ax database we get below error.

Error: Restore failed for Server 'ServerName\InstanceName'.  System.Data.SqlClient.SqlError: Exclusive access could not be obtained because the database is in use. 


Reason : Ax Database is using by some service.

Solution : Kill all active connections which are using Ax database

Change the database name in the query and execute .

 
DECLARE @dbname NVARCHAR(128)
SET @dbname = 'DB name here'
 -- db to drop connections
DECLARE @processid INT
SELECT  @processid = MIN(spid)
FROM    master.dbo.sysprocesses
WHERE   dbid = DB_ID(@dbname)
WHILE @processid IS NOT NULL
    BEGIN
        EXEC ('KILL ' + @processid)
        SELECT  @processid = MIN(spid)
        FROM    master.dbo.sysprocesses
        WHERE   dbid = DB_ID(@dbname)
    END




That's It...


@Rahul Talasila


 

No comments:

Post a Comment

Why do users often get confused about Dynamics 365 Customer Engagement (D365 CE), Dataverse, and the Power Platform?

  The Microsoft ecosystem for business applications can sometimes be difficult to navigate, especially when discussing Dynamics 365 Customer...