I have just developed, as an assignment , a small conventional website, commonly used for “Log in “purposes. User enters the UserID and password. User ID is compares from the customer Table, to verify, if the name already exists in database. If yes, he is directed to main page.
Else he is directed to newuser Register page , for providing personal information . This information is added in the database table as a new recordset.

The code in index.aspx.vb file is as under.

Imports System.Data.SqlClient

Partial Class index
    Inherits System.Web.UI.Page

    Private Sub Page_Load(ByVal sender As Object, ByVal e As         				System.EventArgs) Handles MyBase.Load

 	End sub 

    Protected Sub Submit_Click(ByVal sender As Object, ByVal e As 	System.EventArgs) Handles Submit.Click
        Session("Name") = txtusername.Text
        Dim con As New  SqlConnection(System.Configuration. 						ConfigurationManager.AppSettings("Zeedb"))

        Dim dr As SqlDataReader
        'Dim StudentID As String
        Dim strSQL As String = "SELECT * FROM  tblCustomer  WHERE 			CustomerName = '" & txtusername.Text & "' and Password = '" 		& txtPassword.Text & "'"
        Dim cmdSQL As SqlCommand
            cmdSQL = New SqlCommand(strSQL, con)
            dr = cmdSQL.ExecuteReader

            If dr.Read Then
            End If

        Catch ex As Exception
            lblError.Text = ex.Message
        End Try

    End Sub

    Protected Sub newuser_Click(ByVal sender As Object, ByVal e As 			System.EventArgs) Handles newuser.Click
    End Sub
End Class

The Customers file resides in database named “Zeedb “at a Local SQL server in a different directory within the same machine. Web server used is Local Host built-in within the same machine.

The problem I am facing is that when I debug the system, the build up succeeds. However, when data is entered in text boxes (User Name and Password) I receive an error message:

“The ConnectionString property has not been initialized”

As tried to search on MSDN and Google, it seems to be a very common mistake, but I could not find the remedy. The reason of the fault could not be identified.

Please help me pointing out , where is the oversight, which I cannot locate.
Abdul Hayee.

10 Years
Discussion Span
Last Post by sierrainfo

Hi there. Try adding this to your connection string as follows:


Dim con As New  SqlConnection(System.Configuration. 						ConfigurationManager.AppSettings("Zeedb"))


string con = (string) ConfigurationSettings.AppSettings["Zeedb"];

SqlConnection con= new SqlConnection(ConnectionString);

I hope this helps, however I can make no promises as VB is not a language I have delved into all that much. Let us know how it goes. This line of code is where the connection string is initialized:

SqlConnection con= new SqlConnection(ConnectionString);

A connection string needs to be treated like any other object you use in your code, therefore it needs to be initialized before it can be used. Good luck!


Dear friend

any time if you get this type of problem like "The ConnectionString property has not been initialized" or any initalization exception ,pls check the in initialization of that object and class.

ConnectionString="address of sqlserver databse"
SqlConnection con= new SqlConnection(ConnectionString);


I think the problem might be in converting Converting to String

Dim Conn As String = Convert.ToString(ConfigurationManager.AppSettings["xyz"]) 
Dim objConnection As New SqlConnection(Conn) 

It should work. If it doesn't then check your connection string properties.


Just remove this Line: cmdSQL.ExecuteNonQuery() This is not required. ExecuteNonQuery is used for Insert, Update, Delete statements.

Sunil Punjabi
<URL Snipped>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.