Reg:Database Connection
Hi...
Still I am beginner of Asp.net and Sql server 2005 express edition.
Please tell me, how to open the database in web forms which I want. Should I put the database connection in webconfig file or should i put every page?
Thanks
Kelum

vivek kulkarni132 reputationPosted Jul 13, 2009, 3:34 AM EDT
if you want to connect to sql server through visual studio then you can use the server explorer on the view menu of VS. Its recommended that you use the connection string in web.config so that you dont have to include it over and over in every page. And as its xml this also helps when you deploy your project you can also edit it and change the deployed server.
Thank you,
kelum kanchana28 reputationPosted Jul 13, 2009, 3:52 AM EDT
hemant parmar6 reputationPosted Jul 13, 2009, 4:11 AM EDT
use this syntax ...
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Jul 13, 2009, 11:27 AM EDT
Say this is a snippet of my web.config file:
xml version="1.0"?>
<configuration>
<appSettings>
<add key="WebsiteDBConnectionString" value="Server=PC6\SQLEXPRESS;User ID=sa;Password=sa2005;database=MYDB;Max Pool Size=60;Connect Timeout=3000;"/>
appSettings>
<connectionStrings/>
<system.web>
system.web>
configuration>
Now I like to call this connection string inside my webpages. Call it like below:
string myconnectionstring = ConfigurationManager.AppSettings["WebsiteDBConnectionString"].ToString();
kelum kanchana28 reputationPosted Jul 13, 2009, 7:46 PM EDT
nilesh deokar6 reputationPosted Jul 14, 2009, 2:45 AM EDT