-1

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)
        Try
            cnn.Open()
            Return cnn
        Catch ex As Exception
            MsgBox("Can not open connection ! ")
        Finally
            cnn.Close()
        End Try

    End Function

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

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Netcode
0

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