Testar oConnection = oDataSource.GetConnection Is_already_connected?

Function Ligar_se_a_DB As Object

Dim DatabaseContext As Object
Dim oDataSource As Object
Dim InteractionHandler As Object
Dim sPwd As String
Dim MyString, x As String
Dim i as Integer
Dim Ligado As Boolean
i=909
x = CInt( i )
MyString = String(5, “0”) + x ’ Returns “*****”.

’ Usando Firebird via ODBC

’ Ligar-se à base de dados
DatabaseContext = createUnoService(“com.sun.star.sdb.DatabaseContext”)
oDataSource = DatabaseContext.getByName(“GestACRA”) ’ C:\Users\Minha Pasta\Documents\GestACRA.odb

’ ??? Ligado = oDataSource.IsConnect ??

If Not oDataSource.IsPasswordRequired Then
oConnection = oDataSource.GetConnection("","") ’ User/Pwd=Leitura apenas
Else
InteractionHandler = createUnoService(“com.sun.star.sdb.InteractionHandler”)
oConnection = oDataSource.ConnectWithCompletion(InteractionHandler)
'oConnection.SetReadOnly( False ) ‘’ não pode em ligações partilhadas
End If

If Not IsNull (oConnection) Then
If oConnection.ISCONNECT ??? Then
Ligar_se_a_DB = oConnection
Else
S MsgBox "Não foi possível. A ligação terminou em erro! "
End If

End Function ’ Ligar_se_a_DB
Atentamente
Mário Reis

Function Ligar_se_a_DB
Dim DatabaseContext As Object
Dim oDataSource As Object
Dim InteractionHandler As Object
Dim sPwd As String
Dim MyString, x As String
Dim i as Integer
Dim Ligado As Boolean
i=909
x = CInt( i )
MyString = String(5, "0") + x ' Returns "*****".

' Usando Firebird via ODBC
On Error goto myError

' Ligar-se à base de dados
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
oDataSource = DatabaseContext.getByName("GestACRA") ' C:\Users\Minha Pasta\Documents\GestACRA.odb

' ??? Ligado = oDataSource.IsConnect ??
If Not oDataSource.IsPasswordRequired Then
oConnection = oDataSource.GetConnection("","") ' User/Pwd=Leitura apenas
Else
InteractionHandler = createUnoService("com.sun.star.sdb.InteractionHandler")
oConnection = oDataSource.ConnectWithCompletion(InteractionHandler)
'oConnection.SetReadOnly( False ) ‘’ não pode em ligações partilhadas
End If
Ligar_se_a_DB = "open"
Exit Function
MyError:
Ligar_se_a_DB = "closed"

End Function ' Ligar_se_a_DB

Hello!
This was’nt what i had in mind! I was asking for some something belted in as they have for Base
data_source = ThisDatabaseDocument.DataSource
I’m not finding it now but i believe i already in Base i saw something like this if not data_Source.isconect then data_source.Connect built in methods?! Am i wrong. But i do not foud information about it
Can any one help!best regards

Mário Agostinho Reis
919262146

Esta mensagem contém informação de natureza confidencial e é
exclusivamente dirigida ao(s) destinatário(s) indicado(s). Se, por engano,
receber este email agradecemos que não o copie nem o reenvie e que nos
notifique do ocorrido através do email de resposta.

Ratslinger via Ask LibreOffice <noreply@ask.libreoffice.org> escreveu no dia sexta, 4/11/2022 à(s) 01:33:

    if IsNull(Thisdatabasedocument.CurrentController.ActiveConnection) then
       Thisdatabasedocument.CurrentController.connect
    endif

Available from Base. ThisDatabaseDocument not available in Writer or Calc.
.
Disponível na Base. ThisDatabaseDocument não disponível no Writer ou Calc.
.
Edit:
Standalone forms have ThisComponent available. Have given you that information already.
.
Formulários autônomos têm ThisComponent disponível. Já lhe dei essa informação.

Thank you Ratslinger.
If it’s not available in swriter or scalc, then there’s nothing to do! Even the King loses!
Best regards

Ratslinger via Ask LibreOffice <noreply@ask.libreoffice.org> escreveu no dia sábado, 19/11/2022 à(s) 02:16: