Entity Connection String at run-time


Following is useful

Public Shared Function GetRunTimeEntityConnectionString(EntityConnectionStringName As String) As String
Dim currentConString = Configuration.ConfigurationManager.ConnectionStrings(EntityConnectionStringName).ConnectionString
Dim builder As New EntityClient.EntityConnectionStringBuilder(currentConString)
builder.ProviderConnectionString = <“NewConString”>
‘builder.Metadata = “res://*/LookupModel.csdl|res://*/LookupModel.ssdl|res://*/LookupModel.msl”
‘builder.Provider = “System.Data.SqlClient”
Return builder.ConnectionString
End Function

Dim EntityConnectionString = RuntimeConnectionString.GetRunTimeEntityConnectionString(<EntityConStringName>)
context = New <Namespace>.EntityModel.<EntityName>Entities(EntityConnectionString)

If trying to change actual SharedApp.config as follows then currently get an error.
Configuration.ConfigurationManager.ConnectionStrings(<“Name of Entity ConString”>).ConnectionString = RunTimeEntityConnectionString
system.configuration.configurationerrorsexception the configuration is read only

There are suggested methods for solving this online

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: