From 1b0a48a5a418f6a1e76f3584ce5296066f00b495 Mon Sep 17 00:00:00 2001 From: Kushaal Shroff <51415286+KushaalShroff@users.noreply.github.com> Date: Tue, 1 Oct 2024 16:45:44 +0530 Subject: [PATCH] Fix Current_user being NULL after reset connection (#2996) Before this commit, if the current session had triggered a Tds Reset Connection then the current_user of the session would be set to NULL instead of the databases' default user. This was happening since we were resetting session_authorization which was initially copied from PG's Discard All function. This is not needed since we have fixed the Database Context being reset in an earlier commit, removing this redundant line of code will maintain the user being set after the "USE DB" execution for DbContextReset. With this commit we also enable pooling=true for the dotnet framework. Signed-off-by: Kushaal Shroff --- contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c | 1 - test/dotnet/ExpectedOutput/2_Successful_reset.out | 3 +++ test/dotnet/input/ResetConnection/2_Successful_reset.txt | 1 + test/dotnet/utils/ConfigSetup.cs | 5 ----- test/dotnet/utils/TestUtils.cs | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c b/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c index b7b0f5daca5..4ffbcf2f1dc 100644 --- a/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c +++ b/contrib/babelfishpg_tds/src/backend/tds/tdsprotocol.c @@ -100,7 +100,6 @@ TdsDiscardAll() /* Closing portals might run user-defined code, so do that first. */ PortalHashTableDeleteAll(); - SetPGVariable("session_authorization", NIL, false); ResetAllOptions(); DropAllPreparedStatements(); Async_UnlistenAll(); diff --git a/test/dotnet/ExpectedOutput/2_Successful_reset.out b/test/dotnet/ExpectedOutput/2_Successful_reset.out index 394dc764ee3..1a89e611e27 100644 --- a/test/dotnet/ExpectedOutput/2_Successful_reset.out +++ b/test/dotnet/ExpectedOutput/2_Successful_reset.out @@ -1,4 +1,7 @@ #Q#select db_name(); #D#nvarchar master +#Q#select current_user; +#D#varchar +dbo #Q#drop database db1; diff --git a/test/dotnet/input/ResetConnection/2_Successful_reset.txt b/test/dotnet/input/ResetConnection/2_Successful_reset.txt index 123124922d6..93439ae7d39 100644 --- a/test/dotnet/input/ResetConnection/2_Successful_reset.txt +++ b/test/dotnet/input/ResetConnection/2_Successful_reset.txt @@ -1,2 +1,3 @@ select db_name(); +select current_user; drop database db1; diff --git a/test/dotnet/utils/ConfigSetup.cs b/test/dotnet/utils/ConfigSetup.cs index bb3c74296de..0dcd749c84f 100644 --- a/test/dotnet/utils/ConfigSetup.cs +++ b/test/dotnet/utils/ConfigSetup.cs @@ -9,8 +9,6 @@ public static class ConfigSetup /* Declaring variables required for a Test Run. */ static readonly Dictionary Dictionary = LoadConfig(); public static readonly string BblConnectionString = Dictionary["bblConnectionString"]; - - public static readonly string BCPConnectionString = Dictionary["BCPConnectionString"]; public static readonly string QueryFolder = Dictionary["queryFolder"]; public static readonly string TestName = Dictionary["testName"]; public static readonly bool RunInParallel = bool.Parse(Dictionary["runInParallel"]); @@ -47,9 +45,6 @@ public static Dictionary LoadConfig() /* Creating Server Connection String and Query. */ dictionary["bblConnectionString"] = BuildConnectionString(dictionary["babel_URL"], dictionary["babel_port"], - dictionary["babel_databaseName"], - dictionary["babel_user"], dictionary["babel_password"]) + "pooling=false;"; - dictionary["BCPConnectionString"] = BuildConnectionString(dictionary["babel_URL"], dictionary["babel_port"], dictionary["babel_databaseName"], dictionary["babel_user"], dictionary["babel_password"]); return dictionary; diff --git a/test/dotnet/utils/TestUtils.cs b/test/dotnet/utils/TestUtils.cs index dd95723b535..6a483567121 100644 --- a/test/dotnet/utils/TestUtils.cs +++ b/test/dotnet/utils/TestUtils.cs @@ -42,7 +42,7 @@ public bool insertBulkCopy(DbConnection bblCnn, DbCommand bblCmd, String sourceT /* To Enforce Reset Connection. */ reader = bblCmd.ExecuteReader(); using (SqlConnection destinationConnection = - new SqlConnection(ConfigSetup.BCPConnectionString)) + new SqlConnection(ConfigSetup.BblConnectionString)) { destinationConnection.Open();