Connection String

Topics: Data Access Application Block
Nov 4, 2011 at 1:49 PM

I'm having issues obtaining a correct connection string.  I have setup references in my web.config as such below:

<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" 

/>

 and

<

add name="eMarketPlaceConnectionString" connectionString="Data Source=AIPHLSQL012;Initial Catalog=eMarketplaceTest;User ID=sa; Password=**********" providerName="System.Data.SqlClient"  

/>

 The password I have made asterisks for security purposes.  I try to access data inside this database with a simple call listed below and I get this error message:

Database

 

 

 

db = DatabaseFactory.CreateDatabase();

This is my error:

Password - db.connection.String' threw an exception of type 'System.ArgumentOutOfRangeException'

I drill into it and it says - Length cannot be less than zero.

I know that this is a valid connection string. 



Has anyone ever come across this issue in Enterprise Library 5.0?

Any hep wouold be greatly appreciated.

Jim

Nov 4, 2011 at 10:25 PM

If you are not passing in a database name to CreateDatabase you will have to setup a default database.  

The configuration should look something like:

<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="eMarketPlaceConnectionString"/>
  <connectionStrings>
    <add name="eMarketPlaceConnectionString" 
         connectionString="Data Source=AIPHLSQL012;Initial Catalog=eMarketplaceTest;User ID=sa;Password=**********"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com