Run-time connection string updates
See original GitHub issueIs it possible in v3 to update the connection string at run-time? I am trying to iterate over several databases with different connection strings and apply the same migrations from a .dll to each database. I want to omit the .WithGlobalConnectionString
runner builder extension (this won’t be necessarily known at startup) and just set the connection string in a loop.
My service provider is created like this:
static IServiceProvider CreateServices()
{
return new ServiceCollection()
.AddFluentMigratorCore()
.ConfigureRunner(rb => rb
.AddSqlServer()
.WithMigrationsIn(typeof(SomeMigrationClass).Assembly))
.AddLogging(lb => lb.AddFluentMigratorConsole())
.BuildServiceProvider(false);
}
I am getting at the ProcessorOptions
and attempting to set the connection string like this in my loop:
var migrationRunner = _serviceProvider.GetRequiredService<IMigrationRunner>();
var processorOptions = _serviceProvider.GetRequiredService<IOptionsSnapshot<ProcessorOptions>>().Value;
processorOptions.ConnectionString = "MYCONNECTIONSTRING";
migrationRunner.MigrateUp();
When I do this, the migrationRunner.Processor.ConnectionString
is never changed. It uses the default “No Connection”. Am I doing something wrong?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Unable to convert runtime connection string to its design- ...
I updated to Visual Studio 2013 last week and I can no longer update my Entity Data model through the visual studio designer...
Read more >Connection Strings and Configuration Files - ADO.NET
Learn how to store connection strings for ADO.NET applications in an application configuration file, as a best practice for security and ...
Read more >How to: Save and Edit Connection Strings - Visual Studio ...
To quickly modify the connection string, edit the ConnectionString property, or click the down arrow on the Connection property and choose New ...
Read more >Can not uncheck "Use this connection string at runtime ...
Under the Remote connection string, there is a checkbox for "Use this connection string at runtime (update destination web.config)" which is ...
Read more >Entity Framework 6 – update connection string at runtime | tatvog
By default EF will use the connection string in the app.config file, but you can override by using the ConnectionString property as shown ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Perhaps it would be better to pose the desired solution and then ask whether fluent migrator currently supports it.
Here’s what I’d say you want to do:
@nZeus As a migration is something that you should only do at the start of your services, why don’t you just create your own service collection just for the migration services?
I don’t think that there is a need to have long-lived services with changing connection strings.
BTW: Adding
SetConnectionString
to the migration runner will most likely never happen. As I wrote, you can always create your own service collection and just set the connection string with a.WithGlobalConnectionString(connectionString)
in theConfigureRunner
extension method.