Hi,
We have a Vb.net program and we are using SqlCommand to execute some queries.This is the code block
But while executing delete statement some this timeout error comingCode:If Trim(Slno) <> "" Then oCmd_Local = New SqlCommand("select * from ErrorReport_analysis where (sl_no = '" & Slno & "' and Product = '" & ProductStr & "') order by id", Connum_Local) rs_local = oCmd_Local.ExecuteReader If rs_local.Read = True Then If Trim(Hostname) <> "" Then oCmd_Local = New SqlCommand("select count(*) from ErrorReport_analysis where (sl_no = '" & Slno & "' and Product = '" & ProductStr & "' and HOSTNAME = '" & Hostname & "')", Connum_Local2) rs_local2 = Val(oCmd_Local.ExecuteScalar.ToString) ElseIf Trim(CompKey) <> "" Then oCmd_Local = New SqlCommand("select count(*) from ErrorReport_analysis where (sl_no = '" & Slno & "' and Product = '" & ProductStr & "' and PC_key like '%-" & CompKey & "-%')", Connum_Local2) rs_local2 = Val(oCmd_Local.ExecuteScalar.ToString) End If If rs_local2 = 1 Then 'if only one row present then delete that row itself oCmd_Local = New SqlCommand("Delete from ErrorReport_analysis where (id = " & rs_local.Item("id").ToString & ")", Connum_Local2) oCmd_Local.CommandTimeout = TimeOutval oCmd_Local.ExecuteNonQuery() Else Do While rs_local.Read = True If Trim(Hostname) <> "" Then If rs_local.Item("HOSTNAME").ToString = Hostname Then oCmd_Local = New SqlCommand("Delete from ErrorReport_analysis where (id = " & rs_local.Item("id").ToString & ")", Connum_Local2) oCmd_Local.CommandTimeout = TimeOutval oCmd_Local.ExecuteNonQuery() Exit Do End If ElseIf Trim(CompKey) <> "" Then If InStr(rs_local.Item("PC_key").ToString, "'%-" & CompKey & "-%'", CompareMethod.Text) > 0 Then oCmd_Local = New SqlCommand("Delete from ErrorReport_analysis where (id = " & rs_local.Item("id").ToString & ")", Connum_Local2) oCmd_Local.CommandTimeout = TimeOutval oCmd_Local.ExecuteNonQuery() Exit Do End If Else Exit Do End If Loop End If End If rs_local.Close() rs_local = Nothing Else oCmd_Local = New SqlCommand("select * from ErrorReport_analysis where ((sl_no ='' or sl_no is null) and PC_key like '%-" & CompKey & "-%' and HOSTNAME = '" & Hostname & "' and Product = '" & ProductStr & "') order by id", Connum_Local) rs_local = oCmd_Local.ExecuteReader If rs_local.Read = True Then oCmd_Local = New SqlCommand("Delete from ErrorReport_analysis where (id = " & rs_local.Item("id").ToString & ")", Connum_Local2) oCmd_Local.CommandTimeout = TimeOutval oCmd_Local.ExecuteNonQuery() End If rs_local.Close() rs_local = Nothing End If End If
I have Executed sp_who2 command in Management studio and find out that there are 4 sessions created by program and a session with select statement is blocking the session with delete statement.Why this is happening?what to do?
Thank you




Reply With Quote
