SqlServerConnection should use a more robust way of cloning the connection
See original GitHub issueCurrently in SqlServerConnection.CreateMasterConnection()
we just create a new connection with a modified connection string in order to get a connection to the master database. But we know that SqlConnection.Open()
will by default strip out the password from the connection string so by the time we get the connection string it might have already been mangled.
There is also SqlCredentials
which was added in recent versions of SqlClient as an alternative to having credentials embedded in the connection string.
Incidentally ((ICloneable)sqlConnection).Clone()
can handle all of this, but the functionality isn’t available in CoreCLR.
Issue Analytics
- State:
- Created 9 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
SqlServerConnection should use a more robust way of ...
CreateMasterConnection() we just create a new connection with a modified connection string in order to get a connection to the master database.
Read more >Change sql server connection properties in cloned server
Hi Experts, I was given a cloned copy of a live sql server to do some testing with one default instance. I was...
Read more >Why do I need SQL Clone to copy databases?
Any small database can be copied by restoring it from a backup, attaching the data and log files, or by building it and...
Read more >Cloning From Home… a consideration. - PlantBasedSQL
SQL Clone relies on the relationship between the Image file (the centralized, virtualized parent, as it were that exists on a windows fileshare) ......
Read more >5.6.7.3 Cloning Remote Data
A secure connection is required when cloning encrypted data regardless of whether this clause is specified. For more information, see Configuring an Encrypted ......
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
That helps, thank you!
@jnm2 A couple of things. First,
SecureString
is not recommended anymore: see https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.mdSecond, I suspect that the best approach here is to not use EF to create the database instance. Connecting to master is one of those fragile things that can easily be broken by different SQL and client permissions and settings. Instead, I would recommend creating an empty database instance using a connection to master that you create appropriately.
MigrateAsync
is designed to treat such as database as new and run all the rest of the schema creation for you. EF doesn’t need to create to master for that.So:
(Also, your scenario is just about the only situation where I approve of running Migrate in code. 😉)