Вероятнее всего проблема может быть связанна с данными
Ни кто не любит ждать)
Pantuchi, смотри. Разница между 4 и 27 секунд важна не для твоего кода а для бизнеса.
Спроси бизнес как они хотят?
def addLogError(errText: str, sqlText: str, parameters: str, functionname: str, username: str, appname: str):
connection = None
sql = (f'declare @v_errText nvarchar(max) = \'{errText}\';'
f'declare @v_sqlText nvarchar(max) = \'{sqlText}\';'
f'declare @v_parameters nvarchar(max) = \'{parameters}\';'
f'declare @nv_fn nvarchar(max) = cast(\'{functionname}\' as nvarchar(max));'
f'declare @nv_un nvarchar(max) = cast(\'{username}\' as nvarchar(max));'
f'declare @nv_appname nvarchar(max) = cast(\'{appname}\' as nvarchar(max));'
f''
f'insert into LogErr([errText], [sqlText], [parameters], [functionname], [username], [AppName]) '
f'VALUES('
f' cast(@v_errText as varbinary(max)), '
f' cast(@v_sqlText as varbinary(max)), '
f' cast(@v_parameters as varbinary(max)), '
f' @nv_fn, @nv_un, @nv_appname'
f')')
try:
connection = django.db.connections['default']
cursor = connection.cursor()
cursor.execute(sql)
except BaseException as e:
print(e)
finally:
if connection:
connection.close()
public DateTime getDatetimeValue(int ID, int propertyID)
{
string sql = "select dbo.getDatetimeValue(@ID, @propertyID)";
DateTime result = new DateTime();
using (SqlConnection con = new SqlConnection(stringConnect))
{
SqlCommand com = new SqlCommand(sql, con);
com.Parameters.Add(new SqlParameter("@ID", ID));
com.Parameters.Add(new SqlParameter("@propertyID", propertyID));
try
{
con.Open();
object val = com.ExecuteScalar();
DateTime.TryParse(val.ToString(), out result);
}
catch (Exception e)
{
string stack = e.StackTrace;
string msg = e.Message;
string method = "getDatetimeValue";
string param = "ID=" + ID + "; propertyID=" + propertyID + ";";
addlogErr(WebConfigurationManager.AppSettings["AppName"], method, param, msg, stack);
Debug.WriteLine(formaExceptionMsg(method, param, msg, stack));
if (interceptException)
throw new Exception(method, e);
}
finally
{
con.Close();
}
}
return result;
}
public void RemoveAndGlue(int userID, int periodID)
{
//.....
SqlConnection connection = new SqlConnection(ark.stringConnect);
connection.Open();
SqlTransaction transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted);
try
{
ModelPeriod model = GetPeriod(periodID);
if (model == null) throw new Exception("Ошибка операции");
List<int> items = GetFriends(periodID);
SqlCommand command1 = _Delete(userID, periodID);
command1.CommandTimeout = 60;
command1.Connection = connection;
command1.Transaction = transaction;
command1.ExecuteNonQuery();
ModelPeriod uPeriod = null;
if (items[0] > 0 && items[2] > 0)
{
DateTime dateEnd = ark.getDatetimeValue(items[2], pid_dateBegin); //<-- вываливается по таймауту
dateEnd = dateEnd.AddDays(-1);
uPeriod = new ModelPeriod();
uPeriod.PeriodID = items[0];
uPeriod.DateBegin = ark.getDatetimeValue(items[0], pid_dateBegin); //<-- вываливается по таймауту
uPeriod.DateEnd = dateEnd;
}
else if (items[0] > 0 && items[2] <= 0 && (status == pid_active || status == pid_expired))
{
DateTime dateEnd = ark.getDatetimeValue(items[0], pid_dateEnd); //<-- вываливается по таймауту
ark.setDatetimeValue(contractId, pid_c_dateEnd, dateEnd); //<-- вываливается по таймауту
}
else if (items[0] <= 0 && items[2] > 0)
{
DateTime dateBegin = ark.getDatetimeValue(contractId, pid_c_dateBegin); //<-- вываливается по таймауту
uPeriod = new ModelPeriod();
uPeriod.PeriodID = items[2];
uPeriod.DateBegin = dateBegin;
uPeriod.DateEnd = ark.getDatetimeValue(items[2], pid_dateEnd); //<-- вываливается по таймауту
}
if (uPeriod != null)
{
SqlCommand command2 = Command_UpdateCascadePeriod(userID, uPeriod);
command2.CommandTimeout = 60;
command2.Connection = connection;
command2.Transaction = transaction;
command2.ExecuteNonQuery();
}
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
throw new Exception(ex.Message);
}
finally
{
connection.Close();
}
}