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
nilesh deokarPosted Jul 14, 2009, 6:45 AM
kelum kanchanaPosted Jul 13, 2009, 11:46 PM
Niradhip ChakrabortyPosted Jul 13, 2009, 3:27 PM
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();
hemant parmarPosted Jul 13, 2009, 8:11 AM
use this syntax ...
kelum kanchanaPosted Jul 13, 2009, 7:52 AM
vivek kulkarniPosted Jul 13, 2009, 7:34 AM
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,