Enterprise Library Multiple Named DB Instances Config RRS feed

  • Question

  • I am trying to get the configuration right for using multipe named instances in the latest Enterprise Lib Data Access {3.1}


    This works like a charm:



    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />



    <add name="DataAccessQuickStart"


    connectionString="server=(local)\SQLEXPRESS;database=EntLibQuickStarts;Integrated Security=true" />


    <dataConfiguration defaultDatabase="DataAccessQuickStart"/>



    But how do you add other instances.  I tried like crazy using the GUI tool that comes with the toolkit, but it never comes up like all the demos I see on the web sites, The "instances" branch of the tree never shows up.  There has got to be a simple way ??


     Any help would be appreciated, I would love to use the library.


    Tuesday, December 11, 2007 4:39 AM


  • I think I figured this out.  I was confused looking at old samples and previous version of the library.  In order to use multiple DB's with the Enterprise library, I just needed to treat the connect strings as database instances.  Adding this to my web config did the trick, now to connect to the first database I use:


    Database db = DatabaseFactory.CreateDatabase("DBInstance1");  // left blank it uses the defaultDatabase


    <dataConfiguration defaultDatabase="DBInstance1" />


            <add name="DBInstance1" connectionString="Data Source=Server1;Initial Catalog=DB1;Integrated   Security=True" providerName="System.Data.SqlClient" />

             <add name="DBInstance2" connectionString="Data Source=Server2;Initial Catalog=DB2;Integrated Security=True" providerName="System.Data.SqlClient" />



    This works in the latest (3.1) Application block.

    • Marked as answer by sBerringer Wednesday, July 7, 2010 8:24 PM
    Tuesday, December 11, 2007 3:58 PM