Monday, September 15, 2008

General network error. Check your network documentation.

There is a lot of people out there complaining about SQL Server returning a General network error while executing a command form ADO.NET version 1.1 or 1.0. Since it is a General network error, it seems to me that there are as many reasons for this error as there are people having it. one fine day I too experienced the same so I googled it but saveral posts in several blogs leads to various solutions like append max pool size = 7500, to your connection string will solve the issue or setting the command timeout to anything but zero totally fixes it.

I tried all of them but still i experienced the same error intermittently. Finally i found that The calling asp.net page creates an ojbect which opens the connection over and over and relies on the destruct method of the database object to do the closing so I am assuming our problem is related to this but I have not been able to reproduce it reliably so I can't be sure this is the cause of the problem.

then i found this microsoft KB article

it says that In the current design, after an application role is enabled on a client connection to SQL Server, you cannot reset the security context of that connection. Therefore, when the user ends the SQL Server session and disconnects from the server, the session is not reusable. However, OLE DB resource pooling returns the closed connection to the pool, and the error occurs when that connection is reused and the client application tries to reset the connection's security context by calling sp_setapprole again.

WORKAROUND

The only available workaround is to disable OLE DB Resource Pooling, which ADO uses by default. You can do this by adding "OLE DB Services = -2" to the ADO Connection string, as shown here: 'For SQLOLEDB provider
'strConnect = "Provider=SQLOLEDB;server=SQL7Web;OLE DB Services = -2;uid=AppUser;pwd=AppUser;initial catalog=northwind"

' For MSDASQL provider
'strConnect = "DSN=SQLNWind;UID=Test;PWD=Test; OLE DB Services= -2"


Pooling can be disabled for the SQL Server .Net Data Provider by adding "Pooling=False" to the connection string.

although that solves my issue but what if the connection pooling is needed ????