使用 Oracle.ManagedDataAccess.Client,以下 VB.NET 行会引发内部异常:
Dim conn As New OracleConnection(connStr)
conn.ConnectionString = "Data Source=(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl))); User id=username; Password=password"
conn.Open()
conn.Open 语句成功但抛出以下异常:
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
更重要的是,打开第一个连接需要 1.5 秒。
如果我关闭连接并打开一个新连接,则没有问题。
我对非托管 Oracle 数据提供者没有这样的问题,第一次连接将在几分之一秒内完成。如果我连接到 Oracle 11g 或 12c 数据库服务器,这没有什么区别,因此看起来数据提供者是罪魁祸首。
数据提供者是否尝试了一些失败的东西,之后它在会话的其余部分默认为其他东西,如果是这样,我能做些什么来强制它第一次走成功的路径?
第一次连接的漫长等待仅仅是因为初始化 Oracle 池管理器的成本吗?如果是这样,我想我无法修复它的那部分,但即使是这样,我仍然想知道是否有可能做任何事情来摆脱 SocketException。
当 SocketException 被命中时,.NET 端的堆栈跟踪如下所示:
System.dll!System.Net.Sockets.Socket.EndConnect(System.IAsyncResult asyncResult)
System.dll!System.Net.Sockets.TcpClient.EndConnect(System.IAsyncResult asyncResult)
Oracle.ManagedDataAccess.dll!OracleInternal.Network.TcpTransportAdapter.Connect(OracleInternal.Network.ConnectionOption conOption)
Oracle.ManagedDataAccess.dll!OracleInternal.Network.OracleCommunication.ConnectViaCO(OracleInternal.Network.ConnectionOption connOption, OracleInternal.Network.AddressResolution addrRes)
Oracle.ManagedDataAccess.dll!OracleInternal.Network.OracleCommunication.DoConnect(string tnsDescriptor)
Oracle.ManagedDataAccess.dll!OracleInternal.Network.OracleCommunication.Connect(string tnsDescriptor, bool externalAuth, string instanceName)
Oracle.ManagedDataAccess.dll!OracleInternal.ServiceObjects.OracleConnectionImpl.Connect(Oracle.ManagedDataAccess.Client.ConnectionString cs, bool bOpenEndUserSession, string instanceName)
Oracle.ManagedDataAccess.dll!OracleInternal.ConnectionPool.PoolManager<OracleInternal.ConnectionPool.OraclePoolManager,OracleInternal.ConnectionPool.OraclePool,OracleInternal.ServiceObjects.OracleConnectionImpl>.CreateNewPRThreadFunc(object state)
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)
mscorlib.dll!System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
mscorlib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch()
查看 Oracle .trc 文件,似乎没有什么异常。