We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,417 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

The ConnectionString property has not been initialized. - please help

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

3
Contributors
10
Replies
1 Week
Discussion Span
1 Year Ago
Last Updated
14
Views
Question
Answered
quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Pgmer
Practically a Posting Shark
881 posts since Apr 2008
Reputation Points: 60
Solved Threads: 158
Skill Endorsements: 1

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

quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Pgmer
Practically a Posting Shark
881 posts since Apr 2008
Reputation Points: 60
Solved Threads: 158
Skill Endorsements: 1

What is the value of connectionInfo?

Reverend Jim
Carpe per diem
Moderator
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32

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
quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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.

Reverend Jim
Carpe per diem
Moderator
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32

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

quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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)

Reverend Jim
Carpe per diem
Moderator
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32

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

quentinqid
Newbie Poster
5 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Reverend Jim
Carpe per diem
Moderator
3,614 posts since Aug 2010
Reputation Points: 563
Solved Threads: 452
Skill Endorsements: 32
Question Answered as of 1 Year Ago by Reverend Jim and Pgmer

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0923 seconds using 2.72MB