Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e01cd64

Browse files
authored
Porting PR 19884 SqlConnection doesn't override DbProviderFactory property (#20198)
* Implements #19825: SqlConnection doesn't override DbProviderFactory property (#19884) * Implements #19825: SqlConnection doesn't override DbProviderFactory property * Test added for SqlConnection.DbProviderFactory implementation for #19825 * Remove the additional fact from integ auth test
1 parent 09d0809 commit e01cd64

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/System.Data.SqlClient/src/System/Data/SqlClient/SqlConnection.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ public string WorkstationId
316316
}
317317
}
318318

319+
protected override DbProviderFactory DbProviderFactory
320+
{
321+
get { return SqlClientFactory.Instance; }
322+
}
323+
319324
// SqlCredential: Pair User Id and password in SecureString which are to be used for SQL authentication
320325

321326
//

src/System.Data.SqlClient/tests/FunctionalTests/SqlConnectionTest.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44

55

6+
using System.Data.Common;
7+
using System.Reflection;
68
using Xunit;
79

810
namespace System.Data.SqlClient.Tests
@@ -36,6 +38,17 @@ public void IntegratedAuthConnectionTest()
3638
}
3739
}
3840
}
39-
}
4041

42+
[Fact]
43+
public void SqlConnectionDbProviderFactoryTest()
44+
{
45+
SqlConnection con = new SqlConnection();
46+
PropertyInfo dbProviderFactoryProperty = con.GetType().GetProperty("DbProviderFactory", BindingFlags.NonPublic | BindingFlags.Instance);
47+
Assert.NotNull(dbProviderFactoryProperty);
48+
DbProviderFactory factory = dbProviderFactoryProperty.GetValue(con) as DbProviderFactory;
49+
Assert.NotNull(factory);
50+
Assert.Same(typeof(SqlClientFactory), factory.GetType());
51+
Assert.Same(SqlClientFactory.Instance, factory);
52+
}
53+
}
4154
}

0 commit comments

Comments
 (0)