Simple Way to Access the connection string value from web.config file

It's very simple to access the connection string in the project to establish connection from web.config file.
Here is the code

start with "<" 'appSettings' and close with ">"
"<"add key="sqlconnstr" value="Data source=Database ServerName;database=DatabaseName;user id=UserId;password=Password;connect timeout=0;" "/>"

inside Code Behind

SqlConnection sqlconn;
sqlconn = new SqlConnection(ConfigurationManager.AppSettings["sqlconnstr"].ToString());

you can access anywhere in your project.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: