My understanding is 2 select statements will not cause deadlock to each other.
Recently, I got an error in my code. It happened maybe once or twice a week. I got a deadlock error when my code tries to query a view. The table is maintained by a third party application. We are not allowed to modify it. We just query the data via a view created from that table.
My understanding is even I have multiple threads querying this view. It won't cause the deadlock. I am sure that the rows I am querying will never be updated. So the deadlocks here can only be caused by multiple select statements?
If so, is there a way to overcome this issue?
I have read the post Transaction deadlock for select query.
I am using sql server 2008. There is no extended events in 2008. There is no solutions for this issue in that post? Does anyone know how to solve this issue?
Thank you.
Related
I'm looking for a method or solution to allow for a table to be updated that others are running select queries on?
We have an MS SQL Database storing tables which are linked through ODBC to an Access Database front-end.
We're trying to have a query run an update on one of these linked tables but often it is interrupted by users running select statements on the table to look at data though forms inside access.
Is there a way to maybe create a copy of this database table for the users to look at so that the table can still be updated?
I was thinking maybe a transaction but can you perform transactions for select statements? Do they work that way?
The error we get from inside access when we try to run the update while a user has the table open is:
Any help is much appreciated,
Cheers
As a general rule, this should not be occurring. Those reports should not lock nor prevent the sql system from not allowing inserts.
For a quick fix, you can (should) link the reports to some sql server views for their source. And use this for the view:
SELECT * from tblHotels WITH (NOLOCK)
In fact in MOST cases this locking occurs due to combo boxes being driven by a larger table in from SQL server - if the query does not complete (and access has the nasty ability to STOP the flow of data, then you get a sql server table lock).
You also can see the above "holding" of a lock when you launch a form with a LARGE dataset If access does not finish pulling the table/query from SQL server - again a holding lock on the table can remain.
However, I as a general rule NOT seen this occur for reports.
However, it not all clear how the reports are being used and how their data sources are setup.
But, as noted, the quick fix is to create some views for the reports, and use the no-lock hint as per above. That will prevent the tables from holding locks.
Another HUGE idea? For the reports, if they often use some date range or other critera? MAKE 100% sure that sql server has index on the filter or critera. If you don't, then SQL server will scan/lock the whole table. This advice ALSO applies VERY much to say a form in which you filter - put indexing (sql server side) on those common used columns.
And in fact, the notes about the combo box above? We found that JUST adding a indexing to the sort column used in the combo box made most if not all locking issues go away.
Another fix that often works - and requires ZERO changes to the ms-access client side software?
You can change this on the server:
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
The above also will in most cases fix the locking issue.
Two processes are running simultaneously on a table. One is updating the records. The other is reading the data. While updating it is locking the table.so I am unable to read the data. Help to to handle the same.
Thanks,
Bibhu
I am assuming you are using SQL Server. You can use the WITH NOLOCK hint in your select statement, so the read goes through. However, you should be aware that it is a dirty read. Since the update statement is changing the data and the changes may or may not have been committed, the result of the read (select) statement can be problematic.
Here is a link to a page with more details and simple examples
https://www.mssqltips.com/sqlservertip/2470/understanding-the-sql-server-nolock-hint/
I'm using SQL server 2012 and have got a db already created in which I have four main tables which are linked through a view that triggers one trigger and leads from one table to another. Trigers work to move the needed info from one table to another.
As you may imagine, the main issue has to do with the amount of triggers that db generates and in the end, there is a pop-up window which shows a time-out warning related to the db. What could be the solution for this?
I've thought of creating a block which contains a cursor and within it, another cursor instead of creating a loop of triggers. How could I do that about cursors in the db, what's the correct sintax?
Is there any idea better than that one? I havent tried that one as I dont know how to do so and maybe I continue having the same issue related to "time-out" but I do not have any other idea and wanted to give it a try.
To prevent locks and deadlocks I have decided to use table hints WITH(NOLOCK) within my views.
That had a good effect and the users were happy with it.
The problem started when those views were called from inside an application (A CRM application called PIVOTAL).
When this application queries my views (that have WITH(NOLOCK) inside them) it adds a different table lock READCOMMITTED.
For example:
select * from MY_view WITH(READCOMMITTED)
The result of this is a SQL Server error message telling me about the conflicting locks.
Now, I cannot change the application and the way it generates its scripts.
Is there a way I could make SQL Server ignore the hint outside of My_view?
Is there a way to make the NOLOCK prevail over READCOMMITTED, so that I can keep it within My_View?
Thanks and regards.
Marcello
I don't think there is an easy solution here. SQL Server cannot take conflicting locks as it doesn't know which locks to apply to the underlying tables.
Can you create a separate set of views for the application reading with READCOMMITTED?
We have been having problems with ghost updates in our DB (SQL Server 2005). Fields are changing, and we cannot find the routine that is performing the update.
Is there any way, (perhaps using an update trigger ?) to determine what caused the update? The SQL statement, process, username/login,etc?
Use SQL Server Profiler
You'll probably want to filter away the things you don't need so it might take a while to get it setup.
At least it'll get you to the procedure / query that is responsible as well as user / computer for the alterations, which leaves finding that in your code.
I found and article that might help you out over here:
http://aspadvice.com/blogs/andrewmooney/archive/2007/08/20/SQL-Server-2005-Audit-Log-Using-Triggers.aspx
All the information that you are asking for is available at the time the update is performed. The SQL Profiler will certainly work, but it is a bit of work to craft a filter that does not overwhelm you with data, particularly if you need to run it for days or weeks at a time. An update trigger is easy enough the create, and you can log the information that you need in a new table.
I would probably use AutoAudit to generate triggers on the table first.
It's somewhat limited in terms of knowing exactly what is changing your data, but it's a start.
You could always look at the triggers and modify them to only log certain columns you are interested in and perhaps get more information which it doesn't currently log.