I
inaqui.medina
Hi,
I'm writting my application and I want it to be DBMS independent.
The problem is I don't want to use ODBC because if it is SQL Server
I know SQLClient is faster and the same with Oracle.
So my first idea was something like:
#if SQL_DB
#define CONN_TYPE SqlConnection
#else
#define CONN_TYPE OracleConnection
#endif
//... Same for all ADO objects
I soon found out that this is old C++ and not available in VS.Net.
Then I thought "Ok lets then do:
#if SQL_DB
public class DbConnection : SqlConnection
#else
public class DbConnection : OracleConnection
#endif
{}
//... Again same for all objects
Wrong again because classes like OracleConnection are sealed!!
So right now my only plausible idea is:
public class DbConnection
{
public DbConnection(string connectionString)
{
#if SQL_DB
impl = new SqlConnection(connectionString);
#elif ODBC_DB
impl = new OdbcConnection(connectionString);
#else
impl = new OracleConnection(connectionString);
#endif
}
public DbConnection()
{
#if SQL_DB
impl = new SqlConnection();
#elif ODBC_DB
impl = new OdbcConnection();
#else
impl = new OracleConnection();
#endif
}
public void Open()
{
impl.Open();
}
public void Close()
{
impl.Close();
}
//Implement all methods here and forward to impl
#if SQL_DB
SqlConnection impl;
#elif ODBC_DB
OdbcConnection impl;
#else
OracleConnection impl;
#endif
}
So my questions are:
Hasn't MS worried about this?
Isn't there a better solution?
If not, is this worth the trouble? (implementing all objects and all
methods again and just forward the calls)
Thanks a lot,
inaquimj
I'm writting my application and I want it to be DBMS independent.
The problem is I don't want to use ODBC because if it is SQL Server
I know SQLClient is faster and the same with Oracle.
So my first idea was something like:
#if SQL_DB
#define CONN_TYPE SqlConnection
#else
#define CONN_TYPE OracleConnection
#endif
//... Same for all ADO objects
I soon found out that this is old C++ and not available in VS.Net.
Then I thought "Ok lets then do:
#if SQL_DB
public class DbConnection : SqlConnection
#else
public class DbConnection : OracleConnection
#endif
{}
//... Again same for all objects
Wrong again because classes like OracleConnection are sealed!!
So right now my only plausible idea is:
public class DbConnection
{
public DbConnection(string connectionString)
{
#if SQL_DB
impl = new SqlConnection(connectionString);
#elif ODBC_DB
impl = new OdbcConnection(connectionString);
#else
impl = new OracleConnection(connectionString);
#endif
}
public DbConnection()
{
#if SQL_DB
impl = new SqlConnection();
#elif ODBC_DB
impl = new OdbcConnection();
#else
impl = new OracleConnection();
#endif
}
public void Open()
{
impl.Open();
}
public void Close()
{
impl.Close();
}
//Implement all methods here and forward to impl
#if SQL_DB
SqlConnection impl;
#elif ODBC_DB
OdbcConnection impl;
#else
OracleConnection impl;
#endif
}
So my questions are:
Hasn't MS worried about this?
Isn't there a better solution?
If not, is this worth the trouble? (implementing all objects and all
methods again and just forward the calls)
Thanks a lot,
inaquimj