Hi there,
I am creating a method where I can pass a connection string and depending on which provider i have chosen, this method will create a connection from the appropriate provider. below is a sample of my code.
public IDbConnection CreateConnection(string connectionString)
{
IDbConnection conn = null;
object[] args = { connectionString };
try
{
switch (_provider)
{
case ProviderType.OleDb:
conn = new OleDbConnection(connection
String);
var myconn = new OleDbConnection(connection
String);
break;
case ProviderType.SqlClient:
conn = new SqlConnection(connectionSt
ring);
break;
case ProviderType.SybaseClient:
conn = new AseConnection(connectionSt
ring);
break;
case ProviderType.DDTekSybaseCl
ient:
conn = new SybaseConnection(connectio
nString);
break;
}
}
catch (TargetInvocationException
e)
{
throw new SystemException(e.InnerExc
eption.Mes
sage, e.InnerException);
}
return conn;
}
however my attemp to connect to the database, stating that it cannot initialize the connection. so after investigating, i realised that the "conn" variable which is IDbConnection doesnt hold all the parameters required as compared to a OleDbConnection type.
But I thought that OleDbConnection inherits from IDbConnection. So what can I do to achieve my goal? thanks
Start Free Trial