StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Sharing a database connectionExpand / Collapse
Author
Message
Posted 06/09/2006 9:13:27 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 3:40:41 PM
Posts: 328, Visits: 479
From what I can see, SF keeps a collection of Data Sources which are connections to the database that are available for use.  This is great for anything that has SF as its base in the application, which should be most things.  However, if there is some other third-party control that needs a database connection, or if I just wanted to directly access the open connection object in code how do I go about doing that?  Basically, I want to know 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.
Post #1480
Posted 06/09/2006 9:27:03 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 2:14:29 PM
Posts: 4,901, Visits: 4,886
Well, first let me explain that SF does not keep connections open for a longer period than required.  This produces system overhead and will slow down an application dramatically.  If you want to access the connection strings that are used by SF, you can reference the DataSources collection and create your own connection.  You can also create a DAL and have it open the connection for you, but this really is not recommended.

To manually create a connection you can do the following:

Dim loConnect As New System.Data.SqlClient.SqlConnection()

loConnect.ConnectionString = MicroFour.StrataFrame.Data.DataBasics.DataSources(0).ConnectionString
loConnect.Open()
loConnect.Close()

You really should allow the business object to do all of the work for you, even when using a 3rd party control.  Most any 3rd party control will have support for ADO.NET.  In this case, populate your BO and the use the CurrentDataTable, CurrentView, or CurrentRow property of the BO with the control.

If I have not answered your questions please let me know.

Post #1481
Posted 06/09/2006 9:31:08 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 12/09/2008 3:36:08 PM
Posts: 2,686, Visits: 1,891
There is also a method on the DbDataSourceItem object that creates new connections that can be used with the data source.

Dim loConnection As SqlConnection = DataLayer.DataSources("").CreateBlankDbConnection()

loConnection.Open()

'-- Do work

loConnection.Close()

You can also access a DbDataSourceItem from the DataSources collection by either key or by index.  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.  If you only have one data source (generally you will), then you can access it fine by either DataSources("") or DataSources(0).


www.bungie.net
Post #1482
Posted 06/09/2006 9:36:13 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 3:40:41 PM
Posts: 328, Visits: 479
Ok, I understand so far.  Consider that I have a parent MDI form, that basically just calls a bunch of other dll's like a lot of applications.  If I have a connection in the DataSources collection on my parent MDI, how do I pass it to the dll so that it knows about the databases available in that collection?  I know I can just pass a connection string and reset things, but I thought maybe there was an easier way?
Post #1483
Posted 06/09/2006 9:38:07 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 12/09/2008 3:36:08 PM
Posts: 2,686, Visits: 1,891
If the other DLL is created by you, then simply add references to MicroFour StrataFrame Base and MicroFour StrataFrame Business assemblies.  Then the DLL will be able to see the DataLayer.DataSources collection (it's a shared (static) collection, like a global variable).


www.bungie.net
Post #1484
Posted 06/09/2006 9:52:02 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: Today @ 3:40:41 PM
Posts: 328, Visits: 479
Awesome, I didn't realize that but it makes total sense know that I know.  I guess I was just missing that part completely.  Thanks for the help!
Post #1485
Posted 06/09/2006 9:53:08 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 12/09/2008 3:36:08 PM
Posts: 2,686, Visits: 1,891
No problem   That's why we made the collection shared... so it would be visible from anywhere.


www.bungie.net
Post #1486
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 5:55pm

Powered by InstantForum.NET v4.1.4 © 2009
Execution: 0.094. 14 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.