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

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.