DatabaseFactory.CreateDatabase() error

Topics: Data Access Application Block
Dec 28, 2010 at 10:55 AM

Hi,

I am trying to get data access to an SQL Server from a .NET class library running as an Add-In under AutoCAD 2011. I'm using the Data Access Application Block (DAAB). The data acces is in a separate assembly, that have worked perfectly well for similar add-in scenarios under Word, Excel and Visio. In these scenarios, I just had to make sure that a xxx.dll.config file existed in the folder where the Add-In assembly was deployed. The config file contains:

 <configuration>
  <configSections>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
  </configSections>
  <dataConfiguration defaultDatabase="AET18"/>
  <connectionStrings>
    <add name="AET18" connectionString="Database=AET;Server=AET18;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

 When calling DatabaseFactory.CreateDatabase() I get the error message: Activation error occurred while trying to get instance of type Database, key ""

 I have seen this error message before (using it under Word or Excel), namely when i failed to place a xx.dll.config file in the directory where the add-in resided. So it seems that the enterprise library can't find the config file and thus can't read the connection strings.

 Where should I put the config info?

Dec 29, 2010 at 1:10 AM

I haven't dealt with add-ins but I know that class libraries don't own configuration files.  If you need your entlib code which is in a class library to make use of a config file, you can create an instance of FileConfigurationSource and pass it to the corresponding factory class of the application block you're using.  This approach is discussed in this blog.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com