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


12»»

Dynamically connect to different databasesExpand / Collapse
Author
Message
Posted 07/02/2007 10:16:19 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame 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?

Post #9902
Posted 07/02/2007 10:21:52 AM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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).
Post #9905
Posted 07/02/2007 11:47:23 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame 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 Integer

Get
Return _numDossier
End Get

Set(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) Then

Me.ParaBcuv1.numdossier = value
Me.ParaBcuv1.Refresh()
Me.nomDossier = Me.ParaBcuv1.societe.Trim

Dim loDataCnx As New Data.SqlClient.SqlConnectionStringBuilder(MicroFour.StrataFrame.Data.DataBasics.DataSources(0).ConnectionString)

loDataCnx.InitialCatalog = Me.ParaBcuv1.databcuve

MicroFour.StrataFrame.Data.DataBasics.DataSources(0).ConnectionString = loDataCnx.ToString

Me.connectStringdata = loDataCnx.ToString

End If

End Set

End Property

--

How can I use that connectstringdata in BO at runtime?

Post #9909
Posted 07/02/2007 12:43:45 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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.

Post #9910
Posted 07/02/2007 1:47:26 PM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame 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

Post #9912
Posted 07/02/2007 6:13:14 PM
StrataFrame VIP

StrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame VIPStrataFrame 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)
Post #9918
Posted 07/03/2007 9:06:10 AM


StrataFrame Developer

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
Post #9927
Posted 07/03/2007 10:39:04 AM
StrataFrame Novice

StrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame NoviceStrataFrame 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

Post #9935
Posted 07/03/2007 1:33:55 PM