diff --git a/README.md b/README.md
index 263de2c0f..994d34fea 100644
--- a/README.md
+++ b/README.md
@@ -167,7 +167,7 @@ The following table lists all valid connection properties:
| FILE_TRANSFER_MEMORY_THRESHOLD | No | The maximum number of bytes to store in memory used in order to provide a file encryption. If encrypting/decrypting file size exceeds provided value a temporary file will be created and the work will be continued in the temporary file instead of memory. If no value provided 1MB will be used as a default value (that is 1048576 bytes). It is possible to configure any integer value bigger than zero representing maximal number of bytes to reside in memory. |
| CLIENT_CONFIG_FILE | No | The location of the client configuration json file. In this file you can configure easy logging feature. |
| ALLOWUNDERSCORESINHOST | No | Specifies whether to allow underscores in account names. This impacts PrivateLink customers whose account names contain underscores. In this situation, you must override the default value by setting allowUnderscoresInHost to true. |
-| QUERY_TAG | No | Optional string that can be used to tag queries and other SQL statements executed within a connection. The tags are displayed in the output of the QUERY_HISTORY , QUERY_HISTORY_BY_* functions. |
+| QUERY_TAG | No | Optional string that can be used to tag queries and other SQL statements executed within a connection. The tags are displayed in the output of the QUERY_HISTORY , QUERY_HISTORY_BY_* functions. To set QUERY_TAG on the statement level you can use SnowflakeDbCommand.QueryTag. |
diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
index a4c84caeb..3a3cfb82f 100755
--- a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
+++ b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs
@@ -1624,5 +1624,25 @@ public void TestGetResultsOfUnknownQueryIdWithConfiguredRetry()
conn.Close();
}
}
+
+ [Test]
+ public void TestSetQueryTagOverridesConnectionString()
+ {
+ using (var conn = new SnowflakeDbConnection())
+ {
+ string expectedQueryTag = "Test QUERY_TAG 12345";
+ string connectQueryTag = "Test 123";
+ conn.ConnectionString = ConnectionString + $";query_tag={connectQueryTag}";
+
+ conn.Open();
+ var command = conn.CreateCommand();
+ ((SnowflakeDbCommand)command).QueryTag = expectedQueryTag;
+ // This query itself will be part of the history and will have the query tag
+ command.CommandText = "SELECT QUERY_TAG FROM table(information_schema.query_history_by_session())";
+ var queryTag = command.ExecuteScalar();
+
+ Assert.AreEqual(expectedQueryTag, queryTag);
+ }
+ }
}
}
diff --git a/Snowflake.Data/Client/SnowflakeDbCommand.cs b/Snowflake.Data/Client/SnowflakeDbCommand.cs
index 36a04f151..15d8e0870 100755
--- a/Snowflake.Data/Client/SnowflakeDbCommand.cs
+++ b/Snowflake.Data/Client/SnowflakeDbCommand.cs
@@ -54,6 +54,11 @@ public override int CommandTimeout
get; set;
}
+ public string QueryTag
+ {
+ get; set;
+ }
+
public override CommandType CommandType
{
get
@@ -132,7 +137,7 @@ protected override DbConnection DbConnection
connection = sfc;
if (sfc.SfSession != null)
{
- sfStatement = new SFStatement(sfc.SfSession);
+ sfStatement = new SFStatement(sfc.SfSession, QueryTag);
}
}
}
@@ -143,7 +148,7 @@ protected override DbParameterCollection DbParameterCollection
{
return this.parameterCollection;
}
- }
+ }
protected override DbTransaction DbTransaction
{
@@ -373,15 +378,15 @@ private static Dictionary convertToBindList(List vals = new List