OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Password Protection to Base

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base
View previous topic :: View next topic  
Author Message
shambhagwat
General User
General User


Joined: 07 Jul 2010
Posts: 7

PostPosted: Tue May 22, 2012 6:03 am    Post subject: Password Protection to Base Reply with quote

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
View user's profile Send private message
UboontuGuy
General User
General User


Joined: 22 May 2012
Posts: 5

PostPosted: Tue May 22, 2012 4:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
UboontuGuy
General User
General User


Joined: 22 May 2012
Posts: 5

PostPosted: Tue May 22, 2012 5:00 pm    Post subject: Reply with quote

I have found "my" issue: Check if you have your database registered in Tools>Options>OpenOffice/LibreOffice Base>Databases. Smile
Back to top
View user's profile Send private message
shambhagwat
General User
General User


Joined: 07 Jul 2010
Posts: 7

PostPosted: Tue May 22, 2012 7:45 pm    Post subject: Reply with quote

I have installed appache 3.4
Back to top
View user's profile Send private message
UboontuGuy
General User
General User


Joined: 22 May 2012
Posts: 5

PostPosted: Wed May 23, 2012 2:44 am    Post subject: Reply with quote

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. Smile
Back to top
View user's profile Send private message
shambhagwat
General User
General User


Joined: 07 Jul 2010
Posts: 7

PostPosted: Wed May 23, 2012 4:51 am    Post subject: Reply with quote

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
View user's profile Send private message
UboontuGuy
General User
General User


Joined: 22 May 2012
Posts: 5

PostPosted: Wed May 23, 2012 5:40 am    Post subject: Reply with quote

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
View user's profile Send private message
shambhagwat
General User
General User


Joined: 07 Jul 2010
Posts: 7

PostPosted: Wed May 23, 2012 5:44 am    Post subject: Reply with quote

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 Very Happy and asked for the password.
The user name was filled up automatically.
By whom? I don't know. Confused Rolling Eyes

But therafter nteractionHandler never invoked. Question Mad
Back to top
View user's profile Send private message
UboontuGuy
General User
General User


Joined: 22 May 2012
Posts: 5

PostPosted: Wed May 23, 2012 6:16 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Base All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group