SQL Connection Error
I am getting this error while trying to access my website:
Exception information:
Exception type: SqlException
Exception message: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
开发者_如何学编程This error occurs 6-7 times in a whole day.
Can anyone tell me why do I am getting this error? Is there any special settings I can made on my SQL server end to avoid this crash or its a problem in my web application?
If this problem only occurs only from time to time, it's likely you are running into a timeout for one (or more) of your commands.
Try increasing the value of the CommandTimeout property of your commands.
Also try profiling your Sql server for longrunning queries.
Here's how to configure your SQL server 2005 to allow remote connections: http://support.microsoft.com/kb/914277
This can be caused by various things:
- remote connection disabled in SQL Server.
- Firewall settings
- bad connection string
This KB-Article of Microsoft might help... http://support.microsoft.com/default.aspx?scid=kb;EN-US;914277
EDIT: Be aware that if you develop on a system that has a local database the data is exchanged normally over shared memory. Where as in test- and production-environments you have a separate database server that has to be connected over the tcp protocol with you application.
ConnectionString:
data source=[SERVERADDRESS];initial catalog=[DBNAME];user id=[USER];password=[PASSWORD];persist security info=True;Pooling=True;Max Pool Size=1000;Connection Lifetime=30;
Do you really have to set the pool size and connection lifetime? I am rarely using this settings. They might cause the trouble. Specially the
Connection Lifetime
Should be used very carefully. Read more here http://blogs.msdn.com/b/angelsb/archive/2004/09/20/231963.aspx
精彩评论