Passing connection string to Enterprise Library DAAB 3.1

Last post 05-26-2009 12:26 PM by GTL. 3 replies.

Sort Posts:

  • Passing connection string to Enterprise Library DAAB 3.1

    06-11-2007, 5:37 PM
    • Member
      10 point Member
    • sk78
    • Member since 06-05-2007, 3:38 PM
    • Posts 6

    The company I work is considering to use the Enterprise Library Data Access Application Block. The problem is an internal policy that forces all company systems to get the connection string from a sql server.

    Is there any way to just pass the connection string to the Data Access Application Block instead of getting it from the app.config or web.config?

    I dont see any overloaded methods on the DatabaseFactory.CreateDatabase() method. Pointers please!

  • Re: Passing connection string to Enterprise Library DAAB 3.1

    06-18-2007, 7:50 PM
    • Member
      50 point Member
    • bc1016
    • Member since 05-23-2007, 8:51 PM
    • Los Angeles
    • Posts 38

    You can write your own wrapper class to provide the CreateDatabase in this way by passing in the connection strings to the GenericDatabase() in DAAB:
     

    public static Database CreateDatabase(string server, string db, string id, string password, bool integratedSecurity, string dbProviderFactory)
    {
    string connectionString = string.Format("Server={0};Database={1};Integrated Security={2};UID={3};PWD={4}", server, db, integratedSecurity, id, password);
    return new GenericDatabase(connectionString, dbProviderFactory); // dbProviderFactory = System.Data.SqlClient
    }

    It works for me.

    Bill
    Software Developer
    Los Angeles
  • Re: Passing connection string to Enterprise Library DAAB 3.1

    02-09-2009, 4:25 PM
    • Member
      89 point Member
    • nasserdw
    • Member since 11-10-2005, 4:08 PM
    • Amman - Jordan
    • Posts 49
    hello, i am facing problem passing connnection string to the entLib so i am using your method : public static Database CreateDatabase() { string connectionString = App_Settings.portalCnnStr; string dd = "System.Data.SqlClient"; return new GenericDatabase(connectionString,dd); // dbProviderFactory = System.Data.SqlClient } But the GenericDatabase takes string,DbProviderFactory .. so how to pass second parameter?? i used several ways and in all it failed!!
    Be Creative, use your magination
  • Re: Passing connection string to Enterprise Library DAAB 3.1

    05-26-2009, 12:26 PM
    • Member
      10 point Member
    • GTL
    • Member since 08-01-2007, 6:32 AM
    • Edinburgh
    • Posts 7

     If you know that it's definitely an SQL database being used, you can just create a new SqlDatabase rather than GenericDatabase.  Worked for me!

     e.g:

     Database _db = new SqlDatabase(connectionString);

     

     

Page 1 of 1 (4 items)