Skip to content

Commit 3e20185

Browse files
authored
Disconnect serverConnection in finally block (#769)
Wrap Server creation and BuildContent call in a try/finally so serverConnection.Disconnect() is always invoked. This ensures the SQL Server connection is closed even if BuildContent throws, preventing potential connection leaks.
1 parent 867f15c commit 3e20185

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/Verify.SqlServer/SchemaValidation/SqlScriptBuilder.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ public string BuildContent(SqlConnection connection)
3535
{
3636
ConnectionString = connection.ConnectionString,
3737
};
38-
var server = new Server(serverConnection);
39-
40-
return BuildContent(server, builder);
38+
try
39+
{
40+
var server = new Server(serverConnection);
41+
return BuildContent(server, builder);
42+
}
43+
finally
44+
{
45+
serverConnection.Disconnect();
46+
}
4147
}
4248

4349
string BuildContent(Server server, SqlConnectionStringBuilder builder)

0 commit comments

Comments
 (0)