[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Re: How to switch Data providers

Jay B. Harlow [MVP - Outlook]

3/5/2002 2:05:00 AM

Teodorico,
One method is to use an Abstract Factory pattern. See "Design Patterns -
Elements of Reusable Object-Oriented Software" by Erich Gamma, Richard Helm,
Ralph Johnson, and John Vlissides. By Addison-Wesley Professional Computing
Series.

Your program itself only makes use of the interfaces defined in System.Data,
which include:

- IDataReader
- IDbCommand
- IDbConnection
- IDbDataAdapter
- IDbDataParameter

Your Abstract Factory pattern would need to define a MustInherit BaseFactory
class that has methods for returning each of the above (there are probably
others...) I would add a Shared function 'Create' on this class that returns
one of the concrete classes based on the type requested (ODBC, SQL, OleDB,
Oracle, AS400, ...)

Then you would define a concrete class for each data client. The
OleDbFactory would derive from the above class and implement each of the
methods in terms of System.Data.OleDb. The SqlFactory would also derive from
the above class and implement each of the methods in terms of
System.Data.SqlClient. Same with the OdbcFactory, it would derive from the
above class, and implement each of the methods in terms of
Microsoft.Data.Odbc. I would seriously consider making these Singleton
patterns. A Singleton pattern means only one of the concrete factory objects
exists, ever.

If MS released a Microsoft.Data.Oracle. the OracleFactory would then
derive... (you get the idea ;-)

Your program would call BaseFactory.Create to get a data client factory.
Your code would then call the methods on the returned factory object.

A Builder Pattern may be a good alternative. Builder patterns are a little
smarter Abstract Factories...

I should add that James W. Cooper recently came out with "Visual Basic
Design Patterns" from Addison Wesley. That covers all 23 Design Patterns
from the "Design Patterns - Elements of Reusable Object-Oriented Software"
book.

All 23 Design Patterns are presented in both VB6 & VB.NET. Well worth
getting!

Hope this helps
Jay

"Teodorico Morell" <teomorell@hotmail.com> wrote in message
news:OJ$X0Z9wBHA.2520@tkmsftngp05...
> Before using .Net, I used VB with native ODBC access. To change from one
> database to another was really easy. I just change the DSN.
>
> Now with .Net we have the:
>
> System.Data.SqlClient;
>
> System.Data.OleDb;
>
> Microsoft.Data.Odbc;
>
>
>
> How can I write and application and switch from System.Data.OleDb, lets
say
> to Microsoft.Data.Odbc (To use and ODBC driver because and OLEDB provider
is
> not available) without changing any code.
>
>
>
> Thanks,
>
>
>
>
>
> Teo
>
>
>
>
>
>
>