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


Top 5 Contributors of the Month
david stephan

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

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

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;

In Vb.NET

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


     

Further Readings:

Responses

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