Retain the existing db connection in a command object


Author
Message
Peter Jones
Peter Jones
StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K
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

Trent Taylor
Trent Taylor
StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
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.
Peter Jones
Peter Jones
StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)StrataFrame User (450 reputation)
Group: Forum Members
Posts: 386, Visits: 2.1K


so much to know, so little time...



Thanks, Peter
Trent Taylor
Trent Taylor
StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)StrataFrame Developer (8.5K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
LOL, I understand! BigGrin
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search