- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我开发了一个监控应用程序。所以我使用了一个定时器函数来检查 SQL 表中的一些值。
虽然有这么多函数,但它会为一个名为 getLogEntry() 的函数提供以下错误
message>Transaction (Process ID 84) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.</message>
<innerMessage>
</innerMessage>
<source>.Net SqlClient Data Provider</source>
<stackTrace>at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at System.Data.SqlClient.SqlDataReader.HasMoreRows()
at System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
at ShiftAlertSystem.DBAccess.getLogEntry(Int32 nEventLogIdn, connections cn)</stackTrace>
<createdAt>2012/06/18 13:10:47</createdAt>
这是函数的实现
public LogEntry getLogEntry(int nEventLogIdn, connections cn)
{
lock (_objLock)
{
LogEntry lgEntObj = new LogEntry();
SqlConnection NewCon3 = new SqlConnection();
SqlCommand newCmd2 = null;
SqlDataReader dr = null;
try
{
string connectString;
// Configuration config = ConfigurationManager.u
string DataSource = cryptIT.Decrypt(cn.DataSource_bio);
string initialCatalog = cryptIT.Decrypt(cn.InitialCatalog_bio);
string user = cryptIT.Decrypt(cn.user_bio);
string password = cryptIT.Decrypt(cn.password_bio);
bool intergratedSecurity = cn.IntegratedSecurity_bio;
if (intergratedSecurity)
{
connectString = "Data Source=" + DataSource + ";Initial Catalog=" + initialCatalog + ";Integrated Security=True";
}
else
{
connectString = "Data Source=" + DataSource + ";Initial Catalog=" + initialCatalog + ";User ID=" + user + ";Password=" + password;
}
NewCon3 = new SqlConnection(connectString);
NewCon3.Open();
newCmd2 = NewCon3.CreateCommand();
newCmd2.Connection = NewCon3;
newCmd2.CommandType = CommandType.Text;
newCmd2.CommandText = @"
SELECT [nUserID]
,[sUserName]
,dateadd(s,[nDateTime],'1970/1/1') AS LogDateTime
,[nEventIdn]
,[nTNAEvent]
,[TB_READER].[nReaderIdn]
,[sName]
FROM
[TB_EVENT_LOG]
,[TB_USER]
,[TB_READER]
WHERE
[nEventLogIdn] = " + nEventLogIdn +
@" AND
[TB_EVENT_LOG].[nUserID] = [TB_USER].[sUserID]
AND
[nFlag]= 1
AND
[TB_EVENT_LOG].[nReaderIdn]=[TB_READER].[nReaderIdn]"
;
dr = newCmd2.ExecuteReader();
if (dr != null && dr.Read())
{
lgEntObj.nUserID = dr.GetInt32(0);
lgEntObj.nUserName = dr.GetString(1);
lgEntObj.LogDateTime = dr.GetDateTime(2);
lgEntObj.nEventIdn = dr.GetInt32(3);
lgEntObj.nTNAEvent = dr.GetInt16(4);
lgEntObj.nReaderIdn = dr.GetInt32(5);
lgEntObj.sName = dr.GetString(6);
}
dr.Close();
newCmd2.Dispose();
// NewCon.Close();
NewCon3.Close();
return lgEntObj;
}
catch (Exception exc)
{
CenUtility.ErrorLog.CreateLog(exc);
return null;
}
finally
{
if (dr != null)
dr.Close();
if(newCmd2 != null)
newCmd2.Dispose();
NewCon3.Close();
}
}
}
提前致谢
最佳答案
您可能需要引用此 question以获得更多有用的建议。
我使用以下模式进行数据库重试;在这种情况下,我们返回一个 DataTable,但无论如何模式都是相同的;您检测到基于 SqlException Number 的 SqlDeadlock 或超时,然后重试,最多重试 n 次。
public DataTable DoSomeSql(int retryCount = 1)
{
try
{
//Run Stored Proc/Adhoc SQL here
}
catch (SqlException sqlEx)
{
if (retryCount == MAX_RETRY_COUNT) //5, 7, Whatever
{
log.Error("Unable to DoSomeSql, reached maximum number of retries.");
throw;
}
switch (sqlEx.Number)
{
case DBConstants.SQL_DEADLOCK_ERROR_CODE: //1205
log.Warn("DoSomeSql was deadlocked, will try again.");
break;
case DBConstants.SQL_TIMEOUT_ERROR_CODE: //-2
log.Warn("DoSomeSql was timedout, will try again.");
break;
default:
log.WarnFormat(buf.ToString(), sqlEx);
break;
}
System.Threading.Thread.Sleep(1000); //Can also use Math.Rand for a random interval of time
return DoSomeSql(asOfDate, ++retryCount);
}
}
关于c# - 事务(进程 ID 84)在锁定资源上与另一个进程发生死锁,并已被选为死锁牺牲品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11097887/
有人告诉我,如果我只有一个“东西”,比如家(不是多个家),我应该在 routes.rb 中使用资源 :home,而不是资源 :home。但是当我查看路由时,POST 函数似乎想要 home#creat
Activity 开始。这些代码框架顺利通过。 // Initialize array adapters. One for already paired devices and //
资源 search-hadoop.com search-hadoop.com索引所有邮件列表,非常适合历史搜索。当你遇到问题时首先在这里搜索,因为很可能有人已经遇到了你的问题。 邮件列表 在A
我是 WPF 的新手,正在努力使用位于单独程序集中的样式。这就是我正在做的:- 我有一个带有\Themes 文件夹的类库项目,其中包含一个“generic.xaml”,它合并了\Themes 内的子文
我正在编写一个使用虚拟树状文件结构的插件。基本上它就像一个包含文件的标准文件系统,区别在于这些文件实际上并不存在于文件系统中的特定位置,而只是 java 对象。 这些当前由使用 SettingProv
如果我在 XAML 中使用以下内容,我会收到错误消息: 错
我正在使用 laravel 资源来获取 api 的数据: return [ 'id' => $this->id, 'unread' =>
我有以下 pom.xml: 4.0.0 mycompany resource-fail 0.0.1-SNAPSHOT BazBat
许多GDI +类都实现IDisposable,但是我不确定何时应该调用Dispose。对于使用new或静态方法(例如Graphics.CreateGraphics)创建的实例来说,这很明显。但是,由属
我正在构建一组 RESTful 资源,其工作方式如下:(我将使用“people”作为示例): 获取/people/{key} - 返回一个人对象 (JSON) GET/people?first_nam
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一个使用 $resource 的简单 Controller : var Regions = $resource('mocks/regions.json'); $scope.regions =
在 Azure 门户中,如何查看不同资源之间的依赖关系。我特别想查看哪些资源正在使用我要删除的存储。 最佳答案 您可以使用应用程序洞察应用程序 map 来执行此操作: 您还可以打开存储帐户的日志记录:
我正在使用 ionic 生成资源(图标和启动画面)。我正在使用 ionic v2.1.0 和 cordova v6.4.0。 到目前为止我一直在使用(它在以前的版本中工作): cordova plat
是否可以使用 Assets 包含子文件夹中的文件? 示例:[base_url]/assets/css/pepper-grinder/jquery-ui-1.8.11.custom.min.css 最佳
我正在阅读一些尝试教授 Android 开发的书。在书中,作者概述了 res/下的一些目录。他提到 res/menu 包含基于 XML 的菜单规范。他还提到了保存“通用文件”的 res/raw。当我创
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我在服务器上使用 express-resource。在我的 AngularJS Controller 中: var User = $resource('/services/users/:use
因此,每当我运行我的应用程序时,它都会立即崩溃并给出以下错误: No package identifier when getting value for resource number 0x00000
对于我正在创建的(网络)应用程序,我需要使用基本身份验证在我的 UIWebView 中加载页面。 现在设置我使用的授权 header : NSString *result = [NSString st
我是一名优秀的程序员,十分优秀!