locked
Passing connection string to Enterprise Library DAAB 3.1 RRS feed

  • Question

  • User-1774624993 posted

    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!

    Monday, June 11, 2007 5:37 PM

All replies

  • User1391537864 posted

    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.

    Monday, June 18, 2007 7:50 PM
  • User-1167591364 posted
    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!!
    Monday, February 9, 2009 4:25 PM
  • User-1297688506 posted

     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);

     

     

    Tuesday, May 26, 2009 12:26 PM
  • User943353164 posted

    Hello,

    string dbFactory= "System.Data.SqlClient"

            db = New GenericDatabase(connectionString, DbProviderFactories.GetFactory(dbFactory))

     

    Tuesday, May 3, 2011 2:07 PM