Text Template (.tt) files using EntLib3.1 issue.

Topics: Data Access Application Block
Mar 17, 2008 at 3:50 PM
When I have a DatabaseFactory.CreateDatabase("XXXX"); call in my .tt file, it cant seem to find the app.config file in my project.

I have verified my code works with a unit test but when the Text Template engine runs it seems to not look in the project for the app.config file.

Is there a way to set the connection for the database factory at run time so that I do not have to rely on the app.config file?

Mar 21, 2008 at 2:27 PM
Hi Henry,

The text template engine doesn't know about your project's app.config file, regardless of whether it contains entlib configuration or not.
You could try to load the configuration file manually, either by reading the raw xml or creating a FileConfigurationSource on it and pass it to create an instance of the DatabaseProviderFactory class to get your Database instance.

Mar 21, 2008 at 3:29 PM
Please forgive my ignorance, but i didnt notice any overloads of the DPF constructor for this purpose.

I very much appreciate the reply, Im sure this is more of a TT question but they dont have a nice community like you guys!
Mar 21, 2008 at 6:31 PM
Ahh I missed the DatabaseProviderFactory. This worked great. Thank you!
Here is a snippet:

IConfigurationSource configSource = new FileConfigurationSource(@"C:\App.config");
DatabaseProviderFactory dpf = new DatabaseProviderFactory(configSource);
Database db = dpf.Create();

Thanks again.