모니터링 애플리케이션을 개발했습니다. 그래서 거기에 SQL 테이블의 일부 값을 확인하려면 타이머 함수를 사용했습니다. 이렇게 많은 기능이 있기는하지만트랜잭션 (프로세스 ID 84)이 다른 프로세스와 잠금 리소스에 교착 상태가되어 교착 상태 희생자로 선택되었습니다.
그것은 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();
}
}
}
감사 기능의 구현을 제공
당신이 대답했다 제안을 고려할 수 있습니다 http://stackoverflow.com/questions/2382410/sql-server-deadlock-fix-force-join-order-or-automatically-retry합니다. 원래 쿼리가 교착 상태 인 경우 쿼리 재 시도가 성공적으로 구현되었습니다. – dash
또한 몇 개의 로그 항목을 쓰고 있습니까? 많은 글을 쓰고 있다면, 많은 INSERT로 SELECT를 방해하고있는 것일 수 있습니다. – dash
이 응용 프로그램에서는 이러한 테이블에 아무 것도 기록되지 않지만 다른 소프트웨어는 해당 테이블에 데이터를 씁니다. –