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

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;

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

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"/>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.