BDE, Delphi, ODBC, SQL Native Client & Dead lock

We have Delphi code that uses BDE to access SQL Server 2008 using the SQL Server Native Client ODBC driver (2005 version). Our problem is that we encounter some deadlock issues in the loop that make inserts for multiple tables.

The entire loop is executed in [TDatabase] .StartTransaction. Looking at the SQL Server profiler, we clearly see that at one point during the cycle, the SPID (Session ID?) Changes, and then we naturally end up in a dead end. (Both SPIDs insert into the same table)

It seems that BDE at some point makes a second connection to the database ...

(Although I would like to skip BDE, this is currently not possible).

Does anyone have experience sharing?

+3
source share
3 answers

If your application is multithreaded: BDE is not thread safe. You must use a separate BDE session (explicitly created instance TSession) for each thread; global Session, created automatically for the main thread, is insufficient. In addition, all database access components ( TDatabase, TQueryetc.) can only be used in the context of the stream where their corresponding instance was created TSession.

+1
source

ODBC, SQL Server . , ... ( , , ).

+1

, , , , .

, , , BDE/ODBC . " ", , .

, BDE, . , (TTable.Close, TTable.Last...).

" " , , .

:

  • During the lockout, perform the following statement (for example, using Studio Management): EXEC sp_who2.
  • Look in the column BlkBy. A blocked connection has a number.
  • This number is a spid(server identifier) ​​blocking connection.
  • Then you do DBCC INPUTBUFFER(spid).
  • In the column, EventInfoyou will find the SQL statement that was issued by your program.
  • With this information, you can find the BDE component that causes the problems.
0
source

Source: https://habr.com/ru/post/1738303/


All Articles