当您尝试打开与数据库的oracle连接时,我需要您的帮助才能解决此错误。 Connection.Open ();
ConnectionString值:
"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;
}
我希望你能帮助我。 问候 胡安巴勃罗。
答案 0 :(得分:0)
为什么使用IDbConnection
界面?
试试这个:
string connectString = "Data Source=dbora1;Max Pool Size=50;Min Pool Size=1;Connection Lifetime=120;Enlist=true;User Id=slu;Password=slu_4d332";
OracleConnection connection = new OracleConnection(connectString);
connection.Open();
答案 1 :(得分:0)
Werfried
我只是将代码更改为不使用界面,但错误仍然存在。
protected override IDbConnection OpenConnection()
{
string cs = "Data Source=dbora1;Max Pool Size=50;Min Pool Size=1;Connection Lifetime=120;Enlist=true;User Id=slu;Password=slu_4d332";;
OracleConnection connection = new OracleConnection(cs);
try{
connection.Open();
}catch(Exception ex)
{
ex.ToString();
}
return connection;
}
#endregion
}
Deputy exception image 堆栈跟踪:
StackTrace " at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)\r\n at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)\r\n at Oracle.DataAccess.Client.OracleConnection.Open()\r\n at Oracle.DataAccess.Client.OracleConnection.Open()\r\n at Microsoft.Practices.EnterpriseLibrary.Data.Oracle.OracleDatabase.OpenConnection() in c:\\v\\enterpriselibrary\\front_end\\fuentes\\data\\oracle\\oracledatabase.cs:line 441" string
感谢您的时间