question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SqlServerConnection should use a more robust way of cloning the connection

See original GitHub issue

Currently 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:closed
  • Created 9 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jnm2commented, Feb 3, 2020

That helps, thank you!

1reaction
ajcvickerscommented, Feb 3, 2020

@jnm2 A couple of things. First, SecureString is not recommended anymore: see https://github.com/dotnet/platform-compat/blob/master/docs/DE0001.md

Second, 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:

  • Create the empty database
  • Then call Migrate on it

(Also, your scenario is just about the only situation where I approve of running Migrate in code. 😉)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found