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