Enterprise Data Library - Calling two databases

Topics: Data Access Application Block
Dec 26, 2012 at 5:45 AM
Edited Dec 26, 2012 at 5:47 AM

When i first login to the database, I connect to DB-A to get user information, this user information is stored in session..
I am able to get the user information from DB-A. Then when I go to the next page, I need to connect to DB-B which has all the other required information.

I am using EntLib Data and have set up my DB factory class as

public static class DbFactory
        /// <summary>
        /// Create an instance of default database connection.
        /// </summary>
        /// <returns>Database Object</returns>
        public static Database Create()
            return DatabaseFactory.CreateDatabase();

        /// <summary>
        /// Creates an instance of a specified database connection.
        /// </summary>
        /// <param name="name">Database Object</param>
        /// <returns></returns>
        public static Database Create(string name)
            return DatabaseFactory.CreateDatabase(name);

Now in the Page after login I am trying to access Db-B by passing the connection string in the Create(name) method. Getting an "activation error occured while trying to get instance of type database".

Can you please help me in resolving this error or letting me know how to connect to different databases using EntLib.


Dec 26, 2012 at 5:56 AM
Edited Dec 26, 2012 at 5:57 AM

"I am trying to access Db-B by passing the connection string in the Create(name) method".

The Create() method accepts the name of the database connection as defined in configuration not the database connection string.  Usually, you would configure the connectionStrings in the web.config and then pass in the name of the connection required.  If you don't know the connection string ahead of time you can configure the Data Access Application Block programmatically using the Fluent API.

Randy Levy
Enterprise Library support engineer
Support How-to 

Dec 26, 2012 at 6:15 AM

Thanks Randy that worked.. duh ..