Saturday 11 July 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

Adding a newline into a string in C# and X++

Below is the sample code we can use for  adding a newline after every occurrence of "@" symbol in the string in C#   using System...