Skip to content

ArgumentOutOfRange when datasource starts with commaΒ #3110

Open
@benrr101

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)

Metadata

Assignees

No one assigned

    Labels

    πŸ› Bug!Issues that are bugs in the drivers we maintain.βœ”οΈ Triage DoneIssues that are triaged by dev team and are in investigation.πŸ™Œ Up-for-GrabsIssues that are ready to be picked up for anyone interested. Please self-assign and remove the label✨ Good first issueIssues that are simple enough for newcomers

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions