My application needs to do a certain query against a user-specified connectionstring. The query will need some parameters, so I was thinking of using the DbProviderFactory , in combination with myConnection.GetSchema("DataSourceInformation").Rows[0]["ParameterMarkerFormat"]
to find out if I need to use :
(Oracle), @
(Sql) or ?
(OleDb) to send in the parameters to the database.
To use the DbProviderFactory I need to find out what Provider is needed for a connectionstring. Is there a good way to do this, or do I need to use some sort of if(conStr.indexOf("oledb") != -1) { type = DbTypes.OleDB; }
logic? (Or is there a better way to connect to an "unknown" database type?)
Note: The DbProviderFactory expects the provider to be in the form of System.Data.SqlClient
, not the SQLNCLI.1
that is in the actual connectionstring.