Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.

the error is here: line 20

Line 18: cn.ConnectionString = connectionInfo
Line 19: If cn.State = ConnectionState.Closed Then
Line 20: cn.Open()
Line 21: End If
Line 22: Dim da As New SqlDataAdapter("select c_name from country order by c_name ", cn)


how can i solve this problem? thanks

Recommended Answers

All 10 Replies

If cn.State = ConnectionState.Closed Then
again u need to initilize the connection like cn=new Sqlconnection and cn.connectionstring=connectionInfo

is it in line 20 or what? thanks for your response.. sorry my lack of knowledge. i'm really new. thanks

After 19 and vefore line 20 u need to initialize the connetion to SQL again

hera i post the full coding

Imports System.Data
Imports System.Data.SqlClient
Partial Class login
    Inherits System.Web.UI.Page

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Response.Redirect("register.aspx")
    End Sub

    Protected Sub BtnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnLogin.Click
        'validate player

        If TxtEmailID.Text.Trim = "" Then
            ClsMain.CreateMessageAlert(Me, "Enter email id.", "123")
            Exit Sub
        End If

        If TxtPassword.Text.Trim = "" Then
            ClsMain.CreateMessageAlert(Me, "Enter password.", "123")
            Exit Sub
        End If

        Dim connectionInfo As String
        connectionInfo = ConfigurationManager.AppSettings("echess")
        Dim cn As New SqlConnection()
        cn.ConnectionString = connectionInfo
        If cn.State = ConnectionState.Closed Then
            cn.Open()
        End If


        Dim da As New SqlDataAdapter("select * from eg_player where pl_email_address='" & TxtEmailID.Text & "' and pl_password='" & TxtPassword.Text & "'", cn)
        Dim dt As New DataTable()
        da.Fill(dt)
        If dt.Rows.Count = 1 Then
            If dt.Rows(0)("pl_is_validated") = 0 Then
                ClsMain.CreateMessageAlert(Me, "Can not login, Your membership is not approved by the Admin.", "123")
                Exit Sub
            End If

            Session("mem_id") = dt.Rows(0)("pl_id").ToString()
            Session("mem_name") = dt.Rows(0)("pl_real_name").ToString()
            Session("mem_email_id") = dt.Rows(0)("pl_email_address").ToString()


            If Session("ret_url") = "" Then
                Response.Redirect("player.aspx")
            Else

                Response.Redirect(Session("ret_url").ToString())
            End If

        Else

            ClsMain.CreateMessageAlert(Me, "Can not login, Inavlid email id/password.", "123")

        End If

    End Sub
End Class

You have

connectionInfo = ConfigurationManager.AppSettings("echess")

but I still don't know what the value of connectionInfo is. I need to know the actual contents of ConfigurationManager.AppSettings("echess") to see if it is a valid connection string.

sorry if this sound stupid. where can i get the value. is it from web config file?

You can go to Project -> Properties -> Settings

Or you can set a breakpoint just after

connectionInfo = ConfigurationManager.AppSettings("echess")

or you can add the following line after that

MsgBox(connectionInfo)

after go to Project -> Properties -> Settings, where can i get it? thanks

There should be an entry in the displayed list for "echess". What is the value?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.