we have a few long running procedures in the database, that cause an instant Table Lock on our main text storage table, which causes all other requests of the web app to wait (because the table is used in nearly every request).
- Web Application with ASP.NET, Entity Framework, SQL Server 2008R2
- A lot of Tables (Table per Class Strategie) with data attributes
- ONE Table ("dbo.Translations") for dynamic defined texts (to enable translations).
- No foreign keys to this table
To get the text of the object in the right language, the Object ID is saved to the translation table with the text value
So the Translation Table looks like:
dbo.Translations (ID varchar(36), type varchar(10), lang varchar(5), value varchar(max))
whereas Type is defined for each object and lang is like 'en-GB' (not relevant).
The table has two indexes: PK_Translations on ID (Clustered, not unique) UNQ_Translations on all columns (nonclustered, unique)
The table has to handle two operations: SELECTS and INSERTS.
Update and delete is not a common use-case.
The table holds nearly 1.000.000 rows and an index over ID,type,lang.
When the web application wants to insert (multiple) records, the operation takes a lot of time and creates an instant table lock. This stops every other request to this table (maybe even to other tables, so sometimes it seems to be a database lock?!) and causes them to wait.
The INSERTS of large data is done in the following way:
INSERT INTO Translations (Id, Typ, lang, value) SELECT td.nId, td.Typ, td.lang, td.value FROM #tempDictionary td
Note: #tempDictionairy is a temporary table
The following steps where tested and did not improve the situation:
- Start the SELECT transaction with read uncommitted -> no change
- Extend the index sparsity to 50% to ensure that the inserted records can be saved easily -> no change
How can I find out why the SQL Server creates an table / db lock?