Hello everyone!
I want to write my connection strings and functions in a class and always call the class when i need to make a connection to my database to avoid code repetition and increase code reuse but i have an error. Here is my code below

Public Class ConnectionString

    Public Shared Function ConnSQL() As SqlConnection
        Dim connectionString As String
        Dim cnn As SqlConnection
        connectionString = "localhost;Initial Catalog=MSS;User ID=;Password="
        cnn = New SqlConnection(connectionString)
            Return cnn
        Catch ex As Exception
            MsgBox("Can not open connection ! ")
        End Try

    End Function

The end function is underlined and states this: Function Sqlconn does not return a null value on all code paths

Try to move your "Return cnn" code to right before your End Function. Hopefully it'll fix. I'm a .net newbie too. :)

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