From d003f65a2e37fbdb87a1e9b52d97333e9124593b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 15 Mar 2026 13:27:05 +0000 Subject: [PATCH 1/2] fix: auto-open connection in LoadTempTables (Closes #306) When SqlCommandProvider is constructed with a connection string (new Q(connStr)), the underlying SqlConnection is created but not yet open. Previously LoadTempTables would fail with 'ExecuteNonQuery requires an open and available Connection' because neither the CREATE TABLE command nor the SqlBulkCopy had a chance to open it. Fix: add `use openedConn = connection.UseLocally()` at the top of the generated LoadTempTables body. UseLocally() opens a closed connection and registers disposal (close) at the end of the method, matching the pattern already used by ExecuteNonQuery. When the caller passes a live, already-open SqlConnection the method is a no-op, so existing behaviour is unchanged. Also add a test that exercises the connection-string constructor path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/SqlClient.DesignTime/DesignTime.fs | 7 +++---- tests/SqlClient.Tests/TempTableTests.fs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/SqlClient.DesignTime/DesignTime.fs b/src/SqlClient.DesignTime/DesignTime.fs index 735d6edc..ce3393a1 100644 --- a/src/SqlClient.DesignTime/DesignTime.fs +++ b/src/SqlClient.DesignTime/DesignTime.fs @@ -761,10 +761,9 @@ type DesignTime private() = <@@ let cmd = (%%command : ISqlCommand) cmd.Raw.Connection @@> - <@@ do - use create = (%%connection : SqlConnection).CreateCommand(CommandText = tempTableDefinitions) - create.ExecuteNonQuery() |> ignore - + <@@ use openedConn = (%%connection : SqlConnection).UseLocally() + use create = (%%connection : SqlConnection).CreateCommand(CommandText = tempTableDefinitions) + create.ExecuteNonQuery() |> ignore (%%loadValues exprArgs connection) ignore() @@>) diff --git a/tests/SqlClient.Tests/TempTableTests.fs b/tests/SqlClient.Tests/TempTableTests.fs index 52deeac2..e00b5e36 100644 --- a/tests/SqlClient.Tests/TempTableTests.fs +++ b/tests/SqlClient.Tests/TempTableTests.fs @@ -17,6 +17,28 @@ type TempTable = ConnectionStringOrName = ConnectionStrings.AdventureWorksLiteral> +[] +let usingTempTableWithConnectionString() = + // Regression test for issue #306: LoadTempTables should auto-open the connection + use cmd = new TempTable(ConnectionStrings.AdventureWorksLiteral) + + cmd.LoadTempTables( + Temp = + [ TempTable.Temp(Id = 1, Name = Some "cat") + TempTable.Temp(Id = 2, Name = Some "dog") ]) + + let actual = + cmd.Execute() + |> Seq.map(fun x -> x.Id, x.Name) + |> Seq.toList + + let expected = [ + 1, Some "cat" + 2, Some "dog" + ] + + Assert.Equal<_ list>(expected, actual) + [] let usingTempTable() = use conn = new SqlConnection(ConnectionStrings.AdventureWorksLiteral) From 4dba2a891f83b087b8a17ba4d9c910442ba98dd2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 15 Mar 2026 13:34:08 +0000 Subject: [PATCH 2/2] ci: trigger checks