In my C# application, I have roughly the following code:
In App.Config:
<connectionStrings>
<add name="Con1" connectionString="..." providerName="System.Data.Odbc"/>
</connectionStrings>
In My Code:
static DbConnection createConnection(ConnectionStringSettings conn_str)
{
DbProviderFactory factory = DbProviderFactories.GetFactory(conn_str.ProviderName);
var retval = factory.CreateConnection();
retval.ConnectionString = conn_str.ConnectionString;
return retval;
}
This creates for me a connection variable, conn
and works great (I can open the connection, query it, etc), so I know I'm referencing the correct libraries.
However, later on, I need to get the factory again and use:
DbProviderFactory factory = DbProviderFactories.GetFactory(conn);
But, for whatever reason, I get back that factory = null
.
Am I doing something plainly wrong?
I just tried the following code:
factory came back as not null. There is something else going on since this code should work fine.