Command time out Error in Delphi ADO - delphi

I am executing a storedprocedure in Oracle With ADOStoredProcedure in Delphi 2010. The procedure execution time is 2 minutes.I set Command timeout to 20 Seconds.
When I am Executing the procedure ,Error is not raising related to timeout & procedure is executing for 2 minutes. How to get error at 20th Second
I used Connection string
'Provider=MSDAORA.1;Password=pthmu;User ID=pthmu;Data Source=orcl_300'

The behaviour of ADO.CommandTimeout is depending on provider and data source as stated in the documentation
Use the CommandTimeout property on a Connection object or Command
object to allow the cancellation of an Execute method call, due to
delays from network traffic or heavy server use. If the interval set
in the CommandTimeout property elapses before the command completes
execution, an error occurs and ADO cancels the command. If you set the
property to zero, ADO will wait indefinitely until the execution is
complete. Make sure the provider and data source to which you are
writing code support the CommandTimeout functionality.
UPDATE
Connection Timeout and Query Timeout Not Supported with Microsoft Oracle ODBC Driver and OLE DB Provider
After the query has been sent to the Oracle server, there is no way to cancel the query by using the Oracle OCI. In the case of the preceding connection timeout, you are canceling the request for the connection before it has been completed.

Related

Cleaning up running FireDAC TTasks when closing application

I have a program (in Delphi 10.3) that allows the user to configure FireDAC database access at run time using the standard dialog as provided by the libraries (as listed in FireDAC help)
TfrmFDGUIxFormsConnEdit.Execute(DBConnection, '')
If the user exits shortly after doing this the program crashes with exceptions in TFDPhysMSSQLDriver.GetServers. This is because that function launches a TTask to browse all the available MSSQL servers which takes quite sometime to complete and generates protection errors as soon as it tries to process any "progress" it has made after the rest of the application has shutdown. Since this occurs in the FireDAC library I can't access the ITask handle for the task to wait for it and there doesn't seem to be any obvious way to wait for all outstanding TTasks to complete.
Does anyone know the approved method for either waiting for this task or all tasks to finish or what else I can do to "make safe" before exiting?

With Delphi and Indy 10.6 how do I keep the TIdTCPServer from dropping a client on read timeout

I've noticed that, when my TCPServer is set for 30 sec read timeout, even though I am handling the EIdReadTimeout in the ServerExecute, and Raise it again there, then handle it in ServerException and show the timeout message there, it still drops that specific client without me telling it to. On the Client side I handle the EIdReadTimeout and it doesn't drop the server connection.
I want the Server side to do the same thing so I can set the Server timeout at 30 sec and the client at 45 sec so the server can send a timeout message to the Client for a retry and not abort the connection entirely.

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

We have some Delphi code that uses the BDE to Access SQL Server 2008 through the SQL Server Native Client ODBC driver (2005 version). Our issue is that we're experiencing some deadlock issues in a loop doing inserts to multiple tables.
The whole loop is done within a [TDatabase].StartTransaction. Looking at the SQL Server Profiler we clearly see that at one point during the loop the SPID (Session ID?) change, and then we naturally end up with a deadlock. (Both SPID doing inserts to the same table)
It seems like the BDE at some point does a second connection to the DB...
(Although I would love to skip the BDE, it's currently not possible. )
Anyone with experiences to share?
In case your app is multithreaded: BDE is not threadsafe. You have to use a separate BDE session (explicitly created instance of TSession) for each thread; the global Session created automatically for the main thread is not sufficient. Also, all database access components (TDatabase, TQuery, etc.) can only be used in the context of the thread where their corresponding instance of TSession has been created.
Verify in the ODBC installation if SQL Server driver is configured to do connection pooling.
Appear that Native Client installation activates it for default... (At least, mine installation had connection pooling active and I don't activated it).
This probably comes too late for the asker, but maybe it helps others.
Everytime there is a cursor that doesn't get closed, the BDE/ODBC combo will establish a new connection for successive querys. The "spid change" is probably the result of a non-closed cursor.
To solve this problem you have to find the BDE-component that caused this stil-opened cursor. Then you call a method that will eventually close the cursor (TTable.Close, TTable.Last ...).
After that the "spid change" should be gone and therefore the deadlock.
Some tips to find that component:
During the lock, execute the following statement (for example using Management Studio):
EXEC sp_who2.
Look in column BlkBy. The blocked connection has a number in it.
This number is the spid (Server Process ID) of the blocking connection.
Then you execute DBCC INPUTBUFFER(spid).
In column EventInfo you will find the sql-statement that has been issued by your programm.
With that information you should be able to find the BDE-component that causes your trouble.

SQL Server Management Studio edit timeout

I am trying to run a query to edit records in SQL Server Management Studio 2008 and keep getting the error:
"SQL Execution Error.
Error Message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding."
I have set the following:
Execution Time-out: 0
Set Lock Timeout: -1
Transaction time-out after: 65535
The message appears at about 30 seconds....
There are locks on the database you are trying to change. You need to first remove the locks, then you can execute your change.

Why am I getting a sqlcommand timeout in the application?

I am getting sqlcommand timeout issues when I debug the application even though the stored procedure runs in less than 25 seconds in management studio. I set the timeout attribute to 180 seconds and still get the error. Any suggestions?
Where did you set the timeout attribute at? I used to run into the same issue when I was setting the timeout in the SqlConnection string, but it turns out I also needed it in the SqlCommand itself.
25 seconds is a long time for a stored proc to be running. I'd suggest optimizing the query further.
Are you setting "Connect Timeout" or "Command Timeout" in connection string? It's easy to do mistakes with them.
--EDIT
Try searching in your code if your system isn't locking a table used in the SP.
It won't solve the problem, but logging the start/end of the procedure (on database side, by putting the SP inside another SP) can tell you if the problem is before starting the SP (because of network, webserver load, etc) or while executing it.
I hope it helps
Try running a sp_recompile against that stored procedure, then try from your application again.

Resources