今天发生一个意外情况。情况是这样的:
本地开发环境下,运行网站,在某个画面里进行数据检索,刚开始没有问题,在测试分页按钮“末页”时,出现状况,无法检索数据,并且之后查看其他页面时,只要与数据库有关的操作,都无法正常操作。
之后查看了日志,显示以下的错误信息:
System.Runtime.InteropServices.COMException (0x80070006): 句柄无效。 (异常来自 HRESULT:0x80070006 (E_HANDLE))在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
在 System.Data.SqlClient.SqlConnection.Open()
多次出现以上异常信息后,又出现以下信息:
System.UnauthorizedAccessException: 拒绝访问。 (异常来自 HRESULT:0x80070005 (E_ACCESSDENIED))
在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
在 System.Data.SqlClient.SqlConnection.Open()
之前的开发测试过程中从未出现,所以认为两个异常应该是同一个原因造成的,之后通过GOOGLE,找到一MSDN论坛帖,贴主和我有类似的情况,并且最后表示问题已经解决。具体内容:
问题:
Hi,
I got the following errors in our C# Windows application:
1. Type : System.Runtime.InteropServices.COMException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
Source : mscorlib
Help link :
ErrorCode : -2147024890
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ThrowExceptionForHRInternal(Int32, IntPtr)
Stack Trace : at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at Microsoft.Practices.EnterpriseLibrary.Data.Database.OpenConnection()
at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteNonQuery(DbCommand command)
2. Type : System.UnauthorizedAccessException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
3. Type : System.Threading.SemaphoreFullException, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Adding the given count to the semaphore would cause it to exceed its maximum count.
Note:
1. We are using Microsoft Enterprise Library 2006 Data Access & Exception Application Blocks in our application.
2. We are using a method save each action(Journal Entry) of the application into a database which can be as frequent as fraction of a second
An early solution to this will be a helpful one.
解决方案:
Hi All,
I got the solution for this.
Include 'Min Pool Size =1' in the connection string.