0

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.

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by uzn
0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.