I try to use 2 macro's and a OObase to now who has opened or closed a Writerdoc. When the doc is read-only then the user is told who is using the Opened Doc. For no obvious reasons , and from time to we endup with a "locked" OObase (.lck file) or the connection turned into "read-only" and then all-users have to close OO and their quickstarter to Unlock the OObase

Some questions due to lack of documentaion:

- what is the differens between "getConnection "and "getIsolatedConnection" (who seams to funcytion better) - how do i can control the "open" or "used" connections to a datasource, ,we found "hasConnections" but no way to uses this service
- why and when turns a conncetion into "read-only"


We do not uses the Pooling and the rough code looks like :

Sub Connect_in
Dim oDatumTijd As New com.sun.star.util.DateTime

   on local error goto SLUITEN
   oBaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
   sName = ConverttoURL("T:\dbOPMAAK\OPMAAK.odb")
   oDataSource = oBaseContext.getByName(sName)
      oCon = oDataSource.getIsolatedConnection("", "")
     oStatement = oCon.createstatement
oresultSet = oStatement.executeQuery("select ""In_Use"",""USER"",""Tijd"" from ""Artikel_URL"" where ""URL"" = '" & ucase(thisComponent.URL) & "'" oresultSet.next
if Thiscomponent.isreadonly = False then
   if oresultSet.row = 0 then
sQuery = "INSERT INTO ""Artikel_URL"" (""URL"",""In_Use"",""USER"",""Tijd"") values (?,?,?,?)"
   oStatement = oCon.PrepareStatement(sQuery)
   oDatumtijd =  DateToUNODateTime(Now)
   oStatement.SetTimestamp(4 ,oDatumtijd)
   oStatement.Setstring( 1 ,ucase(Thiscomponent.URL))
   oStatement.SetBoolean( 2 , True)
   oStatement.Setstring( 3 , environ("USERNAME"))
    oStatement.executeUpdate()
   else
sQuery = "UPDATE ""Artikel_URL"" SET ""In_Use"" = ? , ""USER"" = ? , ""Tijd"" = ? WHERE URL = ? "
   oStatement = oCon.PrepareStatement(sQuery)
   oDatumtijd =  DateToUNODateTime(Now)
   oStatement.SetTimestamp(3 ,oDatumtijd)
   oStatement.SetBoolean( 1 , True)
   oStatement.Setstring( 2 , environ("USERNAME"))
   oStatement.Setstring( 4 ,ucase(Thiscomponent.URL))
   oStatement.executeUpdate()
   endif
else
   if oresultSet.row = 0 then
print "Er is een probleem met deze file !!! ze is in gebruik maar door wie weten we niet ????????"
   else
print "Deze file is in gebruik door " & oresultset.getString(2) & " sinds " & mid(oresultset.getString(3),9,2) & "-" & mid(oresultset.getString(3),6,2) & mid(oresultset.getString(3),11,6)
   endif
  endif
oCon.close()
oCon.dispose()

exit sub
SLUITEN:
if Isnull(oCon) then
exit sub
else
oCon.close()
oCon.dispose()
exit sub
endif
End Sub

Sub Connect_out
'   on local error goto SLUITEN

   if thiscomponent.isreadonly = False then
   oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
   sName = ConverttoURL("T:\dbOPMAAK\Opmaak.odb")
   oDataSource = oBaseContext.getByName(sName)
   oCon = createUnoService("com.sun.star.sdbc.drivers.OConnectionWrapper")
   oCon = oDataSource.getIsolatedConnection("", "")

sQuery = "UPDATE ""Artikel_URL"" SET ""In_Use"" = ? , ""USER"" = ? , ""Tijd"" = ? WHERE URL = ? "
   oStatement = oCon.PrepareStatement(sQuery)
   oDatumtijd =  DateToUNODateTime(Now)
   oStatement.SetTimestamp(3 ,oDatumtijd)
   oStatement.SetBoolean( 1 , False)
   oStatement.Setstring( 2 , environ("USERNAME"))
   oStatement.Setstring( 4 ,ucase(Thiscomponent.URL))
   oStatement.executeUpdate()
oCon.close()
oCon.dispose()

   else
   endif
exit sub
SLUITEN:
if Isnull(oCon) then
exit sub
else
oCon.close()
oCon.dispose()
exit sub
endif

End Sub

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to