I am using VS 2005. I am trying to get the connectionstring from the Web.config file.
As per the Msdn as well as search on the google, most of the code days to use ConfigurationManager.Appsettings --> for getting the string from the file.
But when I am going deep into the System.Configuration dll, I am not able to find the ConfigurationManager class.
Please help me to reterive the connectionstring from the config file.
Yes, I had already added the reference. Also I tried to use the System.Web.Confirguration Namescape so that I can get the webConfigurationmanager class.
1) I got a compilation error saying that "Error 1 'ConnectionString' is not a member of 'System.Configuration.ConfigurationManager' since the property has to be changed to "ConnectionStrings" (may be typo error in your code).
2) After changing the above it is working as expected.
Here is my sample code for reference;
Imports System
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Web
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Write(GetConnectionString())
End Sub
Private Function GetConnectionString() As String
Dim lsSettings As String
lsSettings = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ToString
GetConnectionString = lsSettings
End Function
End Class
Yes, in the forum it is typo error. But in the IDE it is giving me error that ConfigurationManager class cannot be found.
Also to ensure that I cross-checked the same in the Object Browser. I could not get the ConfigurationManager class. I found ConfigurationSettings class.