Question:
When i am trying to open the connection of oracle database in C#, then the following error occurred. Mention that this code work on new project. What is the solution for this.
Quote:
ArgumentNullException:
Value cannot be null.
Parameter name: SafeHandle cannot be null.
Stack Trace:
at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
at System.Data.Common.UnsafeNativeMethods.OCIAttrSet(OciHandle trgthndlp, HTYPE trghndltyp, Byte[] attributep, UInt32 size, ATTR attrtype, OciHandle errhp)
at System.Data.OracleClient.TracedNativeMethods.OCIAttrSet(OciHandle trgthndlp, Byte[] attributep, UInt32 size, ATTR attrtype, OciHandle errhp)
at System.Data.OracleClient.OciHandle.SetAttribute(ATTR attribute, String value, OciErrorHandle errorHandle)
at System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity, Boolean unicode, Boolean omitOracleConnectionName)
at System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions)
at System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
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.OracleClient.OracleConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
at FlexiStar.DataProvider.OracleProcedureProvider.GetSpParameterSet(String connectionString, String spName, Boolean includeReturnValueParameter, String& reply) in C:\Users\shihabiu\Desktop\Middleware.Net\Source\QCash Middleware 2.0.2\FlexiStar.DataProvider\MSOracleDataprovider\OracleProcedureProvider.cs:line 294
Code
String cs = @"Data Source=loacalhost/orcl;Integrated Security=no;User ID=fspro;Password=fspro";
using (OracleConnection con = new OracleConnection(cs))
{
OracleDataAdapter da = new OracleDataAdapter("FSO_CFG_SYSTEM_GA", con);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add("P_RESULT_SET_OUT", OracleType.Cursor).Direction = ParameterDirection.Output;
DataTable dt = new DataTable();
try
{
da.Fill(dt);
}
catch (OracleException e)
{
throw new Exception(e.Message, e.InnerException);
}
catch (Exception e)
{
throw new Exception(e.Message, e.InnerException);
}
return dt;
}