Dynamic Datasource with DataAccess

View: New views
5 Messages — Rating Filter:   Alert me  

Dynamic Datasource with DataAccess

by Teddy78 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Dynamic Datasource with DataAccess

by Michael Schall :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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<teddy.fredaigues@...> 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@...
> For additional commands, e-mail: user-cs-help@...
>
>

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


Re: Dynamic Datasource with DataAccess

by Forfun Chou :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

by Teddy78 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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<teddy.fredaigues@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

Re: Dynamic Datasource with DataAccess

by Teddy78 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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.