locked
Error connecting to database using Enterprise library 4.0 RRS feed

  • Question

  • User922347322 posted
    Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p><o:p> </o:p>I’m trying to connect to sql server 2008 through my .Net web application.<o:p></o:p>I’m using enterprise Libray 4.0 Data Access Application Block (DAAB).<o:p></o:p>My class which is a wrapper over DAAB has the following code.<o:p></o:p><o:p> </o:p>

    reader = DatabaseFactory.CreateDatabase("MyDBConn").ExecuteReader(commandType, commandText);

    <o:p></o:p> <o:p> </o:p>When this line is executed, am getting a run-time error with the message:<o:p></o:p>“The requested database MyDBConn is not defined in configuration.”

    <o:p></o:p>
    For testing purpose, my .Net solution has a asp.net web project and a class library which includes the above C# code.<o:p></o:p>My aspx codebehind(part of my web project) is calling this class library.<o:p></o:p><o:p> </o:p>My app.config looks like this:<o:p></o:p>App.config:<o:p></o:p><?xml version="1.0" encoding="utf-8"?><o:p></o:p><configuration><o:p></o:p>    <configSections><o:p></o:p>        <section name="dataConfiguration" <o:p></o:p>                 type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, <o:p></o:p>                 Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, <o:p></o:p>                 PublicKeyToken=31bf3856ad364e35" /><o:p></o:p>    </configSections><o:p></o:p>    <connectionStrings>        <o:p></o:p>      <add name="MyDBConn" connectionString="Database=MyDB;Server=MYSERVER;UID=guest;PWD=guest;User Instance=false"<o:p></o:p>      providerName="System.Data.SqlClient" /><o:p></o:p>    </connectionStrings><o:p></o:p>  <dataConfiguration defaultDatabase="MyDBConn"/><o:p></o:p></configuration><o:p></o:p><o:p> </o:p><o:p>And Stacktrace during the run-time error is:</o:p><o:p>"at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](IReadWriteLocator locator, ILifetimeContainer lifetimeContainer, String id, IConfigurationSource configurationSource)
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.EnterpriseLibraryFactory.BuildUp[T](String id, IConfigurationSource configurationSource)
       at Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.NameTypeFactoryBase`1.Create(String name)
       at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.CreateDatabase(String name)
       at Fulton.DataAccessLayer.DBManager.ExecuteReader(CommandType commandType, String commandText) in "</o:p>
    <o:p></o:p> <o:p> </o:p><o:p></o:p> <o:p></o:p> <o:p>Am I missing something? </o:p>Kindly help.<o:p></o:p><o:p></o:p> 

    Thanks!

    Ed<o:p></o:p>
    Tuesday, September 30, 2008 8:43 PM

All replies

  • User-425639139 posted

     As mentioned in your query you are adding the Connection string in the App.Config try adding the same on web.config of your Application and then access.

    Wednesday, October 1, 2008 12:52 AM