Michel Levy
|
|
Group: StrataFrame Users
Posts: 193,
Visits: 9K
|
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?
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
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).
|
|
|
Michel Levy
|
|
Group: StrataFrame Users
Posts: 193,
Visits: 9K
|
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?
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
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.
|
|
|
Michel Levy
|
|
Group: StrataFrame Users
Posts: 193,
Visits: 9K
|
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
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
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 Team
|
|
Group: StrataFrame Developers
Posts: 3K,
Visits: 2.5K
|
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.
|
|
|
Michel Levy
|
|
Group: StrataFrame Users
Posts: 193,
Visits: 9K
|
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
|
|
|
Greg McGuffey
|
|
Group: Forum Members
Posts: 2K,
Visits: 6.6K
|
|
|
|
Michel Levy
|
|
Group: StrataFrame Users
Posts: 193,
Visits: 9K
|
Hi, no, not so excellent There's something I don't understand: Database is a read-only property, and in BO Mapper (when i build my BO and then generate my dll which is referenced in my app), Database is "hard coded" as I can read in datacuves.designer. ''' <summary>''' The name of the database that contains the table to which this business object is mapped.''' </summary>''' <remarks></remarks>Public Overrides ReadOnly Property Database() As StringGetReturn "databcuv1"End GetEnd Property and even if I fill initial catalog with "databcuv2" in the connectionstring of the new sqldatasourceitem (as you said), database is still the old one, not the new. Sure I've missed something, but what?? and where??
|
|
|