Dynamically connect to different databases


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Sure I've missed something, but what?? and where??

This property is no longer used and was left in for backward compatability.  The data source is the ONLY thing that determines from where the data will be pulled at run-time.  Ths database property is generated using the name of the database from which you pulled the schema....but it ends there and is not actually used at run-time (or any other time for that matter) Smile

Michel Levy
Michel Levy
StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)
Group: StrataFrame Users
Posts: 193, Visits: 9K
Hi,

no, not so excellent Crying

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 String

Get

Return "databcuv1"

End Get

End 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??

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Excellent!
Michel Levy
Michel Levy
StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)
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

StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yep, Greg is absolutely right (once again Wink).  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.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K reputation)
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 Doze ) and give a feedback.




Bon Chance et Bon Nuit!



(and that's about it for my français)
Michel Levy
Michel Levy
StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)
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 Doze ) and give a feedback.

Thanks

Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.5K 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.



Michel Levy
Michel Levy
StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)StrataFrame User (445 reputation)
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 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?


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