.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

get connection string from web.config in asp.net 3.5

Posted By:Rahul       Posted Date: February 05, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

get connection string from web.config in asp.net 3.5 is different from ASP.Net 1.1. Below the code to declare connectionstring in our web.config file.

In Asp.Net 2.0 and Asp.Net 3.5 we have new Tag Inside Web.config file that is ConnectionString Tag

add name="MyConnectionString" connectionString="Server=ServerName;Database=YourDBName;Uid=YOURUSerId;Pwd=YourDBPassword;"/>

Now to get the Connection string defined in the web.config file you have to do like this in your .csĀ  file below code is based on c#

string Conn= ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString;


Dim Conn as String = ConfigurationManager.ConnectionStrings("MyConnString").ConnectionString


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend