-
Please help me -- urgent -- deadlock error
Here Iam using this activex DLL in VC++. Actually this DLL is meant for inserting
data. And last 2 functions get certain vales from databse. But when Iam
implementing this in VC++ it is giving the following error:
“
[Microsoft][ODBC SQL Server Driver][SQL Server]Your transaction (process
ID #71) was deadlocked with another process and has been chosen as the deadlock
victim. Rerun your transaction. “
Option Explicit
Private cn As Connection
Public Function InitConn(ByVal ConnStr As String) As Boolean
On Error GoTo errInitConn
Set cn = New Connection
With cn
.ConnectionString = ConnStr
.ConnectionTimeout = 15
.CommandTimeout = 15
.Open
InitConn = True
End With
Exit Function
errInitConn:
LogError Err.Number, Err.Source, Err.Description
End Function
Private Sub LogError(Optional p_ErrNo As Long, Optional p_ErrSource As String,
Optional p_ErrDesc As String)
Dim LogBuffer As String
Dim FilePtr As Long
LogBuffer = Now & vbTab & p_ErrNo & vbTab + p_ErrSource + vbTab + p_ErrDesc
FilePtr = FreeFile
Open App.Path + "\" + "db.err" For Append As FilePtr
Print #FilePtr, LogBuffer
Close FilePtr
End Sub
Public Function InsertRawmailIn(ByVal UMId As Long, ByVal FromAddr As String,
ByVal ToAddr As String, ByVal MessageSource As String, ByVal RemoteHost As
String, ByVal RemoteIP As String, ByVal RemotePort As Long, Optional ByVal
SenderId As Long, Optional ByVal MessageId As String) As Boolean
Dim SQL As String
Dim rs As Recordset
On Error GoTo errRawmailIn
SQL = "Select * from QRawMailIn where RecNo = -1"
Set rs = New Recordset
rs.Open SQL, cn, adOpenDynamic, adLockOptimistic
With rs
cn.BeginTrans
.AddNew
!UMId = UMId
!FromAddr = FromAddr
!ToAddr = ToAddr
!MessageSource = MessageSource
!RemoteHost = RemoteHost
!RemoteIP = RemoteIP
!RemotePort = RemotePort
!SenderId = SenderId
!MessageId = MessageId
.Update
cn.CommitTrans
.Close
InsertRawmailIn = True
End With
Exit Function
errRawmailIn:
' MsgBox Err.Number & " : " & Err.Description
LogError Err.Number, "InsertRawMailIn", Err.Description
End Function
Public Function InsertRawmailOut(ByVal FromAddr As String, ByVal ToAddr As
String, Optional ByVal RemoteHost As String, Optional ByVal RemoteIP As String,
Optional ByVal RemotePort As Long, Optional ByVal MessageSource As String,
Optional ByVal MessageId As String) As Boolean
Dim SQL As String
Dim rs As Recordset
On Error GoTo errRawmailOut
SQL = "Select * from QRawMailOut where RecNo = -1"
Set rs = New Recordset
rs.Open SQL, cn, adOpenDynamic, adLockOptimistic
With rs
cn.BeginTrans
.AddNew
!FromAddr = FromAddr
!ToAddr = ToAddr
!RemoteHost = RemoteHost
!RemoteIP = RemoteIP
!RemotePort = RemotePort
!MessageSource = MessageSource
!MessageId = MessageId
.Update
cn.CommitTrans
.Close
InsertRawmailOut = True
End With
Exit Function
errRawmailOut:
LogError Err.Number, "InsertRawMailOut", Err.Description
End Function
Public Function InsertRawmailInDeadLetter(ByVal UMId As Long, ByVal FromAddr
As String, ByVal ToAddr As String, ByVal MessageSource As String, ByVal RemoteHost
As String, ByVal RemoteIP As String, ByVal RemotePort As Long, Optional ByVal
SenderId As Long, Optional ByVal MessageId As String) As Boolean
Dim SQL As String
Dim rs As Recordset
On Error GoTo errRawmailInDeadLetter
SQL = "Select * from QRawMailInDeadLetter where QRecNo = -1"
Set rs = New Recordset
rs.Open SQL, cn, adOpenDynamic, adLockOptimistic
With rs
.AddNew
!UMId = UMId
!FromAddr = FromAddr
!ToAddr = ToAddr
!MessageSource = MessageSource
!RemoteHost = RemoteHost
!RemoteIP = RemoteIP
!RemotePort = RemotePort
!SenderId = SenderId
!MessageId = MessageId
.Update
.Close
InsertRawmailInDeadLetter = True
End With
Exit Function
errRawmailInDeadLetter:
LogError Err.Number, "InsertRawMailInDeadLetter", Err.Description
End Function
Public Function InsertRawmailOutDeadLetter(ByVal FromAddr As String, ByVal
ToAddr As String, Optional ByVal RemoteHost As String, Optional ByVal RemoteIP
As String, Optional ByVal RemotePort As Long, Optional ByVal MessageSource
As String, Optional ByVal MessageId As String) As Boolean
Dim SQL As String
Dim rs As Recordset
On Error GoTo errRawmailOutDeadLetter
SQL = "Select * from QRawmailOutDeadLetter where QRecNo = -1"
Set rs = New Recordset
rs.Open SQL, cn, adOpenDynamic, adLockOptimistic
With rs
.AddNew
!FromAddr = FromAddr
!ToAddr = ToAddr
!RemoteHost = RemoteHost
!RemoteIP = RemoteIP
!RemotePort = RemotePort
!MessageSource = MessageSource
!MessageId = MessageId
.Update
.Close
InsertRawmailOutDeadLetter = True
End With
Exit Function
errRawmailOutDeadLetter:
LogError Err.Number, "InsertRawMailOutDeadLetter", Err.Description
End Function
Public Function InsertMailBounced(ByVal FromAddr As String, ByVal ToAddr
As String, ByVal RemoteHost As String, ByVal RemoteIP As String, ByVal RemotePort
As Long) As Boolean
Dim SQL As String
Dim rs As Recordset
On Error GoTo errMailBounced
SQL = "Select * from MailBounced where RecNo = -1"
Set rs = New Recordset
With rs
.Open SQL, cn, adOpenDynamic, adLockOptimistic
.AddNew
!FromAddr = FromAddr
!ToAddr = ToAddr
!RemoteHost = RemoteHost
!RemoteIP = RemoteIP
!RemotePort = RemotePort
.Update
.Close
InsertMailBounced = True
End With
Exit Function
errMailBounced:
LogError Err.Number, "InsertMailBounced", Err.Description
End Function
Public Function GetMailId(ByVal Name As String) As String
Dim SQL As String
Dim rs As Recordset
On Error GoTo errMailId
SQL = "Select MailId from MailAliases where Name = '" & Name & "'"
Set rs = New Recordset
rs.Open SQL, cn, adOpenForwardOnly, adLockReadOnly
With rs
If Not .EOF Then
GetMailId = !MailId
Else
GetMailId = ""
End If
.Close
End With
Exit Function
errMailId:
LogError Err.Number, "GetMailId", Err.Description
End Function
Public Function GetUmId(ByVal UsrName As String) As Long
Dim SQL As String
Dim rs As Recordset
On Error GoTo errUmid
SQL = "Select UmId from UsrList where UsrName = '" & UsrName & "'"
Set rs = New Recordset
rs.Open SQL, cn, adOpenForwardOnly, adLockReadOnly
With rs
If Not .EOF Then
GetUmId = !UMId
Else
GetUmId = -1
End If
.Close
End With
Exit Function
errUmid:
LogError Err.Number, "GetUmId", Err.Description
End Function
Public Function GetMailReplyAddr(ByVal SenderId As Long, ByVal UMId As Long)
As String
Dim SQL As String
Dim rs As Recordset
On Error GoTo errMailReplyAddr
SQL = "Select ReplyAddr from MailReplyAddr where SenderId = " & SenderId
& " and UMId = " & UMId
Set rs = New Recordset
rs.Open SQL, cn, adOpenForwardOnly, adLockReadOnly
With rs
If Not .EOF Then
GetMailReplyAddr = !ReplyAddr
Else
GetMailReplyAddr = ""
End If
.Close
End With
Exit Function
errMailReplyAddr:
LogError Err.Number, "GetMailReplyAddr", Err.Description
End Function
Private Sub Class_Initialize()
'
End Sub
Private Sub Class_Terminate()
cn.Close
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|