Windows 7 32-bit
Libreoffice: 6.2.4.2
MariaSQL: 10.3.13 (ODBC connection)
Hi All,
I have a macro running from the Open File event in the .odb file, which connects to the MySQL database and checks the logged in username and tries to terminate LibreOffice if it is not ‘root’ (Ideally I would prefer if the connection to the database was ended and the user had to log in again,instead of terminating LO, but I’m not sure this can be done from code).
After opening the .odb file, the macro should be executed and connect to database and bring up to login dialog without having to open a form. If the user is not root then close LibreOffice.
The problem is that even though the application windows close as expected and LO seems to be terminated, the sbase.exe, soffice.bin and soffice.exe are still running. Launching the .odb again just doubles the process count without any window showing and I need to kill the processes using task manager.
Any Ideas?
Sub CheckRoot
On Error GoTo ErrorHandler
oDataSource = ThisComponent.CurrentController
If NOT (oDataSource.isConnected()) Then
oDataSource.connect()
End IF
oConnection = oDataSource.ActiveConnection()
oSQL_Statement = oConnection.createStatement()
stSql = "SELECT REGEXP_REPLACE(USER(), '@.*','') AS user"
oQuery_Result = oSQL_Statement.executeQuery(stSql)
If NOT ISNULL(oQuery_Result) Then
oQuery_result.next
dbUser = oQuery_Result.getString(1)
END IF
If (dbUser <> "root") Then
msgbox("You are not authorised to use this system" & dbUser)
oConnection.close()
ThisComponent.close(True)
Wait 2000
starDesktop.terminate ' NOT WORKING '
End If
Exit Sub
ErrorHandler:
Reset
If Err =1 Then
MsgBox "Cannot connect to database" , 16 ,"an error occurred"
Else
MsgBox "Error " & Err & ": " & Error$ + chr(13) + "At line : " + Erl + chr(13) + Now , 16 ,"an error occurred"
End If
End Sub