| | | 
StrataFrame 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. |
| | | | 
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.  |
| | | | 
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 |
| | | | 
StrataFrame 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? |
| | | | 
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 |
| | | | 
StrataFrame 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! |
| | | | 
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 |
| |
|
|