'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#AdditionalJar: mssql-jdbc-6.4.0.jre9.jar
#End Region
Sub Process_Globals
'
Public SQLServer As SQL
Private IntentConectDataBase As Int = 1
Private Conecto As Boolean = False
'
End Sub
Sub AppStart (Args() As String)
'
Try
'
Do While IntentConectDataBase <= 5
'
Log($"IntentConectDataBase: ${IntentConectDataBase} [${DateTime.Date(DateTime.Now)} ${DateTime.Time(DateTime.Now)}]"$)
'
ConectarBaseSQL
Wait For ConectarBaseSQL_Complete
'
IntentConectDataBase = IntentConectDataBase + 1
'
Loop
'
If Conecto = False Then
Log($"No se puedo contar a la base de datos en ${IntentConectDataBase - 1} intentos...!!!"$)
End If
'
StartMessageLoop
'
Catch
Log($"AppStart: ${LastException}"$)
End Try
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Private Sub ConectarBaseSQL
Try
'
Dim ServidorDB As String= "OMAR-PC-1"
Dim InstanciaDB As String= "MSSQL2008R2E"
'
SQLServer.Initialize("com.microsoft.sqlserver.jdbc.SQLServerDriver" ,$"jdbc:sqlserver://${ServidorDB};instanceName=${InstanciaDB};databaseName=BD_Mensajero;Trusted_Connection=yes;user=user1;password=123456789"$)
'
Log("***")
Log("SERVIDOR INICIADO EL: " & DateTime.Date(DateTime.Now) & " " & DateTime.Time(DateTime.Now))
If SQLServer.IsInitialized Then
Log("CONECTADO A LA BASE DE DATOS: OK")
'
IntentConectDataBase = 5
Conecto = True
'
Else
Log("NO SE CONECTADO A LA BASE DE DATOS: VERIFIQUE")
End If
Log("***")
'
Catch
Log($"Error in ConectarBaseSQL [${DateTime.Date(DateTime.Now)} ${DateTime.Time(DateTime.Now)}]: ${LastException}"$)
End Try
'
Sleep(10000)
Log($"Pause 1 min ok [${DateTime.Date(DateTime.Now)} ${DateTime.Time(DateTime.Now)}] "$)
CallSubDelayed(Me,"ConectarBaseSQL_Complete")
'
End Sub