Re: How to do non dependence on database vendor?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




"Brett" <no@xxxxxxxx> skrev i meddelandet
news:eG5WpNaWFHA.2472@xxxxxxxxxxxxxxxxxxxxxxx

> The above sounds good conceptually and can be done with interfaces. That
> still gets into greating multiple classes for each specific
> implementation. What I'm saying is I still don't understand how you plan
> to use Reflection. You've not demonstrated how this is done.

As I said, I hadn't started yet on my
adhoc-query-machine-for-many-databases, but as I will do it soon I'll need
it anyway, so I scrambled together a small example:

-----------------------
using System;
using System.Data;
using System.Reflection;

namespace DbPlus
{
public class ReflectionProxy : IDbProxy
{
IDbConnection cn;

public ReflectionProxy(string assemblyName, string connectionClass,
string connectionString)
{
Assembly a = Assembly.Load( assemblyName );
Type t = a.GetType(connectionClass);
cn = (IDbConnection) Activator.CreateInstance(t, true);
cn.ConnectionString = connectionString;
cn.Open();
}

public bool IsOpen
{
get { return (cn.State == ConnectionState.Open); }
}

public IDbCommand CreateCommand()
{
return cn.CreateCommand();
}
}
}
-----------------------

When I used it in my testprogram I have hardcoded the values, but these can
easily be put in some ini-file or something...

In this case I simply connect to an Access DB, just to show how it can work.

-----------------------
IDbProxy proxy = new ReflectionProxy(
"System.Data, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089",
"System.Data.OleDb.OleDbConnection",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mytest.mdb");
-----------------------

I hope this example show what I mean when I say that you only need one proxy
for the standard SQL compliant DBs.


// Bjorn A


.