1
Vote

Activation error occured while trying to get instance of type Database, key "DBName"

description

<p>Im using Enterprise library 5.0</p> <p>I have a scenario, where I have to access two different databases in my application.</p> <p>&nbsp;</p> <p>Basically this application is a webservice,delployed on my local for testing purpose.</p> <p>I&#39;m trying to access this web method from diffent windows application, default connection works fine but the other database throw&#39;s exception.</p> <p>&nbsp;</p> <p>Problem is only my defaultDatabase is works fine, if I change defaultDatabase=&quot;MYCON1&quot; with &quot;MYCON2&quot; it works fine, if I try to access the other database which is not default, throws exception.</p> <p>&nbsp;</p> <p> &lt;dataConfiguration defaultDatabase=&quot;MYCON1&quot; /&gt;</p> <p> &lt;connectionStrings&gt;</p> <p> &lt;add name=&quot;MYCON1&quot; connectionString=&quot;Data Source=server1;Initial Catalog=dbName1;User Id=Username1;Password=password1;&quot;</p> <p> providerName=&quot;System.Data.SqlClient&quot; /&gt;</p> <p> &lt;add name=&quot;MYCON2&quot; connectionString=&quot;Data Source=Server2;Initial Catalog=dbName2;User Id=Username2;Password=password2;&quot;</p> <p> providerName=&quot;System.Data.SqlClient&quot; /&gt;</p> <p> &lt;/connectionStrings&gt;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p> Database myDB=EnterpriseLibraryContainer.Current.GetInstance&lt;Database&gt;(); --&gt; works fine for the default database (MYCON1)</p> <p>&nbsp;</p> <p>&nbsp;</p> <p> Database myDB=EnterpriseLibraryContainer.Current.GetInstance&lt;Database&gt;(&quot;MYCON2&quot;); --&gt; Error message, see below</p> <p>&nbsp;</p> <p>&nbsp;</p> <p> Activation error occured while trying to get instance of type Database, key &quot;MYCON2&quot;</p>

comments

ctavares wrote Aug 6, 2010 at 10:20 PM

I do this sort of thing all the time and it works fine; I'm unable to reproduce the issue from the information here. Could you post a small but complete example that demonstrates the problem so I have something I can use to track it down?