Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Database is in use error

You want to restore database and your database is connected with many applications you may face following error:

Exclusive access could not be obtained because the database is in use.

Fix:

You require to stop kill connections sessions for this database except running then restore database.

I am sharing one T-SQL query that will do your job, query will kill all connections except running connection

Example:

--NOTE: Below query will kill all connections except running connection.
-- Kill all sessions using a database
USE [master]
GO
DECLARE @dbName SYSNAME
DECLARE @sqlCmd VARCHAR(MAX)
DECLARE @db_id int;
SET @sqlCmd = ''
SET @dbName = 'C4UDatabase' -- Change database name here
SET @db_id = DB_ID(@dbName);
SELECT   @sqlCmd = @sqlCmd + 'KILL ' + CAST(session_id AS VARCHAR) +
         CHAR(13)
FROM     sys.dm_exec_sessions
WHERE    DB_NAME(@db_id) = @dbName
PRINT @sqlCmd
--Uncomment below line to kill
EXEC (@sqlCmd)
-- Kill all sessions using a database

 

The maximum message size quota for incoming messages (65536) has been exceeded.

Error:

System.ServiceModel.CommunicationException: The maximum message size quota for incoming messages (65536) has been exceeded.
To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element.

 Fix:

You can set at web.config MaxReceivedMessageSize property to another value
You should set maxReceivedMessageSize="2147483647" to increase message size.

Try below changes in config file:

<bindings>
          <wsHttpBinding>
              <binding name="WsHttpBinding_IYourService" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
              </binding>
          </wsHttpBinding>
          <basicHttpBinding>
              <binding name="BasicHttpBinding_IYourService "maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
              </binding>
          </basicHttpBinding>
      </bindings>
    <client />

System.ServiceModel.ServiceActivationException: The requested service, ' .. ' could not be activated.

If you are facing following issue with WCF web service , one fix I will explain in detail.

Error Message:

System.ServiceModel.ServiceActivationException: The requested service, ' .. ' could not be activated. 

Fix:

Step 1:

Open WCF application service Web.cong , in Configuration section check below code is available.  

<serviceHostingEnvironment>
      <serviceActivations>
 
         <add service="TestWebService"  relativeAddress="TestWebService.svc" />
      </serviceActivations>
 </serviceHostingEnvironment>

Step 2:

If still facing issue now check  below <serviceActivations> Service name then open

TestWebService.svc ServiceHost file and Check Service name matching:

i.e

<%@ ServiceHost Language="C#"
Debug="true" Service="TestWebService"   CodeBehind=" TestWebService.svc.cs"%>