﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » Business Objects and Data Access (How do I?)  » Sharing a database connection</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 15:26:34 GMT</lastBuildDate><ttl>20</ttl><item><title>Sharing a database connection</title><link>http://forum.strataframe.net/FindPost1480.aspx</link><description>From what I can see, SF keeps a collection of Data Sources which are connections to the database that are available for use.&amp;nbsp; This is great for anything that has SF as its base in the application, which should be most things.&amp;nbsp; However, if there is some other third-party control that needs a database connection, or if I&amp;nbsp;just wanted to directly access the open connection object in code how do I go about doing that?&amp;nbsp; Basically, I want to know&amp;nbsp;how I can take an open db connection that SF has, and pass it to another object without it having to open up a new connection.</description><pubDate>Fri, 09 Jun 2006 09:53:08 GMT</pubDate><dc:creator>Andria Jensen</dc:creator></item><item><title>RE: Sharing a database connection</title><link>http://forum.strataframe.net/FindPost1486.aspx</link><description>No problem :)&amp;nbsp; That's why we made the collection shared... so it would be visible from anywhere.</description><pubDate>Fri, 09 Jun 2006 09:53:08 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Sharing a database connection</title><link>http://forum.strataframe.net/FindPost1485.aspx</link><description>Awesome, I didn't realize that but it makes total sense know that I know.&amp;nbsp; I guess I was just missing that part completely.&amp;nbsp; Thanks for the help!</description><pubDate>Fri, 09 Jun 2006 09:52:02 GMT</pubDate><dc:creator>Andria Jensen</dc:creator></item><item><title>RE: Sharing a database connection</title><link>http://forum.strataframe.net/FindPost1484.aspx</link><description>If the other DLL is created by you, then simply add references to MicroFour StrataFrame Base and MicroFour StrataFrame Business assemblies.&amp;nbsp; Then the DLL will be able to see the DataLayer.DataSources collection (it's a shared (static) collection, like a global variable).</description><pubDate>Fri, 09 Jun 2006 09:38:07 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Sharing a database connection</title><link>http://forum.strataframe.net/FindPost1483.aspx</link><description>Ok, I understand so far.&amp;nbsp; Consider that I have a parent MDI form, that basically just calls a bunch of other dll's like a lot of applications.&amp;nbsp; If I have&amp;nbsp;a connection in the DataSources collection&amp;nbsp;on my parent MDI, how do I pass it to the dll so that it knows about the databases available in that collection?&amp;nbsp; I know I can just pass a connection string and reset things, but I thought maybe there was an easier way?</description><pubDate>Fri, 09 Jun 2006 09:36:13 GMT</pubDate><dc:creator>Andria Jensen</dc:creator></item><item><title>RE: Sharing a database connection</title><link>http://forum.strataframe.net/FindPost1482.aspx</link><description>There is also a method on the DbDataSourceItem object that creates new connections that can be used with the data source.&lt;P&gt;Dim loConnection As SqlConnection = DataLayer.DataSources("").CreateBlankDbConnection()&lt;/P&gt;&lt;P&gt;loConnection.Open()&lt;/P&gt;&lt;P&gt;'-- Do work&lt;/P&gt;&lt;P&gt;loConnection.Close()&lt;P&gt;You can also access a DbDataSourceItem from the DataSources collection by either key or by index.&amp;nbsp; Generally, you will want to use the key (string value) to retrieve the data source, as you never know what order the data sources are in.&amp;nbsp; If you only have one data source (generally you will), then you can access it fine by either DataSources("") or DataSources(0).</description><pubDate>Fri, 09 Jun 2006 09:31:08 GMT</pubDate><dc:creator>StrataFrame Team</dc:creator></item><item><title>RE: Sharing a database connection</title><link>http://forum.strataframe.net/FindPost1481.aspx</link><description>Well, first let me explain that SF does not keep connections open for a longer period than required.&amp;nbsp; This produces system overhead and will slow down an application dramatically.&amp;nbsp; If you want to access the connection strings that are used by SF, you can reference the DataSources collection and create your own connection.&amp;nbsp; You can also create a DAL and have it open the connection for you, but this really is not recommended.&lt;P&gt;&lt;FONT size=2&gt;To manually create a connection you can do the following:&lt;/FONT&gt;&lt;/P&gt;&lt;FONT size=2&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;Dim&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; loConnect &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;New&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt; System.Data.SqlClient.SqlConnection()&lt;BR&gt;&lt;/FONT&gt;&lt;BR&gt;&lt;FONT color=#111111&gt;loConnect.ConnectionString = MicroFour.StrataFrame.Data.DataBasics.DataSources(0).ConnectionString&lt;BR&gt;loConnect.Open()&lt;BR&gt;loConnect.Close()&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;You really should allow the business object to do all of the work for you, even when using a 3rd party control.&amp;nbsp; Most any 3rd party control will have support for ADO.NET.&amp;nbsp; In this case, populate your BO and the use the CurrentDataTable, CurrentView, or CurrentRow property of the BO with the control.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;If I have not answered your questions please let me know. :)&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Fri, 09 Jun 2006 09:27:03 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item></channel></rss>