Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2026-05

Stuck in TMSSQLConnection.Execute

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Luca Olivetti

Hello,

I encountered a strange problem in an application, that's been running for over a year now.
The application is quite convoluted with hundred of threads, one (actually more than one) of those threads connects to an ms sql server and now it blocks inside TMSSQLConnection.Execute, but not always

procedure TMSSQLConnection.Execute(const cmd: string);
begin
   DBErrorStr:='';
   DBMsgStr  :='';
   CheckError( dbcmd(FDBProc, PAnsiChar(cmd)) );
   CheckError( dbsqlexec(FDBProc) );  <--- this doesn't return
   CheckError( dbresults(FDBProc) );
end;

However when I terminate the application and before the destroy method of the thread is called, dbsqlexec returns and the rest of the thread goes on as nothing happened.

As an experiment I wrapped the method in synchronize but that only freezes the gui when it happens.

I don't know it if is relevant but I have a note in my program that I have to initialize the sql server libraries in the main thread, otherwise doing it in another thread eventually causes a sigsev.

I got the dlls (almost 2 years ago) following the instructions here

https://forum.lazarus.freepascal.org/index.php/topic,55037.msg409167.html#msg409167

using Environment: PLAT=Win32, WIDTH=32, VS_VERSION=2017, TDSVER=7.3 (though older artifacts are deleted after a month)

This is on windows 32 bits, fpc 3.2.2, any hint on how to debug it further?

Bye

Luca
michael
to Luca Olivetti

Are you using 1 connection per thread ? If not, then that may be your problem.

Michael.

Luca Olivetti wrote 41 lines
Hello, I encountered a strange problem in an application, that's been running for over a year now. The application is quite convoluted with hundred of threads, one (actually more than one) of those threads connects to an ms sql server and now it blocks inside TMSSQLConnection.Execute, but not always procedure TMSSQLConnection.Execute(const cmd: string); begin DBErrorStr:=''; DBMsgStr :=''; CheckError( dbcmd(FDBProc, PAnsiChar(cmd)) ); CheckError( dbsqlexec(FDBProc) ); <--- this doesn't return CheckError( dbresults(FDBProc) ); end; However when I terminate the application and before the destroy method of the thread is called, dbsqlexec returns and the rest of the thread goes on as nothing happened. As an experiment I wrapped the method in synchronize but that only freezes the gui when it happens. I don't know it if is relevant but I have a note in my program that I have to initialize the sql server libraries in the main thread, otherwise doing it in another thread eventually causes a sigsev. I got the dlls (almost 2 years ago) following the instructions here https://forum.lazarus.freepascal.org/index.php/topic,55037.msg409167.html#msg409167 using Environment: PLAT=Win32, WIDTH=32, VS_VERSION=2017, TDSVER=7.3 (though older artifacts are deleted after a month) This is on windows 32 bits, fpc 3.2.2, any hint on how to debug it further? Bye
Luca Olivetti
to Luca Olivetti: I encountered a strange problem in an application, that's been running for over a year…

El 6/5/26 a les 10:55, Luca Olivetti via fpc-pascal ha escrit:

As always I found the problem right after hitting "send": another thread started a transaction which blocks this one.
I still don't understand why (this is a select that it shouldn't be affected by the other transaction)

Bye

Show quoted text 41 lines
Hello, I encountered a strange problem in an application, that's been running for over a year now. The application is quite convoluted with hundred of threads, one (actually more than one) of those threads connects to an ms sql server and now it blocks inside TMSSQLConnection.Execute, but not always procedure TMSSQLConnection.Execute(const cmd: string); begin   DBErrorStr:='';   DBMsgStr  :='';   CheckError( dbcmd(FDBProc, PAnsiChar(cmd)) );   CheckError( dbsqlexec(FDBProc) );  <--- this doesn't return   CheckError( dbresults(FDBProc) ); end; However when I terminate the application and before the destroy method of the thread is called, dbsqlexec returns and the rest of the thread goes on as nothing happened. As an experiment I wrapped the method in synchronize but that only freezes the gui when it happens. I don't know it if is relevant but I have a note in my program that I have to initialize the sql server libraries in the main thread, otherwise doing it in another thread eventually causes a sigsev. I got the dlls (almost 2 years ago) following the instructions here https://forum.lazarus.freepascal.org/index.php/ topic,55037.msg409167.html#msg409167 using Environment: PLAT=Win32, WIDTH=32, VS_VERSION=2017, TDSVER=7.3 (though older artifacts are deleted after a month) This is on windows 32 bits, fpc 3.2.2, any hint on how to debug it further? Bye
Luca Olivetti
to michael: Are you using 1 connection per thread ? If not, then that may be your problem. Michael.

El 6/5/26 a les 12:02, michael via fpc-pascal ha escrit:

Thank you, no, that's not the problem (each thread uses its own connection), see my other reply.

Bye

Show quoted text 52 lines
Are you using 1 connection per thread ? If not, then that may be your problem. Michael. On 2026-05-06 10:55, Luca Olivetti via fpc-pascal wrote: > Hello, > > I encountered a strange problem in an application, that's been running > for over a year now. > The application is quite convoluted with hundred of threads, one > (actually more than one) of those threads connects to an ms sql server > and now it blocks inside TMSSQLConnection.Execute, but not always > > > procedure TMSSQLConnection.Execute(const cmd: string); > begin >   DBErrorStr:=''; >   DBMsgStr  :=''; >   CheckError( dbcmd(FDBProc, PAnsiChar(cmd)) ); >   CheckError( dbsqlexec(FDBProc) );  <--- this doesn't return >   CheckError( dbresults(FDBProc) ); > end; > > > However when I terminate the application and before the destroy method > of the thread is called, dbsqlexec returns and the rest of the thread > goes on as nothing happened. > > As an experiment I wrapped the method in synchronize but that only > freezes the gui when it happens. > > I don't know it if is relevant but I have a note in my program that I > have to initialize the sql server libraries in the main thread, > otherwise doing it in another thread eventually causes a sigsev. > > I got the dlls (almost 2 years ago) following the instructions here > > https://forum.lazarus.freepascal.org/index.php/ > topic,55037.msg409167.html#msg409167 > > using Environment: PLAT=Win32, WIDTH=32, VS_VERSION=2017, TDSVER=7.3 > (though older artifacts are deleted after a month) > > This is on windows 32 bits, fpc 3.2.2, any hint on how to debug it > further? > > Bye _______________________________________________ fpc-pascal maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Luca Olivetti
to Luca Olivetti: El 6/5/26 a les 10:55, Luca Olivetti via fpc-pascal ha escrit: As always I found the…

El 6/5/26 a les 12:02, Luca Olivetti via fpc-pascal ha escrit:

Since I don't manage the ms sql server, don't know what it does in its stored procedures and views and don't want to learn the intricacies of its transaction management, I just added a TCriticalSection so that only one connection can start a transaction (they should complete quite fast anyway).
Maybe there's a way to achieve the same with some special parameter in the transaction/connection but the global TCriticalSection works.

Bye

Show quoted text 55 lines
El 6/5/26 a les 10:55, Luca Olivetti via fpc-pascal ha escrit: As always I found the problem right after hitting "send": another thread started a transaction which blocks this one. I still don't understand why (this is a select that it shouldn't be affected by the other transaction) Bye > Hello, > > I encountered a strange problem in an application, that's been running > for over a year now. > The application is quite convoluted with hundred of threads, one > (actually more than one) of those threads connects to an ms sql server > and now it blocks inside TMSSQLConnection.Execute, but not always > > > procedure TMSSQLConnection.Execute(const cmd: string); > begin >    DBErrorStr:=''; >    DBMsgStr  :=''; >    CheckError( dbcmd(FDBProc, PAnsiChar(cmd)) ); >    CheckError( dbsqlexec(FDBProc) );  <--- this doesn't return >    CheckError( dbresults(FDBProc) ); > end; > > > However when I terminate the application and before the destroy method > of the thread is called, dbsqlexec returns and the rest of the thread > goes on as nothing happened. > > As an experiment I wrapped the method in synchronize but that only > freezes the gui when it happens. > > I don't know it if is relevant but I have a note in my program that I > have to initialize the sql server libraries in the main thread, > otherwise doing it in another thread eventually causes a sigsev. > > I got the dlls (almost 2 years ago) following the instructions here > > https://forum.lazarus.freepascal.org/index.php/ > topic,55037.msg409167.html#msg409167 > > using Environment: PLAT=Win32, WIDTH=32, VS_VERSION=2017, TDSVER=7.3 > (though older artifacts are deleted after a month) > > This is on windows 32 bits, fpc 3.2.2, any hint on how to debug it > further? > > Bye _______________________________________________ fpc-pascal maillist  -  https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal