1,105,534 Community Members

The ConnectionString property has not been initialized. - please help

Member Avatar
quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Pgmer
Practically a Posting Shark
881 posts since Apr 2008
Reputation Points: 50 [?]
Q&As Helped to Solve: 158 [?]
Skill Endorsements: 3 [?]
Featured
 
0
 

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

Member Avatar
quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Pgmer
Practically a Posting Shark
881 posts since Apr 2008
Reputation Points: 50 [?]
Q&As Helped to Solve: 158 [?]
Skill Endorsements: 3 [?]
Featured
 
0
 

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

Member Avatar
Reverend Jim
Noli mentula
5,447 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

What is the value of connectionInfo?

Member Avatar
quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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
Member Avatar
Reverend Jim
Noli mentula
5,447 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

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.

Member Avatar
quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Reverend Jim
Noli mentula
5,447 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

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)

Member Avatar
quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Reverend Jim
Noli mentula
5,447 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

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

Question Answered as of 2 Years Ago by Reverend Jim and Pgmer
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: