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

ArgumentOutOfRange when datasource starts with comma #3110

Open
benrr101 opened this issue Jan 14, 2025 · 1 comment
Open

ArgumentOutOfRange when datasource starts with comma #3110

benrr101 opened this issue Jan 14, 2025 · 1 comment
Labels
🐛 Bug! Issues that are bugs in the drivers we maintain. 🆕 Triage Needed For new issues, not triaged yet.

Comments

@benrr101
Copy link
Contributor

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)

@benrr101 benrr101 added 🐛 Bug! Issues that are bugs in the drivers we maintain. 🆕 Triage Needed For new issues, not triaged yet. labels Jan 14, 2025
@ErikEJ
Copy link
Contributor

ErikEJ commented Jan 15, 2025

Have you tried this on older client versions?

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. 🆕 Triage Needed For new issues, not triaged yet.
Projects
None yet
Development

No branches or pull requests

2 participants