Doubt connections

P

Paulo

Hi, if the customer choose access (mdb) I have to use OleDbConnection,
OleDbCommand classes, etc... etc, but if the customer chooses Sql Server as
database I have to use SqlConnection, SqlDataReader, etc...

Do you know any pieces of code / classes wich gives to me the flexibility to
choose between those databases?

Thanks!
 
S

sloan

Get the enterprise library 3.1 version.

It will abstract you "up one level", so you're not super tied to 1 rdbms.
(even though I don't consider access a true rdbms)

.......

Another option is to write a data-access-layer, via an interface.

Interface IEmployeeData


and then have 2 concrete versions of IEmployeeData

example:

interface IEmployeeData
IDataReader GetAllEmployees();
IDataReader GetSomeEmployess( Guid deptUUID ) ;
void UpdateEmployee ( Guid empUUID, string lastName , string
firstName , string ssn , Guid deptUUID ) ;
void DeleteEmployee ( Guid empUUID) ;


and then implement one for SqlServer, and 1 for Access.

public class EmployeeDataViaSqlServer : IEmployeeData

public class EmployeeDataViaAccess : IEmployeeData


Its called the Factory Design Pattern.


http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!126.entry

http://www.dofactory.com/Patterns/PatternFactory.aspx


The reason I mention the factory pattern is because of the large differences
in ways you're going to code up a DAL for the two.

Sql Server has stored procedures, which most commonly you're gonna add
parameters to.
db.AddInParameter ( )

Access, you don't have stored procedures. So the code is going to look
different.

..........

I have done the IEmployeeData thing, and I use the Ent Library 3.1 within
that setup. I use the "key" model (my blog entry) to decide which concrete
version to give back.

But as long as your biz layer uses the IEmployeeData interface, you'll be
good. And you'll need to learn how to work with the IDataReader interface
instead of a concrete version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top