Colleagues,
Here's the code:
And here's what's happening when I tried to Save this module:
Could you explain to me why the System doesn't see that loSqlConnection was 1. Declared, 2. Assigned a value of a proper type in the TRY-CATCH-EMDTRY construct?
And how do I fix this glitch?
TIA!
Regards,
Ilya
Here's the code:
Code:
'====================================================================================================================================
Private Function Test_SQL_Connection() As Boolean
'===================================================================================================================================
' Purpose : Tests the connection to the SQL Server.
' Description : Uses global memvar gcConnectStrDB to connect to the specified DB Server and open the specified database.
' Parameters : None.
' Returns : Success as Boolean.
' Side effects : None.
' Notes : 1. Application-specific.
' 2. Verbose on errors, silent otherwise.
' Author : Ilya I. Rabyy
' Revisions : 2020-07-30 by Ilya – started 1st draft.
'===================================================================================================================================
Dim llRet As Boolean = True ' Initially
Dim lcErrMsg As String = "", loSqlConnection As SqlConnection, loErr As Exception
Try
loSqlConnection = New SqlConnection(gcConnectStrDB)
Catch loErr
llRet = False
gcProcLog = gcProcLog & Now.ToString("yyyy-MM-dd HH:mm:ss") & ": ERROR OCCURED!" & vbCrLf & Space(21) & loErr.Message & _
vbCrLf & "Occured in " & vbCrLf & loErr.Source & vbCrLf & loErr.StackTrace & vbCrLf & Space(21) & _
"Program quits." & vbCrLf
gcErrStr = "Error occurred when testing SQL Server Connection." & "See details in the " & gcLogFile & vbCrLf & _
"Program quits."
gcProcLog = gcProcLog & Space(21) & "Program quits." & vbCrLf
File.WriteAllText(gcLogFile, gcProcLog) ' There's not much text in the Process Log string yet, write it all anyway
MsgBox(gcErrStr, MsgBoxStyle.Critical, gcAppName)
End Try
If Not llRet Then
Return llRet
End If
gcProcLog = gcProcLog & Now.ToString("yyyy-MM-dd HH:mm:ss") & ": Sql Connection tested successfully." & vbCrLf
loSqlConnection.Close()
Return llRet
End Function
Could you explain to me why the System doesn't see that loSqlConnection was 1. Declared, 2. Assigned a value of a proper type in the TRY-CATCH-EMDTRY construct?
And how do I fix this glitch?
TIA!
Regards,
Ilya