| View previous topic :: View next topic |
| Author |
Message |
shambhagwat General User

Joined: 07 Jul 2010 Posts: 7
|
Posted: Tue May 22, 2012 6:03 am Post subject: Password Protection to Base |
|
|
I am working on project of tracking receipts from students.
The Database name is "AbhijatTrial.odb".
There are two tables. 1. Student and 2. Receipts
I want to set up a username and password for the database.
So I created two Subs in a blank odt file as under
1. SetUserAndPassword
This Sub sets username and password.and IsPasswordRequired property.
msgbox function states that new setting has been made.
All is working fine.
after excuting this sub it was disabled in Main Sub
the odt file was saved and closed and reopened to run the next sub
2. GetConnecton
This Sub try to get connection.
After testing IsPasswordRequired in the if clause
the programme step into the line
InteractionHandler = createUnoService("com.sun.star.sdb.InteractionHandler")
So we can say that value of IsPasswordRequired property is True.
But InteractionHandler is not invoked in the next line i.e.
Connection = DataSource.ConnectWithCompletion(InteractionHandler)
Instead the "AbhijatTrial.odb" is opened.
What is wrong with the code?
| Code: |
'***************************
Main
'**************************
'Disabled after first run
' SetUserAndPassword
GetConnecton
End Sub
'************************************************************************************************
|
| Code: |
'***********************************
Sub SetUserAndPassword
'***********************************
Dim DatabaseContext As Object
Dim DataSource As Object
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("abhijattrial")
DataSource.User = "abcd"
DataSource.Password = "efgh"
DataSource.IsPasswordRequired = True
'Checking of the settings
msgbox("DataBase Name : " & DataSource.name)
msgbox("URL : " & DataSource.URL)
msgbox("IsPasswordRequired : " & DataSource.IsPasswordRequired)
msgbox("User :" & DataSource.User)
msgbox("Password :" & DataSource.Password)
End Sub
'***********************************************************************************
|
| Code: |
Sub GetConnecton
'******************************
Dim DatabaseContext As Object
Dim DataSource As Object
Dim Connection As Object
Dim InteractionHandler as Object
DatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
DataSource = DatabaseContext.getByName("abhijattrial")
msgbox(DataSource.IsPasswordRequired)
If Not DataSource.IsPasswordRequired Then
Connection = DataSource.GetConnection("","")
Else
InteractionHandler = createUnoService("com.sun.star.sdb.InteractionHandler")
Connection = DataSource.ConnectWithCompletion(InteractionHandler)
End If
End Sub
'***********************************************************************************
|
|
|
| Back to top |
|
 |
UboontuGuy General User

Joined: 22 May 2012 Posts: 5
|
Posted: Tue May 22, 2012 4:46 pm Post subject: |
|
|
I just install LibreOffice 3.4.6 with libmyodbc 1.5.6 and have the same issue: The interaction handler is not invoked. This works on 3.4.4 with libmyodbc 1.5.6-1.
Which version of OpenOffice/LibreOffice are you using? |
|
| Back to top |
|
 |
UboontuGuy General User

Joined: 22 May 2012 Posts: 5
|
Posted: Tue May 22, 2012 5:00 pm Post subject: |
|
|
I have found "my" issue: Check if you have your database registered in Tools>Options>OpenOffice/LibreOffice Base>Databases.  |
|
| Back to top |
|
 |
shambhagwat General User

Joined: 07 Jul 2010 Posts: 7
|
Posted: Tue May 22, 2012 7:45 pm Post subject: |
|
|
| I have installed appache 3.4 |
|
| Back to top |
|
 |
UboontuGuy General User

Joined: 22 May 2012 Posts: 5
|
Posted: Wed May 23, 2012 2:44 am Post subject: |
|
|
The issues, in my case, were two: 1) I forgot to register the database. 2) I have an ON ERROR RESUME NEXT before (without this sentence, popup an error). I suggest you check "Connection" value with a tool like MRI.  |
|
| Back to top |
|
 |
shambhagwat General User

Joined: 07 Jul 2010 Posts: 7
|
Posted: Wed May 23, 2012 4:51 am Post subject: |
|
|
1. I registered the database first.
otherwise the command
DatabaseContext.getByName("abhijattrial") won't work.
but error message will be pop up.
2. I will test the connection in watch window and then i will post again.
Thanks. |
|
| Back to top |
|
 |
UboontuGuy General User

Joined: 22 May 2012 Posts: 5
|
Posted: Wed May 23, 2012 5:40 am Post subject: |
|
|
It's true. But, when you update or a new install (as my case) LibreOffice / OpenOffice from scratch and Database exist previously, you can get the error. I suppose now this is not your case.
I tested on LibreOffice 3.4.4, LibreOffice 3.4.6 and OpenOffice 3.3.4. |
|
| Back to top |
|
 |
shambhagwat General User

Joined: 07 Jul 2010 Posts: 7
|
Posted: Wed May 23, 2012 5:44 am Post subject: |
|
|
I have inserted one more line at the end.
msgbox(IsNull(Connection))
I am talking about Sub GetConnecton.
thus last if clause is as under
| Code: |
If Not DataSource.IsPasswordRequired Then
Connection = DataSource.GetConnection("","")
Else
InteractionHandler = createUnoService("com.sun.star.sdb.InteractionHandler")
Connection = DataSource.ConnectWithCompletion(InteractionHandler)
End If
msgbox(IsNull(Connection))
|
The msgbox function returns False
It means connection has been established.
One more point is there,
I have made so many attempts but
the InteractionHandler invoked only once and asked for the password.
The user name was filled up automatically.
By whom? I don't know.
But therafter nteractionHandler never invoked.  |
|
| Back to top |
|
 |
UboontuGuy General User

Joined: 22 May 2012 Posts: 5
|
Posted: Wed May 23, 2012 6:16 am Post subject: |
|
|
Let me tell you my results:
When I applied MRI tool, when error, "Connection" returns "void". When was fix, "Connection" returns an object with data. That's the reason I suggested use MRI: You can see all Properties and Methods. Call as "MRI Connection" inmediately after line "Connection = DataSource.ConnectWithCompletion(InteractionHandler)". Remember follow with an stop (like MsgBox) to view object status.
About username automatically filled I believe It's record in ".odb" file when you specify the connection (ODBC, sqlite, MYSQL/J, MYSQL(ODBC), etc). If you need to change it, go to objetcs elements frame, press RightBotton Mouse and appears Database>Properties and change user name. |
|
| Back to top |
|
 |
|