The maximum message size quota for incoming messages exceeded exception in WCF

This is a common error you get when developing you are consuming WCF service operation that deals with large data.

To overcome this error you need to customize the bindings, service behavior and endpoint behavior of the service.

  1. Customize the binding:

First of all you need to set the maxbufferpoolsize and maxReceivedMessageSize in the binding.

MaxBufferPoolSize  gets or sets the maximum size of any buffer pools used by the transport.  The default is 524,288 bytes.

MaxReceivedMessageSize gets and sets the maximum message size that can be receivied. The default is 65536 bytes.

ReaderQuotas: Defines the contraints on the complexity of SOAP messages that can be processed by endpoint configured with a binding. You need to set the maxBytesPerRead, maxDepth, maxNameTableCharCount,maxStringContentLength.

Read more of this post

UDP Binding Example in WCF 4.5


UDP (User Datagram Protocol) is a connectionless protocol that runs on top of IP networks. It is similar to TCP/IP. However, it provides less error handling and recovery that TCP/IP. It provides a direct way of send and receive datagrams over an IP network, primarily used for broadcasting messages across networks.

UDP and WCF 4.5:

WCF 4.5 framework supports UDP bindings. It is one of the new features of WCF 4.5. Following is an example how to use UDP Binding in .Net 4.5

Service Configuration :




<behavior name=””>

<serviceMetadata httpGetEnabled=”true” httpsGetEnabled=”true”/>

<serviceDebug includeExceptionDetailInFaults=”false”/>

<serviceThrottling maxConcurrentCalls=”1000″ maxConcurrentInstances=”1000″ maxConcurrentSessions=”1000″/>





<service name=”UdpServiceHost.HelloService”>

<endpoint address=”soap.udp://localhost:8080/” binding=”udpBinding” contract=”UdpServiceHost.IService”/>



<add baseAddress=”http://localhost:8080/UdpServiceHost/”/&gt;





</system.serviceModel> Read more of this post

Drop database Error: ALTER DATABASE failed because a lock could not be placed on database

I was trying to drop a database from my development environment. But I was getting the following error.


Alter failed for Database ‘AdventureWorks’. (Microsoft.SqlServer.Smo)

For help, click:


An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)


ALTER DATABASE failed because a lock could not be placed on database ‘AdventureWorks’. Try again later.
ALTER DATABASE statement failed. (Microsoft SQL Server, Error: 5061)



This means there are some process already locked the database and you cannot drop it before that process release the lock.

To see which process is locking the database. Run the following  command

exec sp_who2

This will list all processes and uid that has a lock on databases.

In my case, I can see PID 52 was holding the AdventureWorks database. As it is my Dev environment and i know that nothing will harm any other system if I kill this process and eventually drop the database, I issued the following command.

kill <PID> 

KILL 52 //In my case 

After you have kill all the processes that are holding a lock in your database, you will be able to drop the database.