我正在尝试从我的c#代码连接到Oracle并从中检索一些数据。
以下是我的示例代码:
DbCommon dbConn = CommonConfigMgr.GetConnFromPool(dbConnStr, dataSourceConfig.Schema);
try
{
dbConn.Open();
log.Debug("before constucting the oracle procedures... Line: 453");
dbConn.CreateDbCommand("begin :username := eokutil.f_get_username_from_udcid(:udcid, :use_gobumap);end;", CommandType.Text);
dbConn.AddCommandParameter(":username", username, ParameterDirection.Output);
dbConn.AddCommandParameter(":udcid", udcid, ParameterDirection.Input);
dbConn.AddCommandParameter(":use_gobumap", 1, ParameterDirection.Input);
log.Debug("after constructing the oracle procedures... Line: 458");
dbConn.ExecuteNonQuery();
Object returnValue = dbConn.GetCommandParameterValue(":username");
if (returnValue == null || returnValue.ToString().Length == 0)
{
string message = String.Format("Unable to retrieve AX username for UDCID '{0}' from datasource '{1}'", udcid, dataSource);
log.Error(message);
throw new ApplicationException(message);
}
username = returnValue.ToString().ToUpper();
log.InfoFormat("Record retrieved from eokutil.f_get_username_from_udcid: UDCID=>{0} USERNAME=>{1}", udcid, username);
}
catch(Exception e)
{
dbConn.RollbackTransaction();
log.DebugFormat(e.Message);
log.ErrorFormat("Fails to get AXC username from UDCID. {0}", e);
throw e;
}
但有时我会遇到以下异常:
Fails to get AXC username from UDCID. Oracle.DataAccess.Client.OracleException ORA-03114: not connected to ORACLE at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32 isRecoverable)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
at XtenderSolutions.Administration.Database.DbCommonEx.ExecuteNonQuery(DbCommand cmd)
at XtenderSolutions.UtilityLibrary.General.DbCommon.ExecuteNonQuery()
at net.hedtech.bdm.sso.AxLoginHelper.GetAxUsernameFromUDCID(String dataSource, String udcid)
对于剩下的电话,我得到的是这样的话:
Fails to get AXC username from UDCID. Oracle.DataAccess.Client.OracleException ORA-03135: connection lost contact
Process ID: 7009
Session ID: 799 Serial number: 33639 at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32 isRecoverable)
at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
at XtenderSolutions.Administration.Database.DbCommonEx.ExecuteNonQuery(DbCommand cmd)
at XtenderSolutions.UtilityLibrary.General.DbCommon.ExecuteNonQuery()
at net.hedtech.bdm.sso.AxLoginHelper.GetAxUsernameFromUDCID(String dataSource, String udcid)
有任何建议要克服这个问题吗?
相同的代码适用于其他客户端。我正在寻找一些东西,其中oracle可以确保它将在打开连接后运行每个查询
客户正在使用:
数据库版本是Oracle Database 12c企业版发行版 12.1.0.2.0
ODAC版本为12.1.0.2.0。
请帮助我。
有没有办法重新连接连接并再次执行相同的步骤?
是否有可能从Oracle方面做到这一点?
正如您所看到的,我们正在使用某些第三方,并且我们正在使用连接池。如果连接池有问题,如何从我们的代码中克服它?