Hi guys.Here's the scenario: aspnet application, about 300 web requests per second, each request generates 10 to 20 sql server requests. In my vb6 times it was very easy to generate DEADLOCK error with even 3 users with this code: sqlstr = "SELECT Parameter1 FROM Companies WHERE ID = " & CompanyID rst.Open sqlstr, cnGlobal, adOpenForwardOnly, adLockOptimistic If Not (rst.BOF And rst.EOF) Then Parameter1 = "" & rst("Parameter1") End If rst.Close Set rst = Nothingin 2 or 3 minutes I could get deadlock error. I solved problem by using adLockReadOnly. I had no problem since years. But ado.net does not have this featıure, well it does but implementing this feature is not good for me at the moment. and its irrelevant with this question.Instead of changing code I tried to use:sqlstr = "SELECT Parameter1 FROM Companies WITH (NOLOCK) WHERE ID = " & CompanyID Using cn As New SqlConnection(DBClass.ConnectionString_) cn.Open() Using cmd As New SqlCommand(sqlstr, cn), rst As SqlDataReader = cmd.ExecuteReader If rst.Read Then Return "" & rst("Parameter1") End If End Using End Usingand Error is gone. Then I read about DEADLOCKs and organized indexes well and there's no DEADLOCK even I use sql sentence without WITH (NOLOCK).but question remains in my mind:Is it safe to use WITH (NOLOCK) if I only read something like "parameter". it will never change, maybe one or two times in a year. In this scenario can I use WITH (NOLOCK) without any doubts ? I know WITH (NOLOCK) can produce dirty resucts but in my case this value won't change often.Also I read something like WITH (NOLOCK) can cause log files corruption. is that true ?I also developed a routine that tries to read this value and if it encounters DEADLOCK error retries it. Do you use something like that in your applications ?I'm very surprise that there are lots of dirty information about surprise on the web. everybody says something different.Can anyone with DEADLOCK experience enlighten me? do you have any experience reading [b]parameter [/b] with WITH (NOLOCK) ? Does it cause any problems in the feature. Now I test my system with my multithreaded application which generates couple of hundreds of test requests per second to web application but I have concerns about real life.best.
↧