By Peter Jones - 7/27/2009
Hi,
Just a thought....
I recently had a need to populate just a single BO on a form from a different database to the other BO's on the form. The actual database to use isn't known until runtime.
All our db access is via stored procedures in SQL Commands so, given that I had ready access to connection string I needed to use, I simply created SQL Connection, opened it and then set the SQL Commands .connection property. In tracking down why this didn't work I can see Business Layer creates a connection 'on-the-fly' and ignores what may already be there in the SQL Command object.
I was wondering if it may be useful to check if a SQL Command object already has a connection object defined and use it rather than creating a 'standard connection'. The assumption here being that if a system has gone to the trouble of creating a connection and placing it in the SQL Command object then that's the connection that should be used.
BTW - this is 'just a thought' - I have no need for this functionality as I have achieved the required results by other means.
Cheers, Peter
|
By Trent L. Taylor - 7/29/2009
You can already do this one of several different ways. First, you can create another data source key (which I don't think is what you need to do here) or you can just tell the BO to re-create the data layer, which will resolve this problem. So if you change the connection string to an already existing data source and a BO instance already exists, then just call the RecreateDataLayer method on the BO.
If this doesn't give you what you want, just dynamically create a new DataSource with a unique key, add it to the DataBasics.DataSources collection, set the DataSourceKey on the BO, and then you are good. Remove it when done if necessary.
|
By Peter Jones - 7/29/2009
so much to know, so little time...
Thanks, Peter
|
By Trent L. Taylor - 7/30/2009
LOL, I understand!
|
|