0

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

2
Contributors
3
Replies
5
Views
8 Years
Discussion Span
Last Post by vasioky
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;

0

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

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"/>
This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.