How to pass password when opening DatasourceBrowser

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to pass password when opening DatasourceBrowser

Fernand Vanrie
  For opening a DataSourceBrowser I use following code

      Dim aProps(6) as New com.sun.star.beans.PropertyValue
      aProps(0).Name = "DataSourceName"
      aProps(0).Value = "mysql_native"
      aProps(1).Name = "CommandType"
      aProps(1).Value = 2 ' 0 = tabel , 1 = query , 2 = SQL statement
      aProps(2).Name = "Command"
      aProps(2).Value = "SQL statement"
     aProps(3).Name = "ShowTreeView"
      aProps(3).Value = false
      aProps(4).Name = "ShowTreeViewButton"
      aProps(4).Value = false
      aProps(5).Name = "ShowMenu"
      aProps(5).Value = true
      aProps(6).Name = "EscapeProcessing"
      aProps(6).Value = false
      oDataSourcebrowser =
frame1.loadComponentFromURL(".component:DB/DataSourceBrowser",
"_beamer", 0, aProps)

   That works fine excepted that  the user is asked for a "Username" and
"Password" when  the  datasource is opened !

How can i avoid this behaviour by passing the "username and "password"
within my code ?
I tryed to use a "ActiveConnection" where the Username and password are
passed... no luck
Neither "UserName" or "Password" are accepted as arguments ....

Only when de datasource is open (even hidden) on the desktop the
"UserName" and "Password are no longer asked.

thanks for any hint

Fernand
Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Frank Schönheit
Hi Fernand,

>   For opening a DataSourceBrowser I use following code
>
>       Dim aProps(6) as New com.sun.star.beans.PropertyValue
>       aProps(0).Name = "DataSourceName"
>       aProps(0).Value = "mysql_native"
>       aProps(1).Name = "CommandType"
>       aProps(1).Value = 2 ' 0 = tabel , 1 = query , 2 = SQL statement

(I always recomment using com.sun.star.sdb.CommandType.* here, for
better readability of your code)

>       aProps(2).Name = "Command"
>       aProps(2).Value = "SQL statement"
>      aProps(3).Name = "ShowTreeView"
>       aProps(3).Value = false
>       aProps(4).Name = "ShowTreeViewButton"
>       aProps(4).Value = false

(note that ShowTreeView/Button are superseded (though still supported)
by Enable/ShowBrowser -
http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/DataSourceBrowser.html#XInitialization)

>       aProps(5).Name = "ShowMenu"
>       aProps(5).Value = true
>       aProps(6).Name = "EscapeProcessing"
>       aProps(6).Value = false
>       oDataSourcebrowser =
> frame1.loadComponentFromURL(".component:DB/DataSourceBrowser",
> "_beamer", 0, aProps)
>
>    That works fine excepted that  the user is asked for a "Username" and
> "Password" when  the  datasource is opened !
>
> How can i avoid this behaviour by passing the "username and "password"
> within my code ?
> I tryed to use a "ActiveConnection" where the Username and password are
> passed... no luck

Hmm - I copied your code snipped, and added an "ActiveConnection"
parameter to aProps, containing an already established connection - this
worked like charm, as expected.

Sure you passed the right object, did not dispose it meanwhile, and the
like?

> Neither "UserName" or "Password" are accepted as arguments ....

No, those are indeed not supported.

> thanks for any hint

The ActiveConnection is the way to go, and it usually works - not sure
what you do differently, sorry.

Ciao
Frank

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Fernand Vanrie
  Hey Frank ,

Thanks for the respons:

Wath i already tryed en yet again tryed

      oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
      oConn =
oDB.GetByName("mysql_native").GetConnection("username","password")

      Dim aProps(7) as New com.sun.star.beans.PropertyValue
      aProps(0).Name = "ActiveConnection"
      aProps(0).Value = oconn

but the browser stays empty ! ( i tryed with  table and sql Statement)

maybe you did wath i already found out:

- worked from a opened Basedoc ?
- you tryed first the code with datasourceName and made the connection
manualy and then changed he code to activeconnection ?

i trye to connect to a MySQL datasource using the Native Connector

Greetz

Fernand


> Hi Fernand,
>
>>    For opening a DataSourceBrowser I use following code
>>
>>        Dim aProps(6) as New com.sun.star.beans.PropertyValue
>>        aProps(0).Name = "DataSourceName"
>>        aProps(0).Value = "mysql_native"
>>        aProps(1).Name = "CommandType"
>>        aProps(1).Value = 2 ' 0 = tabel , 1 = query , 2 = SQL statement
> (I always recomment using com.sun.star.sdb.CommandType.* here, for
> better readability of your code)
>
>>        aProps(2).Name = "Command"
>>        aProps(2).Value = "SQL statement"
>>       aProps(3).Name = "ShowTreeView"
>>        aProps(3).Value = false
>>        aProps(4).Name = "ShowTreeViewButton"
>>        aProps(4).Value = false
> (note that ShowTreeView/Button are superseded (though still supported)
> by Enable/ShowBrowser -
> http://api.openoffice.org/docs/common/ref/com/sun/star/sdb/DataSourceBrowser.html#XInitialization)
>
>>        aProps(5).Name = "ShowMenu"
>>        aProps(5).Value = true
>>        aProps(6).Name = "EscapeProcessing"
>>        aProps(6).Value = false
>>        oDataSourcebrowser =
>> frame1.loadComponentFromURL(".component:DB/DataSourceBrowser",
>> "_beamer", 0, aProps)
>>
>>     That works fine excepted that  the user is asked for a "Username" and
>> "Password" when  the  datasource is opened !
>>
>> How can i avoid this behaviour by passing the "username and "password"
>> within my code ?
>> I tryed to use a "ActiveConnection" where the Username and password are
>> passed... no luck
> Hmm - I copied your code snipped, and added an "ActiveConnection"
> parameter to aProps, containing an already established connection - this
> worked like charm, as expected.
>
> Sure you passed the right object, did not dispose it meanwhile, and the
> like?
>
>> Neither "UserName" or "Password" are accepted as arguments ....
> No, those are indeed not supported.
>
>> thanks for any hint
> The ActiveConnection is the way to go, and it usually works - not sure
> what you do differently, sorry.
>
> Ciao
> Frank
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Frank Schönheit
Hi Fernand,

> Wath i already tryed en yet again tryed
>
>       oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
>       oConn =
> oDB.GetByName("mysql_native").GetConnection("username","password")
>
>       Dim aProps(7) as New com.sun.star.beans.PropertyValue
>       aProps(0).Name = "ActiveConnection"
>       aProps(0).Value = oconn
>
> but the browser stays empty ! ( i tryed with  table and sql Statement)

"stays empty"? If you pass an ActiveConnection to the DSB, then it stays
empty, if you don't pass it, then it asks for user/password, and
properly displays your table? Did I get this right?

> maybe you did wath i already found out:
>
> - worked from a opened Basedoc ?

no Base doc open at all, I did this from within a Writer doc.

> - you tryed first the code with datasourceName and made the connection
> manualy and then changed he code to activeconnection ?

Used the same code as you wrote above.

> i trye to connect to a MySQL datasource using the Native Connector

/me too.

Ciao
Frank

--
ORACLE
Frank Schönheit | Software Engineer | [hidden email]
Oracle Office Productivity: http://www.oracle.com/office

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Fernand Vanrie
   Frank ,

Are you sure you didn' tryed with user/password before you tryed the
activeconnection, because OO remembers the connection made by
user/password ?

"stays empty"? If you pass an ActiveConnection to the DSB, then it stays
empty, if you don't pass it, then it asks for user/password, and
properly displays your table? Did I get this right?"

yes thats wath happens, with table or SQL statement i do not tryed a query

Irun on windows , OOO320m17 (3.2.1), Connector 1.0.0

tryed connection Pooling ON and OFF, no difference

The code who works but is asking for User and pasdword:


      Dim aProps(7) as New com.sun.star.beans.PropertyValue
      aProps(0).Name = "DataSourceName"
      aProps(0).Value = "mysql_native" ' deze "naam" moet dus GEREGISTREERD ZIJN als Database in OO
      aProps(1).Name = "CommandType"
      aProps(1).Value = 0
      aProps(2).Name = "Command"
      aprops(2).value = "pmgdbase.mag_news_export"

The code who do not works :

      oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
       oConn =
oDB.GetByName("mysql_native").GetConnection("user","password")
   '      xray oconn
      Dim aProps(7) as New com.sun.star.beans.PropertyValue
      aProps(0).Name = "ActiveConnection"
      aProps(0).Value = oconn
      aProps(1).Name = "CommandType"
      aProps(1).Value = 0 ' 0 = tabel , 1 = query , 2 = SQL statement
      aProps(2).Name = "Command"
      aprops(2).value = "pmgdbase.mag_news_export

Is there something wrong with the way is pass te oConn object ?? (when
xraying everithings seems to be ok)

Greetz

Fernand

>> Wath i already tryed en yet again tryed
>>
>>        oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
>>        oConn =
>> oDB.GetByName("mysql_native").GetConnection("username","password")
>>
>>        Dim aProps(7) as New com.sun.star.beans.PropertyValue
>>        aProps(0).Name = "ActiveConnection"
>>        aProps(0).Value = oconn
>>
>> but the browser stays empty ! ( i tryed with  table and sql Statement)
> "stays empty"? If you pass an ActiveConnection to the DSB, then it stays
> empty, if you don't pass it, then it asks for user/password, and
> properly displays your table? Did I get this right?
>
>> maybe you did wath i already found out:
>>
>> - worked from a opened Basedoc ?
> no Base doc open at all, I did this from within a Writer doc.
>
>> - you tryed first the code with datasourceName and made the connection
>> manualy and then changed he code to activeconnection ?
> Used the same code as you wrote above.
>
>> i trye to connect to a MySQL datasource using the Native Connector
> /me too.
>
> Ciao
> Frank
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Fernand Vanrie
  Frank,

Found a work around:

I now passes the "password" to the com.sun.star.comp.dba.ODatabaseSource
password property

   oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
   oDB.GetByName("mysql_native").password = "mypassword"

and the databrowser opens  silently with the data init.



but please (if you find two seconds) check if i did something wrong when
using the activeconnection

Thanks

Fernand

>   Frank ,
>
> Are you sure you didn' tryed with user/password before you tryed the
> activeconnection, because OO remembers the connection made by
> user/password ?
>
> "stays empty"? If you pass an ActiveConnection to the DSB, then it stays
> empty, if you don't pass it, then it asks for user/password, and
> properly displays your table? Did I get this right?"
>
> yes thats wath happens, with table or SQL statement i do not tryed a
> query
>
> Irun on windows , OOO320m17 (3.2.1), Connector 1.0.0
>
> tryed connection Pooling ON and OFF, no difference
>
> The code who works but is asking for User and pasdword:
>
>
>      Dim aProps(7) as New com.sun.star.beans.PropertyValue
>      aProps(0).Name = "DataSourceName"
>      aProps(0).Value = "mysql_native" ' deze "naam" moet dus
> GEREGISTREERD ZIJN als Database in OO
>      aProps(1).Name = "CommandType"
>      aProps(1).Value = 0
>      aProps(2).Name = "Command"
>      aprops(2).value = "pmgdbase.mag_news_export"
>
> The code who do not works :
>
>      oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
>       oConn =
> oDB.GetByName("mysql_native").GetConnection("user","password")
>   '      xray oconn
>      Dim aProps(7) as New com.sun.star.beans.PropertyValue
>      aProps(0).Name = "ActiveConnection"
>      aProps(0).Value = oconn
>      aProps(1).Name = "CommandType"
>      aProps(1).Value = 0 ' 0 = tabel , 1 = query , 2 = SQL statement
>      aProps(2).Name = "Command"
>      aprops(2).value = "pmgdbase.mag_news_export
>
> Is there something wrong with the way is pass te oConn object ?? (when
> xraying everithings seems to be ok)
>
> Greetz
>
> Fernand
>
>>> Wath i already tryed en yet again tryed
>>>
>>>        oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
>>>        oConn =
>>> oDB.GetByName("mysql_native").GetConnection("username","password")
>>>
>>>        Dim aProps(7) as New com.sun.star.beans.PropertyValue
>>>        aProps(0).Name = "ActiveConnection"
>>>        aProps(0).Value = oconn
>>>
>>> but the browser stays empty ! ( i tryed with  table and sql Statement)
>> "stays empty"? If you pass an ActiveConnection to the DSB, then it stays
>> empty, if you don't pass it, then it asks for user/password, and
>> properly displays your table? Did I get this right?
>>
>>> maybe you did wath i already found out:
>>>
>>> - worked from a opened Basedoc ?
>> no Base doc open at all, I did this from within a Writer doc.
>>
>>> - you tryed first the code with datasourceName and made the connection
>>> manualy and then changed he code to activeconnection ?
>> Used the same code as you wrote above.
>>
>>> i trye to connect to a MySQL datasource using the Native Connector
>> /me too.
>>
>> Ciao
>> Frank
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Frank Schönheit
In reply to this post by Fernand Vanrie
Hi Fernand,

> Are you sure you didn' tryed with user/password before you tryed the
> activeconnection, because OO remembers the connection made by
> user/password ?

Yes.

> The code who works but is asking for User and pasdword:
>
>
>       Dim aProps(7) as New com.sun.star.beans.PropertyValue
>       aProps(0).Name = "DataSourceName"
>       aProps(0).Value = "mysql_native" ' deze "naam" moet dus GEREGISTREERD ZIJN als Database in OO
>       aProps(1).Name = "CommandType"
>       aProps(1).Value = 0
>       aProps(2).Name = "Command"
>       aprops(2).value = "pmgdbase.mag_news_export"
>
> The code who do not works :
>
>       oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
>        oConn =
> oDB.GetByName("mysql_native").GetConnection("user","password")
>    '      xray oconn
>       Dim aProps(7) as New com.sun.star.beans.PropertyValue
>       aProps(0).Name = "ActiveConnection"
>       aProps(0).Value = oconn
>       aProps(1).Name = "CommandType"
>       aProps(1).Value = 0 ' 0 = tabel , 1 = query , 2 = SQL statement
>       aProps(2).Name = "Command"
>       aprops(2).value = "pmgdbase.mag_news_export

One difference I see here is that you do *not* pass the DataSourceName
in the second case (my macro here does). This might make the difference
- can you try passing it, additional to the ActiveConnection?

Is your oconn object, by any chance, invalid?

Ciao
Frank
--
ORACLE
Frank Schönheit | Software Engineer | [hidden email]
Oracle Office Productivity: http://www.oracle.com/office

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Fernand Vanrie
  On 1/10/2010 14:51, Frank Schönheit wrote:

> Hi Fernand,
>
>> Are you sure you didn' tryed with user/password before you tryed the
>> activeconnection, because OO remembers the connection made by
>> user/password ?
> Yes.
>
>> The code who works but is asking for User and pasdword:
>>
>>
>>        Dim aProps(7) as New com.sun.star.beans.PropertyValue
>>        aProps(0).Name = "DataSourceName"
>>        aProps(0).Value = "mysql_native" ' deze "naam" moet dus GEREGISTREERD ZIJN als Database in OO
>>        aProps(1).Name = "CommandType"
>>        aProps(1).Value = 0
>>        aProps(2).Name = "Command"
>>        aprops(2).value = "pmgdbase.mag_news_export"
>>
>> The code who do not works :
>>
>>        oDB = CreateUnoService("com.sun.star.sdb.DatabaseContext")
>>         oConn =
>> oDB.GetByName("mysql_native").GetConnection("user","password")
>>     '      xray oconn
>>        Dim aProps(7) as New com.sun.star.beans.PropertyValue
>>        aProps(0).Name = "ActiveConnection"
>>        aProps(0).Value = oconn
>>        aProps(1).Name = "CommandType"
>>        aProps(1).Value = 0 ' 0 = tabel , 1 = query , 2 = SQL statement
>>        aProps(2).Name = "Command"
>>        aprops(2).value = "pmgdbase.mag_news_export
> One difference I see here is that you do *not* pass the DataSourceName
> in the second case (my macro here does). This might make the difference
NO i tryed that also :-)
> - can you try passing it, additional to the ActiveConnection?
>
> Is your oconn object, by any chance, invalid?
I can Xray it and it shows all details according to the wanted
connection, so ??

only passing the password to the com.sun.star.comp.dba.ODatabaseSource
password property works for me

Greetz

Fernand
> Ciao
> Frank


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Frank Schönheit
Hi Fernand,

>> Is your oconn object, by any chance, invalid?
> I can Xray it and it shows all details according to the wanted
> connection, so ??
>
> only passing the password to the com.sun.star.comp.dba.ODatabaseSource
> password property works for me

I'm clueless than :(

Ciao
Frank

--
ORACLE
Frank Schönheit | Software Engineer | [hidden email]
Oracle Office Productivity: http://www.oracle.com/office

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Fernand Vanrie
  Frank,

You clueless, thats new for me :-)

I am still convinced thats your machine knows the Username and
passwords, or  your sytem is never asking for it :-) ? But wathever i
kan keep my users away from the tables, and thats wath count.

Thanks again for the interest in my problems.

Fernand




>>> Is your oconn object, by any chance, invalid?
>> I can Xray it and it shows all details according to the wanted
>> connection, so ??
>>
>> only passing the password to the com.sun.star.comp.dba.ODatabaseSource
>> password property works for me
> I'm clueless than :(
>
> Ciao
> Frank
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to pass password when opening DatasourceBrowser

Frank Schönheit
Hi Fernand,

> You clueless, thats new for me :-)

Damn, that slipped my attention, normally I do not admit that :)

> I am still convinced thats your machine knows the Username and
> passwords, or  your sytem is never asking for it :-) ?

If I replace the "getConnection" call to create the connection with
"connectWithCompletion", then it actually asks for the user/password -
so: no, that's not the difference :)

Ciao
Frank



--
ORACLE
Frank Schönheit | Software Engineer | [hidden email]
Oracle Office Productivity: http://www.oracle.com/office

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]