Re: How to pass password when opening DatasourceBrowser

Fernand Vanrie <[email protected]> Fri, 01 Oct 2010 09:44:50 +0200
Newsgroups gmane.comp.openoffice.dba.devel
Message-ID <[email protected]>
  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: [email protected]
> For additional commands, e-mail: [email protected]