Re: How to do non dependence on database vendor?
- From: "Bjorn Abelli" <bjorn_abelli@xxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 16 May 2005 11:46:42 +0200
"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
.
- Follow-Ups:
- Re: How to do non dependence on database vendor?
- From: Brett
- Re: How to do non dependence on database vendor?
- References:
- How to do non dependence on database vendor?
- From: Brett
- Re: How to do non dependence on database vendor?
- From: Bjorn Abelli
- Re: How to do non dependence on database vendor?
- From: Brett
- Re: How to do non dependence on database vendor?
- From: Bjorn Abelli
- Re: How to do non dependence on database vendor?
- From: Brett
- Re: How to do non dependence on database vendor?
- From: Bjorn Abelli
- Re: How to do non dependence on database vendor?
- From: Brett
- Re: How to do non dependence on database vendor?
- From: Bjorn Abelli
- Re: How to do non dependence on database vendor?
- From: Brett
- How to do non dependence on database vendor?
- Prev by Date: Re: how to validate an xml file against xsd in whidbey
- Next by Date: Re: How to retrun a character with ascii code
- Previous by thread: Re: How to do non dependence on database vendor?
- Next by thread: Re: How to do non dependence on database vendor?
- Index(es):