【发布时间】:2016-07-02 09:45:36
【问题描述】:
我需要您的帮助来解决当您尝试打开与数据库的 oracle 连接时发生的此错误。 Connection.Open ();
连接字符串值:
"Data Source=dbora1;Max Pool Size=50;Min Pool Size=1;Connection Lifetime=120;Enlist=true;User Id=slu;Password=slu_4d332;" string
异常为null,strack trace如下:
StackTrace "
at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)
at Oracle.DataAccess.Client.OracleConnection.Open()
at Oracle.DataAccess.Client.OracleConnection.Open()
at Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.OpenConnection() in c:\\v\\enterpriselibrary\\front_end\\fuentes\\data\\oracle\\oracledatabase.cs:line 444" string
他们还留下了image of the quickview of the variable that captured the exepcion.
这里是初始化数据库连接的完整代码:
protected override IDbConnection OpenConnection()
{
OracleConnection connection = (OracleConnection)GetConnection();
try
{
//Test the connection context mark.
if ( connection.State == ConnectionState.Closed )
{
connection.Open();
}
this.instrumentation.ConnectionOpened(ConnectionStringNoCredentials);
return connection;
}
catch (System.ObjectDisposedException)
{
connection = (OracleConnection)GetConnection( true );
try
{
connection.Open();
return connection;
}
catch
{
connection.Close();
throw;
}
}
catch(System.InvalidOperationException e)
{
// Log in eventviewer
LogConnectionPoolTimeOutEvent(e);
connection.Close();
this.instrumentation.ConnectionFailed(ConnectionStringNoCredentials);
throw;
}
catch (System.OutOfMemoryException)
{
connection.Close();
this.instrumentation.ConnectionFailed(ConnectionStringNoCredentials);
throw;
}
catch(Exception ex)
{
connection.Close();
this.instrumentation.ConnectionFailed(ConnectionStringNoCredentials);
throw;
}
}
而方法代码GetConnection()为:
public override IDbConnection GetConnection()
{
return GetConnection( false );
}
protected IDbConnection GetConnection( bool renew )
{
IDictionary connectionHolder;
OracleConnection tempConn;
//Test the connection context mark.
if ( ConnectionContext.CachedConnectionContext )
{//If the mark is in the callcontext
//Get the connection holder
connectionHolder = CallContext.GetData(ConnectionContext.CALLCONTEXTKEY) as IDictionary;
//If the connection holder does not exists
if ( connectionHolder == null )
{
//create a conection holder
connectionHolder = new Hashtable();
//create the initial connection
tempConn = new OracleConnection(base.ConnectionString);
//add the connection to the holder
connectionHolder.Add(base.ConnectionString, tempConn);
//save the holder in the call context
CallContext.SetData(ConnectionContext.CALLCONTEXTKEY, connectionHolder);
}
else
{
//get the connection from the holder
tempConn = connectionHolder[base.ConnectionString] as OracleConnection;
if ( tempConn == null )
{ //if the connection was not in the holder
//create a new connection
tempConn = new OracleConnection(base.ConnectionString);
//add the connection to the holder
connectionHolder.Add(base.ConnectionString, tempConn);
}
else
{ //if the connection exists
if ( renew )
{ //if should renew the connection
//TODO:Delete
HealthModel.Trace.TraceToken token = HealthModel.Trace.TraceHelper.Start( "+++++++ R e n e w", "", "", 0 );
//closes the connection
tempConn.Close();
//create a new connection
tempConn = new OracleConnection(base.ConnectionString);
//add the connection to the holder
connectionHolder[base.ConnectionString] = tempConn;
//TODO:Delete
HealthModel.Trace.TraceHelper.End( token );
}
}
}
}
else
{//if the mark was not in the call context
//create a connection
tempConn = new OracleConnection(base.ConnectionString);
}
return tempConn;
}
我希望你能帮助我。 问候 胡安·巴勃罗。
【问题讨论】:
-
能否请您显示您初始化和打开连接的完整代码?
-
我刚刚添加了请求的代码。非常感谢 Wernfried!
-
什么是
GetConnection()?我假设它返回导致错误的null。 -
我刚刚添加了GetConnection的代码,你可以查看它。
标签: c# .net oracle oracle10g c#-2.0