Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix | SqlLocalDB instance pipename issue with Encryption #1433

Merged
merged 3 commits into from
Jan 14, 2022
Merged

Fix | SqlLocalDB instance pipename issue with Encryption #1433

merged 3 commits into from
Jan 14, 2022

Conversation

JRahnama
Copy link
Contributor

fixes #1395

This PR fixes the issue by adding the support for Instance pipe name of localdb.

@ErikEJ
Copy link
Contributor

ErikEJ commented Dec 14, 2021

Does this also cover Shared instance?

@JRahnama
Copy link
Contributor Author

@ErikEJ I think so, Every localdb (shared or not) is having a pipe name instance
image
that pipe name is good for shared instances as well.
We were only checking for (localdb) as an identifier of localDB, however as per mentioned issue, some frameworks are using name pipe internally. This was not a problem up until we added Encrypt=true and now it tries to send and encrypted connection to localDB which is not supported.

Copy link
Contributor

@DavoudEshtehari DavoudEshtehari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add LocalDbSharedInstanceName into the config.json and config.default.json files?

@DavoudEshtehari DavoudEshtehari changed the title Fix SqlLocalDB instance pipename issue with Encryption Fix | SqlLocalDB instance pipename issue with Encryption Jan 7, 2022
@DavoudEshtehari DavoudEshtehari added the 🐛 Bug! Issues that are bugs in the drivers we maintain. label Jan 7, 2022
@DavoudEshtehari DavoudEshtehari modified the milestones: 4.0.1, 5.0.0-preview1 Jan 13, 2022
}
else if (input.StartsWith(LocalDbPrefix_NP.AsSpan(), StringComparison.OrdinalIgnoreCase))
{
return input.ToString();
Copy link
Contributor

@johnnypham johnnypham Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the input should also be checked if it's empty here. I'm getting different errors when using the prefixes as the server:

(localdb)\;
(provider: SNI_PN11, error: 51 - An instance name was not specified while connecting to a Local Database Runtime. Specify an instance name in the format (localdb)\instance_name.)

np:\\.\pipe\LOCALDB#/:
(provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Copy link
Contributor Author

@JRahnama JRahnama Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is user error. The error is pretty much explanatory and that is the behavior from before for (localdb).
1- (localdb)\.
2-(localdb)\Instance name
3- (localdb)\.\shared instance name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for named pipe:
the only part changing in np:\\.\pipe\LOCALDB#SH452F48\tsql\query is the number inside it

Copy link
Contributor Author

@JRahnama JRahnama Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could use other methods such as RegEx, but that would be an overkill. The fact that connection string starts with np:\\.\pipe\LOCALDB# is enough to conclude that user is trying LocalDB, so the Encrypt=true would not be applied to it. If user wants to change the named pipe server will reject that.

Copy link
Contributor

@johnnypham johnnypham Jan 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of (localdb)\ , we tell the user that the server name is not in the correct format, i.e. the instance name is missing. In the case of np:\\.\pipe\LOCALDB#/, shouldn't we also tell them that the instance name is missing?

Edit: I don't think you understand my original comment. There is no need for regex here and this has nothing to do with encrypt=true. All I'm saying is when the user tries to connect with np:\\.\pipe\LOCALDB#/, we should tell them they are missing the instance name, just like we already do if they try connecting with (localdb)\.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of (localdb)\ , we tell the user that the server name is not in the correct format, i.e. the instance name is missing. In the case of np:\\.\pipe\LOCALDB#/, shouldn't we also tell them that the instance name is missing?

I dont think so. Because that pattern is not created by user. It is in a folder in LocalDB inside Program File folder. So, you cant just create whatever you want. One can read the name from the folder using a process or copy paste it, whereas (localdb) could have some user mistakes. Plus are you testing in managed SNI?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is the same in managed SNI.

The whole point of error handling is that we can't assume that the user knows what they're doing and got their named pipe server name from the correct source. If we assumed that the user does the right thing every time, there would be no need for error handling.

The error message when trying to connect to np:\\.\pipe\LOCALDB#/ states that a connection could not be opened because the server was not found or was inaccessible. We should be more specific and say that the connection failed because the provided server name was not even in the correct format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see merit in aligning the errors produced between tcp and np scenarios. However, I wouldn't block this PR since we are not changing the behavior here. The behavior can be addressed in the future so that we don't delay fixing this issue for the upcoming hotfix.

@JRahnama JRahnama merged commit c805b8f into dotnet:main Jan 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug! Issues that are bugs in the drivers we maintain.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SqlException thrown related to encryption not being supported for SQL LocalDB named pipes
6 participants