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.

Possible source of error in creating master connection string

See original GitHub issue

Hello @Zaid-Ajaj. I am rewriting your code to the F# equivalent and I stumbled upon a problem with this line of code:

var connectionStringOfMaster = ConnectionString.Replace(databaseName, "master");

By change I tested this with a database name that was part of the Data Source name. I,e.

let connString = @"Data Source=VOXDB-PICURED01;Initial Catalog=PICURED;Persist Security Info=True;Integrated Security=SSPI;"

And obviously replacing PICURED with master yields a Data Source=VOXDB-master01

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
halcwbcommented, Feb 10, 2021

Hi Casper, I see what is happening here. The thing is, we are not using just a simple string replace. Instead, we use SqlConnectionStringBuilder to parse the full database name (i.e. “VOXDB-PICURED01” in your case) and replace it by “master”. I am not sure why in your case, only “PICURED” would get replaced and not the full database name “VOXDB-PICURED01”

On a side note: why rewrite the library in F# if you can use this library underneath and only wrap it inside a more F# API ? Personally I have used library in F# projects without problems but it is up to if you want a different API

I had a closer look at you’r code, but I think it is a simple string replace, only this method is used with the generated connection string that contains a random generated database name like: Data Source=VOXDB-PICURED01;Initial Catalog=ThrowawayDbfe50108b74;Integrated Security=True;Persist Security Info=True

So this will very unlikely be confused with the Data Source name.

Only I want it to run on the new Microsoft.Data.SqlClient.

Sounds like it would be a nice and easy PR to add to this library

I might try that, but don’t underestimate how rusty my C# language abilities are 😉.

0reactions
halcwbcommented, Feb 26, 2021

@Zaid-Ajaj Looks great, thanks. FYI this is my F# translation: https://gist.github.com/halcwb/c7a1340d69c9d4dcd2c6f0cdda46ab7e.

Small detail, I don’t think you need to keep track of the original connection string. Just use the master connection string for that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

This operation requires a connection to the 'master' database
The error is: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the ......
Read more >
Troubleshoot common connection issues to Azure SQL ...
Possible causes include the following: the client tried to connect to an unsupported version of SQL Server; the server was too busy to...
Read more >
Connectionstring results in unwanted error · Issue #97780
"This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original ...
Read more >
Connection to external SQL Server database
Connection String test failed: A network-related or instance-specific error occurred while establishing a connection to SQL Server.
Read more >
SQL Connection Strings tips
The connection string is an expression that contains the parameters required for the applications to connect a database server.
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