It all depends on how you really fulfill your requests;
Submit the following request:
SqlConnection myConnection = new SqlConnection("connection_string"); SqlCommand myCommand = new SqlCommand(); myCommand.Connection = myConnection; myCommand.CommandType = CommandType.StoredProcedure; myCommand.CommandTimeout = some_long_time; myCommand.CommandText = "database_killing_procedure_lol"; myConnection.Open()
Two things will happen; one is that this method will queue until the command completes. ExecuteNonQuery (). Secondly, we will also link the connection from the connection pool throughout the method.
What happens if we cross? Well, an exception is thrown - an SqlException exception with the property Number = -2. However, remember that in the above code there is no exception management, so all that happens is objects that go out of scope, and we will need to wait for them to be deleted. In particular, our connection will not be reused until this happens.
This is one of the reasons why the following pattern is preferred:
using(SqlConnection myConnection = new SqlConnection("connection_string")) { using(SqlCommand myCommand = new SqlCommand()) { SqlCommand myCommand = new SqlCommand(); myCommand.Connection = myConnection; myCommand.CommandType = CommandType.StoredProcedure; myCommand.CommandTimeout = some_long_time; myCommand.CommandText = "database_killing_procedure_lol"; myConnection.Open()
This means that as soon as the request is completed, either naturally (it will be completed) or through an exception (timeout or otherwise), the resources will be immediately returned.
In your particular problem, having a large number of queries that take a long time to complete is bad for many reasons. In a web application, you have potentially many users fighting for a limited amount of resources; memory, database connections, processor time, etc. Therefore, linking any of them to expensive operations will reduce the responsiveness and performance of your web application or limit the number of users that you can serve at the same time. If the database is expensive, you can also associate your database with a further restriction on usage.
It is always worth trying to give the runtime of database queries only for this reason. If you cannot, then you will have to be careful how many of these types of queries you can run at the same time.
EDIT:
So, you are really interested in what is happening on the SQL Server side ... the answer ... it depends! CommandTimeout is actually a client event - you say that if the request takes more than n seconds, then I no longer want to wait. SQL Server receives a message that it is, but it still needs to deal with what it is doing now, so it may actually take some time before SQL Server completes the query. He will try to prioritize, but more on that.
This is especially true for transactions; if you are executing a query enclosed in a transaction and you are rolling back this as part of exception management, then you need to wait until the rollback is complete.
It also very often happens that people panic and start issuing KILL commands against the identifier of the SQL process the query is working with. This is often an error if the team is executing a transaction, but is often suitable for lengthy selections.
SQL Server must manage it so that it remains consistent. The fact that the client is no longer listening means that you have wasted your work, but SQL Server still needs to be cleaned up after itself.
So, the ASP.Net side will be all right, as itβs all the same, but SQL Server still needs to finish the job or reach the point where it can refuse this work, or roll back any changes in any transactions that were are open.
This can obviously affect database server performance depending on the query!
Even a long run of SELECT or UPDATE or INSERT outside the transaction should complete. SQL Server will try to abandon it as soon as possible, but only if it is safe. Obviously, for UPDATES and INSERT in particular, it must reach the point at which the database remains unchanged. For SELECT, he will try to finish as soon as he can.