Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes it's possible, but AFAIK only via Reflection. The following code should do what you need (read below for usage):</p> <pre><code>public static string SetConnectionString(Type assemblyMember, Type settingsClass, string newConnectionString, string connectionStringKey) { Type typSettings = Type.GetType(Assembly.CreateQualifiedName(assemblyMember.Assembly.FullName, settingsClass.FullName)); if (typSettings == null) { return null; } PropertyInfo prpDefault = typSettings.GetProperty("Default", BindingFlags.Static | BindingFlags.Public); if (prpDefault == null) { return null; } object objSettings = prpDefault.GetValue(null, null); if (objSettings == null) { return null; } // the default property, this[], is actually named Item PropertyInfo prpItem = objSettings.GetType().GetProperty("Item", BindingFlags.Instance | BindingFlags.Public); if (prpItem == null) { return null; } object[] indexerName = { connectionStringKey }; string oldConnectionString = (string)prpItem.GetValue(objSettings, indexerName); prpItem.SetValue(objSettings, newConnectionString, indexerName); return oldConnectionString; } </code></pre> <p><code>assemblyMember</code> is the calling type<br> <code>settingsClass</code> is the type of your settings class<br> <code>newConnectionString</code> is the full string to set<br> <code>connectionStringKey</code> is the name of the connection string that you defined in your app's settings</p> <p>You should call this method as soon as possible after your app has started, preferably in the Main() method.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload