Start New Discussion within our Software Development Community

HI,

I'm getting the object refernce not set to an instance of an object error in the code below.

I couldnt figure it out, where I'm going wrong.
Please help.

Public Function GetConnection() As SqlConnection
        Dim connectionString As New SqlConnection()
        Dim Conn As String = Nothing
        Conn = ConfigurationManager.ConnectionStrings("connectionString").ConnectionString

        Dim objConnection As New SqlConnection()
        objConnection.ConnectionString = Conn

        Return objConnection

    End Function

The error is on the 4th line of the code.

HI,

I'm getting the object refernce not set to an instance of an object error in the code below.

I couldnt figure it out, where I'm going wrong.
Please help.

Public Function GetConnection() As SqlConnection
        Dim connectionString As New SqlConnection()
        Dim Conn As String = Nothing
        Conn = ConfigurationManager.ConnectionStrings("connectionString").ConnectionString

        Dim objConnection As New SqlConnection()
        objConnection.ConnectionString = Conn

        Return objConnection

    End Function

The error is on the 4th line of the code.

the error was because the connection string in the web.config did not match the connection String in the function above. I changed the string in web.config and error got resolved.
Thanks

This question has already been answered. Start a new discussion instead.