You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Teddy78 <te...@sgcib.com> on 2009/08/24 18:37:35 UTC

Dynamic Datasource with DataAccess

Hello all,

I need to specify connectionString datasource in code, I cannot specify
password in properties.config or in dao.config ( because I obtain the
password by making a request to a service)

How I can specify it?

Here is my code : 
DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
//I would like to specify datasource before call the method Configure
builder.Configure();  // This code use dao.config : I need to specify
datasource in dao.config otherwise I get an error.
IDaoManager daoManager = DaoManager.GetInstance("SqlMapDao");
// now I can modify datasource of daoManager : but no interest for me :
DataSource datasource = daoManager.LocalDataSource as DataSource;
datasource.ConnectionString = "Server=Host\Server1;Database=db1;User
ID=userId;Password=pwd";
			
Thanks
-- 
View this message in context: http://www.nabble.com/Dynamic-Datasource-with-DataAccess-tp25119303p25119303.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-cs-help@ibatis.apache.org


Re: Dynamic Datasource with DataAccess

Posted by Teddy78 <te...@sgcib.com>.
Thank you Michael, I will do it
Teddy

Michael Schall wrote:
> 
> What are you passing to Configure?
> 
> If you can pass an XmlDocument object, instead of a file, you can just
> replace the connection string in the dom before calling configure...
> If you are currently passing the file path or file object, just read
> the file into a XmlDocument first, change the connection string then
> call configure.
> 
> Hope this helps.
> 
> Mike
> 
> On Mon, Aug 24, 2009 at 11:37 AM, Teddy78<te...@sgcib.com>
> wrote:
>>
>> Hello all,
>>
>> I need to specify connectionString datasource in code, I cannot specify
>> password in properties.config or in dao.config ( because I obtain the
>> password by making a request to a service)
>>
>> How I can specify it?
>>
>> Here is my code :
>> DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
>> //I would like to specify datasource before call the method Configure
>> builder.Configure();  // This code use dao.config : I need to specify
>> datasource in dao.config otherwise I get an error.
>> IDaoManager daoManager = DaoManager.GetInstance("SqlMapDao");
>> // now I can modify datasource of daoManager : but no interest for me :
>> DataSource datasource = daoManager.LocalDataSource as DataSource;
>> datasource.ConnectionString = "Server=Host\Server1;Database=db1;User
>> ID=userId;Password=pwd";
>>
>> Thanks
>> --
>> View this message in context:
>> http://www.nabble.com/Dynamic-Datasource-with-DataAccess-tp25119303p25119303.html
>> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
>> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-cs-help@ibatis.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Dynamic-Datasource-with-DataAccess-tp25119303p25129615.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-cs-help@ibatis.apache.org


Re: Dynamic Datasource with DataAccess

Posted by Teddy78 <te...@sgcib.com>.
Thank you for your reply, but i need to specify my datasource before the call
to configure method. I will pass an XmlDocument object as a parameter of
Configure as Mickael explain.

Teddy


Forfun Chou wrote:
> 
> I also need to connect Database dynamic. Here is my code, and it works
> fine.
>                    DomSqlMapBuilder builder = new DomSqlMapBuilder();
>                     _mapper = (SqlMapper)builder.Configure();
>                     DataSource ds = (DataSource)_mapper.DataSource;
>                     ds.ConnectionString = my_connect_string;
> Hope this helps.
> 
> 

-- 
View this message in context: http://www.nabble.com/Dynamic-Datasource-with-DataAccess-tp25119303p25129639.html
Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-cs-help@ibatis.apache.org


Re: Dynamic Datasource with DataAccess

Posted by chunfang zhou <ch...@gmail.com>.
I also need to connect Database dynamic. Here is my code, and it works fine.
                   DomSqlMapBuilder builder = new DomSqlMapBuilder();
                    _mapper = (SqlMapper)builder.Configure();
                    DataSource ds = (DataSource)_mapper.DataSource;
                    ds.ConnectionString = my_connect_string;
Hope this helps.

Re: Dynamic Datasource with DataAccess

Posted by Michael Schall <mi...@gmail.com>.
What are you passing to Configure?

If you can pass an XmlDocument object, instead of a file, you can just
replace the connection string in the dom before calling configure...
If you are currently passing the file path or file object, just read
the file into a XmlDocument first, change the connection string then
call configure.

Hope this helps.

Mike

On Mon, Aug 24, 2009 at 11:37 AM, Teddy78<te...@sgcib.com> wrote:
>
> Hello all,
>
> I need to specify connectionString datasource in code, I cannot specify
> password in properties.config or in dao.config ( because I obtain the
> password by making a request to a service)
>
> How I can specify it?
>
> Here is my code :
> DomDaoManagerBuilder builder = new DomDaoManagerBuilder();
> //I would like to specify datasource before call the method Configure
> builder.Configure();  // This code use dao.config : I need to specify
> datasource in dao.config otherwise I get an error.
> IDaoManager daoManager = DaoManager.GetInstance("SqlMapDao");
> // now I can modify datasource of daoManager : but no interest for me :
> DataSource datasource = daoManager.LocalDataSource as DataSource;
> datasource.ConnectionString = "Server=Host\Server1;Database=db1;User
> ID=userId;Password=pwd";
>
> Thanks
> --
> View this message in context: http://www.nabble.com/Dynamic-Datasource-with-DataAccess-tp25119303p25119303.html
> Sent from the iBATIS - User - Cs mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-cs-help@ibatis.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-cs-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-cs-help@ibatis.apache.org