0
votes

I am using NHibernate to connect to an Oracle database. Everything was fine until I suddenly started to get the strange Value cannot be null. Parameter name: SafeHandle cannot be null. error. I am not sure what I have changed to get this error and I do not know what exactly it means. Google does not give results too. Below is the full stack trace. Any ideas ?

Error happens when BuildSessionFactory is called:

 var x = Fluently.Configure()
        .Database(OracleClientConfiguration.Oracle10
            .ConnectionString(connectionString))
        .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
        .BuildConfiguration();

    return x.BuildSessionFactory();

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 NHibernate.Connection.DriverConnectionProvider.GetConnection() at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare() at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper) at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory) at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners) at NHibernate.Cfg.Configuration.BuildSessionFactory() at Models.SessionFactory.CreateOracleConnection(String connectionString) in c:\Users\CMENGU\Projects\TNT\Models\SessionManager.cs:line 21 at TNT.SessionManager.InitOracleFactory() in c:\Users\CMENGU\Projects\TNT\TNT\SessionManager.cs:line 29 at TNT.Program.Main() in c:\Users\CMENGU\Projects\TNT\TNT\Program.cs:line 30 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

1
Both the SafeHandle and other parts of the error point to an issue with the connnection. Make sure the Db is Ok, that nobody changed a setting or a schema etc. - Henk Holterman
@HenkHolterman Nothing works. DB is OK. I can connect with Toad and everyone else in my team can run the code successfully. Not sure what is going on - Cemre Mengü
That all points to a problem in your configuration, not in your code. I'm no Oracle expert but try to find out what has changed. Something has. Driver DLLs, listener configs, ... - Henk Holterman

1 Answers

0
votes

It turns out that it was the visual studio 2015 preview that was somehow messing up something related to oracle libraries which led to this error. I had to reformat my pc couple of times until I understood whats going on.