public void Cannot_change_connection_when_open()
        {
            var connection = new SqlConnection(SqlServerNorthwindTestStoreFactory.NorthwindConnectionString);

            var serviceProvider
                = new ServiceCollection()
                  .AddScoped(p => connection)
                  .AddDbContext <ConnectionInOnConfiguringContext>().BuildServiceProvider();

            using (SqlServerTestStore.GetNorthwindStore())
            {
                using var context = serviceProvider.GetRequiredService <ConnectionInOnConfiguringContext>();

                context.Database.OpenConnection();
                Assert.Same(connection, context.Database.GetDbConnection());
                Assert.True(context.Customers.Any());

                using var newConnection = new SqlConnection(SqlServerNorthwindTestStoreFactory.NorthwindConnectionString);

                Assert.Equal(
                    RelationalStrings.CannotChangeWhenOpen,
                    Assert.Throws <InvalidOperationException>(() => context.Database.SetDbConnection(newConnection)).Message);
            }
        }