-
Notifications
You must be signed in to change notification settings - Fork 316
Fix | SqlLocalDB instance pipename issue with Encryption #1433
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,25 +10,37 @@ namespace Microsoft.Data | |
| { | ||
| internal static partial class LocalDBAPI | ||
| { | ||
| private const string const_localDbPrefix = @"(localdb)\"; | ||
| private const string LocalDbPrefix = @"(localdb)\"; | ||
| private const string LocalDbPrefix_NP = @"np:\\.\pipe\LOCALDB#"; | ||
|
|
||
|
|
||
| [UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = CharSet.Unicode)] | ||
| private delegate int LocalDBFormatMessageDelegate(int hrLocalDB, uint dwFlags, uint dwLanguageId, StringBuilder buffer, ref uint buflen); | ||
|
|
||
| // check if name is in format (localdb)\<InstanceName - not empty> and return instance name if it is | ||
| // localDB can also have a format of np:\\.\pipe\LOCALDB#<some number>\tsql\query | ||
| internal static string GetLocalDbInstanceNameFromServerName(string serverName) | ||
| { | ||
| if (serverName == null) | ||
| return null; | ||
| serverName = serverName.TrimStart(); // it can start with spaces if specified in quotes | ||
| if (!serverName.StartsWith(const_localDbPrefix, StringComparison.OrdinalIgnoreCase)) | ||
| return null; | ||
| string instanceName = serverName.Substring(const_localDbPrefix.Length).Trim(); | ||
| if (instanceName.Length == 0) | ||
| return null; | ||
| else | ||
| return instanceName; | ||
| if (serverName is not null) | ||
| { | ||
| // it can start with spaces if specified in quotes | ||
| // Memory allocation is reduced by using ReadOnlySpan | ||
| ReadOnlySpan<char> input = serverName.AsSpan().Trim(); | ||
| if (input.StartsWith(LocalDbPrefix.AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| input = input.Slice(LocalDbPrefix.Length); | ||
| if (!input.IsEmpty) | ||
| { | ||
| return input.ToString(); | ||
johnnypham marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| else if (input.StartsWith(LocalDbPrefix_NP.AsSpan(), StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return input.ToString(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for named pipe: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
|
|
||
| } | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.