I use TUniConnection and TUniQuery components in subthread. I need to terminate the thread as soon as possible when the user closes the program.
However, in some cases, it would be more time-consuming on database operations. For example, connect to DB Server or execute SQL. The thread will be blocked in these methods if those methods take more time-consuming. Is there any way we can quickly cancel or terminate those operations?
How to cancel the db access operation?
-
AndreyZ
Hello,
Depending on the database server you are using, you can set the ConnectionTimeout option to decrease the time for connection establishment in the following way:You will find more information about server-specific options in the "Provider-Specific Notes" section of the UniDAC documentation.
You can break query execution by calling the TUniQuery.BreakExec method. You should call this method from another thread. For more information, please refer to the UniDAC documentation.
Depending on the database server you are using, you can set the ConnectionTimeout option to decrease the time for connection establishment in the following way:
Code: Select all
UniConnection.SpecificOptions.Values['ConnectionTimeout'] := '5';You can break query execution by calling the TUniQuery.BreakExec method. You should call this method from another thread. For more information, please refer to the UniDAC documentation.
AndreyZ,
I do a test, use TUniConnection connect to a non-existent database:
In line 8, "st" equal to 56364 ms, more bigger than 5000 ms.
I do a test, use TUniConnection connect to a non-existent database:
Code: Select all
FConnection.SpecificOptions.Values['ConnectionTimeout'] := '5';
FConnection.SpecificOptions.Values['SQL Server.ConnectionTimeout'] := '5';
st := GetTickCount;
try
FConnection.Connect;
st := GetTickCount - st;
except
st := GetTickCount - st; // Line 8
end;-
AndreyZ
This behaviour is connected with the specificity of the OLEDB provider work. OLEDB tries to find the specified server and it takes much time if it doesn't exist. You can check this OLEDB behaviour with ADO components and Microsoft SQL Server Management Studio. We cannot influence OLEDB provider work.