954,595 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

To use Data acess application block with web application VS 2008

At run time I am getting error requested database does not exist in configuration see at Line 19
string con = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["cn"].ConnectionString;

Line 19:      Database db = DatabaseFactory.CreateDatabase(con);
Line 20: string sqlcmd = "select * from Movies where MovieID<500";
Line 21:  DbCommand dbcommand = db.GetSqlStringCommand(sqlcmd);


In my webconfig i have given required Code in web config

<configSections><section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data"/></configSections>

<connectionStrings><add name="AdventureWorksDB" providerName="System.Data.SqlClient" connectionString="server=localhost;database=AdventureWorks;UID=user;PWD=word;"/><connectionStrings> 
<dataConfiguration defaultDatabase="AdventureWorksDB"/>


i have even added required DLL....
i also configured the EnterPrise Library

i defined there required connection string

followed steps in given link http://www.datadirect.com/developer/net/docs/dot-net-daab.pdf .

but of no result ..

can some one tell me

skumar.snl
Newbie Poster
12 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

your problem is here :
string con = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["cn"].ConnectionString;
you have no connection string with name "cn" your connection string is called AdventureWorksDB this mean you have to write :

System.Web.Configuration.WebConfigurationManager.ConnectionStrings["AdventureWorksDB "].ConnectionString;

vasioky
Newbie Poster
8 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
 

System.Web.Configuration.WebConfigurationManager.ConnectionStrings["AdventureWorksDB "].ConnectionString;

my connection string is same name as in webconfig file..
i checked still getting same error database in not defined in config
Is there any default setting for connection? other then webconfig

skumar.snl
Newbie Poster
12 posts since Dec 2008
Reputation Points: 10
Solved Threads: 0
 

ok the second problem can be also in your web.config declaration. you have to different database but I'm not sure because I never used dataConfiguration tag. Hope this will solve your problem.

<connectionStrings><add name="AdventureWorksDB" providerName="System.Data.SqlClient" connectionString="server=localhost;database=AdventureWorks;UID=user;PWD=word;"/><connectionStrings> 
<dataConfiguration defaultDatabase="AdventureWorksDB"/>
vasioky
Newbie Poster
8 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You