Dynamically connect to different databases


Author
Message
Michel Levy
Michel Levy
Advanced StrataFrame User (607 reputation)Advanced StrataFrame User (607 reputation)Advanced StrataFrame User (607 reputation)Advanced StrataFrame User (607 reputation)Advanced StrataFrame User (607 reputation)Advanced StrataFrame User (607 reputation)Advanced StrataFrame User (607 reputation)Advanced StrataFrame User (607 reputation)Advanced StrataFrame User (607 reputation)
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?

Reply
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
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.



GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search