Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,19 @@ private static bool IsEndpoint(string dataSource, string prefix)
length = foundIndex;
}

// check for the instance name
foundIndex = dataSource.LastIndexOf('\\', length - 1, length - 1);
// Safeguard LastIndexOf call to avoid ArgumentOutOfRangeException when length is 0
if (length > 0)
{
// check for the instance name
foundIndex = dataSource.LastIndexOf('\\', length - 1, length - 1);
}
else
{
foundIndex = -1;
}



if (foundIndex > 0)
{
length = foundIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,20 @@ public void ConnectionRetryForNonAzureEndpoints()
Assert.Equal(1, (int)field.GetValue(cn));
}



[Fact]
public void ConnectionString_WithOnlyComma()
{
// Test Case for https://github.com/dotnet/SqlClient/issues/3110
// Validates that a single-comma Data Source (e.g., "Data Source=,") no longer causes ArgumentOutOfRangeException
// Instead, it should throw a SqlException indicating a connection failure

SqlConnection cn = new SqlConnection("Data Source=,;Initial Catalog=master;Integrated Security=True");
Assert.Throws<SqlException>(() => { cn.Open(); });

}

[Theory]
[InlineData("myserver.database.windows.net")]
[InlineData("myserver.database.cloudapi.de")]
Expand Down
Loading