C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Visual Studio »

how to use a connection the web.config


Posted Date: 29 Sep 2008    Resource Type: Code Snippets    Category: Visual Studio
Author: Pinky shahMember Level: Bronze    
Rating: 1 out of 5Points: 5



This code shows how to get connection string from web.config.

<configuration>
<appSettings>
<add key="ConStr" value="server=localhost,;database=db;uid=uid;password=pwd;"/>
</appSettings>
<connectionStrings>
<add name="ConnectionString1" connectionString="Data Source=sql;Initial Catalog=database;User ID=uid"
providerName="System.Data.SqlClient" />
</connectionStrings>


write the code in the class/weboform(page_load)
-----------------------------------------------

Public Shared ReadOnly Property ConnectionString() As String
Get
Return System.Configuration.ConfigurationManager.AppSettings("ConStr")
End Get
End Property

Public Conn As New SqlConnection()

Public Sub OpenConnection()
Try
If (Conn.State = ConnectionState.Open) Then
Conn.Close()
Conn.ConnectionString = ConnectionString
Conn.Open()
Else
Conn.ConnectionString = ConnectionString
Conn.Open()
End If

Catch ex As Exception
End Try
End Sub


like wise u can establish a connection:
Any doubts please contact me




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Web.config  .  How to use a connection the web.config  .  Get  .  Connection string  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to deploy dot net application to pc having 2 versions of framework
Previous Resource: How to add a windows control library template to Visual C# Express
Return to Discussion Resource Index
Post New Resource
Category: Visual Studio


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use