Azure DevOps, Scrum, & .NET Software Leadership and Consulting Services

Introducing Slide Speaker: Videos with Voice-over from your PowerPoint and Google Slides Presentations

Using a run-time defined connection string with Enterprise Library's Data Access Block.


As you can probably tell from previous posts, I’m feel pretty mixed about on the Microsoft Patterns & Practices Enterprise Library Data Access Block (MPAPELDAB, for short).  I like the design of the classes and I really like that you can access databases other than just SQL Server but I’m having some serious problems with registry and event log access exceptions. 

A few days ago, I was trying to access a database using a connection string that I define at run-time.  I double dog dare ya to try to figure that one out.  Wow.  It is not obvious.  Far far extra far from obvious.  The MPAPELDAB appears to be written with the assumptions that…

  1. you will always know your database connection strings at deploy time
  2. they will be in your MPAPELDAB database configuration file

Not bad as assumptions go.  I can see how they would make them cuz probably 99% of the time that’s the way it’ll roll. 

I found the solution on “Yang’s .NET Zone”.  It’s non-trivial.  I took the source code, tweeked it a little, and posted my version here.  (NOTE: yes, I know you shouldn’t put more than one class or enum per file…I did it so that I only had to post one file instead of 3.)

-Ben

SUBSCRIBE TO THE BLOG


One response to “Using a run-time defined connection string with Enterprise Library's Data Access Block.”

  1. Kim Avatar
    Kim

    Benny, were you getting a little tired last night when you wrote this one? "I’m feel pretty about on the Microsoft Patterns…"

    🙂

    Kimmah

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.