ArgumentOutOfRange when datasource starts with commaΒ #3110
Open
Description
Describe the bug
When a connection string's data source starts with a comma, a ArgumentOutOfRangeException is thrown. Here is the stack trace:
Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'startIndex')
at System.String.LastIndexOf(Char value, Int32 startIndex, Int32 count)
at Microsoft.Data.Common.ADP.IsEndpoint(String dataSource, String prefix)
at Microsoft.Data.Common.ADP.IsAzureSynapseOnDemandEndpoint(String dataSource)
at Microsoft.Data.SqlClient.SqlConnection.CacheConnectionStringProperties()
at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(String value)
at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString)
at Program.<Main>$(String[] args) in C:\Projects\[redacted]\Program.cs:line 21
To reproduce
Very easy to reproducte:
var connection = new SqlConnection("Data Source=,");
Expected behavior
I think ideally either the comma should be accepted or a more explanatory "invalid data source" should be returned.
Further technical details
Microsoft.Data.SqlClient version: 6.0.0-preview3.24332.3
.NET target: .NET 8
SQL Server version: n/a (exception happens before connection is even attempted)
Operating system: Windows 11 (Version 10.0.26100 Build 26100)