| | | StrataFrame Novice
       
Group: StrataFrame Users Last Login: Today @ 12:13:03 PM Posts: 54, Visits: 931 |
| | Hi, I'm a french absolute beginner in both StrataFrame and VB.Net (but 23 years with Clipper and Fox)... Data are on several databases on SQL Server (DataBcuv1, DataBcuv2, ...) and global parameters are in ParaBcuv on the same Server. The most important of these is the correspondence between "folder" ID and database name (first folder may be linked to databcuv4, if my customer requires it). In my main form, I launch (in its shown method) a form "choixdossier" as showdialog(), to chooses working folder (i.e. database), and I return a connect string in a property of my main form. I use one BO for this first connection to parabcuv, and I need to dynamically re-set the connection strings of all BO to databcuv which are used in all forms in that application (all BO are in a BO library referenced in final application). But method SetDataSources is in appmain.vb, not in my main form :-( How can I do that? |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 10:01:58 PM Posts: 1,268, Visits: 3,234 |
| | You can manually drop the data source and re-add it with a different connection string any time you need to change it. Just be sure to use the same name (the default is an empty string). |
| | | | StrataFrame Novice
       
Group: StrataFrame Users Last Login: Today @ 12:13:03 PM Posts: 54, Visits: 931 |
| | Thanks for your reply, Greg, but... I don't want to reset datasource in design mode, but let the user reset it using the form "choixdossier". form choixdossier sends "numdossier" to form ecran, and in form ecran, I have Public Property numDossier() As IntegerGet Return _numDossier End GetSet(ByVal value As Integer) ' remplissage du BO parabcuv Me.ParaBcuv1.getdossiers_bydossier() Me.ParaBcuv1.Refresh() _numDossier = value _strtoSeek = "dossier = " & value.ToString If Me.ParaBcuv1.Seek(_strtoSeek) ThenMe.ParaBcuv1.numdossier = value Me.ParaBcuv1.Refresh() Me.nomDossier = Me.ParaBcuv1.societe.TrimDim loDataCnx As New Data.SqlClient.SqlConnectionStringBuilder(MicroFour.StrataFrame.Data.DataBasics.DataSources(0).ConnectionString)loDataCnx.InitialCatalog = Me.ParaBcuv1.databcuveMicroFour.StrataFrame.Data.DataBasics.DataSources(0).ConnectionString = loDataCnx.ToString Me.connectStringdata = loDataCnx.ToStringEnd IfEnd SetEnd Property-- How can I use that connectstringdata in BO at runtime? |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 10:01:58 PM Posts: 1,268, Visits: 3,234 |
| Just to make sure you understand what I'm taking about, I'm saying that the BO is configured to use a specific datasource, accesses via a key. The default key is an empty string. What I'm saying is that if you drop the actual datasource and re-add it with a new connection string, the BO never needs to be changed. This can be done at runtime easily by just dropping the current data source and adding the new one:
' Drop existing
DataLayer.DataSources.Remove("")
' Add a new one with the new connection string
DataLayer.DataSources.Add(New SqlDataSourceItem("","Data Source=myServer;Initial Catalog=....")
Now any BO that uses the default datasource (key = "") will get/pull data from a new data source, no changes to BO needed and done at runtime.
|
| | | | StrataFrame Novice
       
Group: StrataFrame Users Last Login: Today @ 12:13:03 PM Posts: 54, Visits: 931 |
| | OK Greg, now I understand what you were talking about (all my apologies for misunderstanding, but english is not my native language), and it seems to be exactly what I was looking for. I'll try it tomorrow (it's 9 PM here, time to stop working ) and give a feedback. Thanks |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 10:01:58 PM Posts: 1,268, Visits: 3,234 |
| nowI understand what you were talking about (all my apologies for misunderstanding, but english is not my native language), and it seems to be exactly what I was looking for.
No worries. I had all sorts of misunderstandings like this when I started. I think you're doing great!
I'll try it tomorrow (it's 9 PM here, time to stop working  ) and give a feedback.
Bon Chance et Bon Nuit!
(and that's about it for my français) |
| | | | 
StrataFrame Developer

Group: StrataFrame Developers Last Login: 09/26/2008 8:30:36 AM Posts: 2,685, Visits: 1,886 |
| Yep, Greg is absolutely right (once again ). If you change the ConnectionString property on a DataSource, you're not guaranteed that it's going to be updated throughout the application (it gets cached off for speed so it doesn't need to be looked up every time). So, instead, remove the DataSource and re-add it to the DataSources collection, just like in Greg's sample, and all of the business objects will update and start using the new data source.
www.bungie.net |
| | | | StrataFrame Novice
       
Group: StrataFrame Users Last Login: Today @ 12:13:03 PM Posts: 54, Visits: 931 |
| | Greg and Ben, Thanks a lot ! you've driven me exactly on the road I needed, so now I can move forward by myself. Thanks again |
| | | | |
|