Adding reference to ENterprise Library DLL in a Class library Project

Topics: Data Access Application Block
Apr 29, 2009 at 4:26 AM
Edited Apr 29, 2009 at 7:47 PM
Hello,

I have a class Library Project in C# .NET . In That I have added referenece to the Ent Lib 3.1 Data ACcess APplication DLL's . I have added an app.config to the CLass Library project and Using the entlibraryconfig.exe I have created the connection string in APP.COnfig .
I now need to access the app.config from the class library for creating the Db:
db = DatabaseFactory.CreateDatabase("conn");
However since it is a class library project, it cannot read from the APP.config file.

I need a Class library because I need to reference this DLL from Biztalk application.

Please suggest what are my options for creating the connection string to get accessed from the class library project.

Thank you.
Apr 29, 2009 at 7:36 AM
Hi,

One option for you is to put the DAAB information in the application that will host the class library which is your biztalk application. Also, you can try to use the IConfigurationSource to read your app.config, you can learn more about IConfigurationSource here: http://codebetter.com/blogs/david.hayden/archive/2006/01/08/136360.aspx .

Here is a code snippet for IConfigurationSource:

 

string configPath = GetConfigPath();
IConfigurationSource source = new FileConfigurationSource(configPath);
DatabaseProviderFactory providerFactory = new DatabaseProviderFactory(source);
Database db = providerFactory.Create("MyDatabase");

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com