DAAB and other database providers

Topics: Data Access Application Block
Feb 2, 2010 at 8:31 AM

Hi.

I'm using DAAB to abstract data acess to support mulitple database vendors. Everything works as intended. However I have run into a problem. I need to handle some common database exceptions (ie. wrong user/pass, unique index violated, table locked, key is being referenced) and show to user as normal errors that can happen everyday. To accomplish this I have added code to my custom exception handler to check for exception type and then to check for error number:

public Exception HandleException(Exception exception, Guid correlationID) {

if (exception is SqlException) { // cast and check Number property }

else if (exception is IfxException) { // cast and check Errors[0].SQLState property } }

While this works well the side effect is that all my users now have to have all database drivers installed altough 90% of the users use MS SQL database. System admins will not allow me to install extra drivers on their systems since those databases do not exist. I need a strategy to check for specific database errors but somehow tell .NET not to load driver providers untill they are really needed.

Any ideas?

 

 

Feb 2, 2010 at 8:39 AM

Why not install on a different machine and just copy the assemblies you need?  Are you also not allowed to just at least copy the necessary assemblies?  Since your intent is to support multiple database vendors, it's necessary to obtain their corresponding assemblies,

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 2, 2010 at 8:56 AM

It's a valid approach perhaps. However, IBM data providers for DB2 and Informix are installed on GAC and they have separate installations for 32bit and 64bit drivers. Their drivers are not native .NET drivers as I understand things and installing correct one is essential. That's the reason why I'm hesitant to have local copy of an assembly. I don't know which assembly to take. My solution builds with Any CPU flag set.

Feb 2, 2010 at 9:16 AM

I think you're gonna have to post this in other forums.  I don't know if it's possible to tell .NET to not load the drivers but it certainly is out of scope for EntLib.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Feb 4, 2010 at 8:08 AM

After a few tries I have figured it out using reflection. The key point would be to avoid referencing any class which is specific for a database provider until you're sure you're going to use it. The code in exception handler is now rewritten like this:

 

public Exception HandleException(Exception exception, Guid correlationID)

{  

if (exception.GetType().Name == "IfxException")

{

// Informix database is my class inherited from Database.

exception = InformixDatabase.CheckSqlState(exception);

}

}