Skip to content

Commit 8dd6904

Browse files
committed
remove SqlAuthenticationMethod hack
1 parent f69c9c9 commit 8dd6904

3 files changed

Lines changed: 10 additions & 25 deletions

File tree

readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ This test:
5050
```cs
5151
await Verify(connection);
5252
```
53-
<sup><a href='/src/Tests/Tests.cs#L316-L320' title='Snippet source file'>snippet source</a> | <a href='#snippet-SqlServerSchema' title='Start of snippet'>anchor</a></sup>
53+
<sup><a href='/src/Tests/Tests.cs#L317-L321' title='Snippet source file'>snippet source</a> | <a href='#snippet-SqlServerSchema' title='Start of snippet'>anchor</a></sup>
5454
<!-- endSnippet -->
5555

5656
Will result in the following verified file:
@@ -69,7 +69,7 @@ await Verify(connection)
6969
// include only tables and views
7070
.SchemaIncludes(DbObjects.Tables | DbObjects.Views);
7171
```
72-
<sup><a href='/src/Tests/Tests.cs#L682-L688' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaInclude' title='Start of snippet'>anchor</a></sup>
72+
<sup><a href='/src/Tests/Tests.cs#L683-L689' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaInclude' title='Start of snippet'>anchor</a></sup>
7373
<!-- endSnippet -->
7474

7575
Available values:
@@ -107,7 +107,7 @@ await Verify(connection)
107107
_ => _ is TableViewBase ||
108108
_.Name == "MyTrigger");
109109
```
110-
<sup><a href='/src/Tests/Tests.cs#L707-L715' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
110+
<sup><a href='/src/Tests/Tests.cs#L708-L716' title='Snippet source file'>snippet source</a> | <a href='#snippet-SchemaFilter' title='Start of snippet'>anchor</a></sup>
111111
<!-- endSnippet -->
112112

113113

@@ -129,7 +129,7 @@ command.CommandText = "select Value from MyTable";
129129
var value = await command.ExecuteScalarAsync();
130130
await Verify(value!);
131131
```
132-
<sup><a href='/src/Tests/Tests.cs#L491-L501' title='Snippet source file'>snippet source</a> | <a href='#snippet-Recording' title='Start of snippet'>anchor</a></sup>
132+
<sup><a href='/src/Tests/Tests.cs#L492-L502' title='Snippet source file'>snippet source</a> | <a href='#snippet-Recording' title='Start of snippet'>anchor</a></sup>
133133
<!-- endSnippet -->
134134

135135
Will result in the following verified file:
@@ -184,7 +184,7 @@ await Verify(
184184
sqlEntries = entries
185185
});
186186
```
187-
<sup><a href='/src/Tests/Tests.cs#L568-L598' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
187+
<sup><a href='/src/Tests/Tests.cs#L569-L599' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingSpecific' title='Start of snippet'>anchor</a></sup>
188188
<!-- endSnippet -->
189189

190190

@@ -212,7 +212,7 @@ var sqlErrorsViaType = entries
212212
.Select(_ => _.Data)
213213
.OfType<ErrorEntry>();
214214
```
215-
<sup><a href='/src/Tests/Tests.cs#L624-L643' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
215+
<sup><a href='/src/Tests/Tests.cs#L625-L644' title='Snippet source file'>snippet source</a> | <a href='#snippet-RecordingReadingResults' title='Start of snippet'>anchor</a></sup>
216216
<!-- endSnippet -->
217217

218218

src/Tests/Tests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ static Tests() =>
88
"VerifySqlServer",
99
connection =>
1010
{
11-
var serverConnection = new ServerConnection();
12-
SqlScriptBuilder.SqlConnectionObjectField.SetValue(serverConnection, connection);
13-
serverConnection.NonPooledConnection = true;
11+
var serverConnection = new ServerConnection
12+
{
13+
ConnectionString = connection.ConnectionString,
14+
};
1415
var server = new Server(serverConnection);
1516
server.ConnectionContext.ExecuteNonQuery(
1617
"""

src/Verify.SqlServer/SchemaValidation/SqlScriptBuilder.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
class SqlScriptBuilder(SchemaSettings settings)
22
{
3-
// TODO: when Microsoft.Data.SqlClient 7.0.1 adds TypeForwardedTo for SqlAuthenticationMethod,
4-
// revert to using new ServerConnection(SqlConnection) and remove this reflection workaround.
5-
//
6-
// SMO 181.15.0 ServerConnection(SqlConnection) constructor calls InitFromSqlConnection
7-
// which references SqlAuthenticationMethod — a type moved from Microsoft.Data.SqlClient
8-
// to Microsoft.Data.SqlClient.Extensions.Abstractions in SqlClient 7.0. The CLR can't
9-
// resolve the type in the original assembly, causing a TypeLoadException.
10-
//
11-
// Workaround: construct ServerConnection() with default constructor (no InitFromSqlConnection),
12-
// then set the internal m_SqlConnectionObject field via reflection to reuse the open connection.
13-
// SMO detects the connection is already open and uses it directly.
14-
internal static readonly FieldInfo SqlConnectionObjectField =
15-
typeof(ConnectionManager).GetField("m_SqlConnectionObject", BindingFlags.NonPublic | BindingFlags.Instance) ??
16-
throw new("Could not find field m_SqlConnectionObject on ConnectionManager. The SMO internals may have changed.");
17-
183
static Dictionary<string, string> tableSettingsToScrubLookup;
194

205
static SqlScriptBuilder()
@@ -50,7 +35,6 @@ public string BuildContent(SqlConnection connection)
5035
};
5136
try
5237
{
53-
SqlConnectionObjectField.SetValue(serverConnection, connection);
5438
var server = new Server(serverConnection);
5539
return BuildContent(server, builder);
5640
}

0 commit comments

Comments
 (0)