|
In DevForce you can do this with an implementation of the IDataSourceKeyResolver interface. The interface supports a single method, GetKey, which DevForce will call the first time it needs to work with the data source. The "key" returned by the method is usually a ClientEdmKey, which is basically just strongly-typed connection information. In your GetKey method you can build up the connection string entirely from code, or take an existing connection string from the config and modify it as needed, or as you do above, load it into a SqlConnectionStringBuilder to work with.
Here's an example:
[System.Runtime.Serialization. DataContract] public class DynamicDataSourceKeyResolver : IDataSourceKeyResolver { public IDataSourceKey GetKey( String keyName, String keyExtension, bool onServer) { if (!onServer) return null; EntityConnectionStringBuilder eBuilder = new EntityConnectionStringBuilder(cs.ConnectionString); SqlConnectionStringBuilder sBuilder = new SqlConnectionStringBuilder(eBuilder.ProviderConnectionString); sBuilder.Password = "bob"; eBuilder.ProviderConnectionString = sBuilder.ConnectionString; return new ClientEdmKey(keyName, eBuilder.ConnectionString); } }
|