From 8fc35b3833a2a0b3b305dc68e546b78cfb18074e Mon Sep 17 00:00:00 2001 From: Andrea Cattaneo Date: Fri, 24 Feb 2023 15:22:13 +0100 Subject: [PATCH] SqlDb v1.0.0.153 - command timeout parameter --- ACUtils.SqlDb/ACUtils.SqlDb.csproj | 4 ++-- ACUtils.SqlDb/SqlDb.cs | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ACUtils.SqlDb/ACUtils.SqlDb.csproj b/ACUtils.SqlDb/ACUtils.SqlDb.csproj index 1871ec3..417ea10 100644 --- a/ACUtils.SqlDb/ACUtils.SqlDb.csproj +++ b/ACUtils.SqlDb/ACUtils.SqlDb.csproj @@ -5,8 +5,8 @@ Andrea Cattaneo true false - 1.0.0.152 - 1.0.0.152 + 1.0.0.153 + 1.0.0.153 Utility per interrogazione database MSSQL it true diff --git a/ACUtils.SqlDb/SqlDb.cs b/ACUtils.SqlDb/SqlDb.cs index 7410292..8f44c9d 100644 --- a/ACUtils.SqlDb/SqlDb.cs +++ b/ACUtils.SqlDb/SqlDb.cs @@ -20,6 +20,7 @@ public class SqlDb : IDisposable private static MissingSchemaAction missingSchemaAction = MissingSchemaAction.AddWithKey; public static MissingSchemaAction MissingSchemaAction { get => missingSchemaAction; set => missingSchemaAction = value; } + public static int? CommandTimeout; private static bool enforceConstraints = true; public static bool EnforceConstraints { get => enforceConstraints; set => enforceConstraints = value; } @@ -53,7 +54,12 @@ public SqlDb(string connectionString, bool persistentConnection = false) #region generateCommand internal static SqlCommand generateCommand(SqlConnection connection, string queryString) { - return new SqlCommand(queryString, connection); + var command = new SqlCommand(queryString, connection); + if (CommandTimeout.HasValue) + { + command.CommandTimeout = CommandTimeout.Value; + } + return command; } internal static SqlCommand generateCommand(SqlConnection connection, string queryString, KeyValuePair[] queryParams) @@ -406,7 +412,7 @@ public static T GetColVal(DataRow dataRow, string columnName) switch (val.GetType().Name) { case "DBNull": - return default(T); + return default; } switch (typeof(T).Name) {