how do i set a lock wait timeout in sql server?
Is there anyway that I can specify maybe through JDBC
or a configuration script that I can use?
I want to make sure that my statements will only wait specific time on accessing a row with a lock
Thanks
You can either issue a TSQL SET LOCK_TIMEOUT nnnn statement or set it in the connection string using the lockTimeout property.
Related
I want to set Timeout value for a specific sql query which will execute inside a stored procedure.
Is it possible to set the timeout value for a particular query?
It is the client API rather than SQL Server that enforces query timeouts (RPC or batch). Consequently, you can't set a client command timeout at a more granular level when a stored procedure contains multiple statements. You'll need to split the proc such that the desired query is executed separately by the client, and specify a different timeout for that command.
The specifics of how to set the timeout vary depending on the client API. In the case of .NET, it is the SqlCommand.CommandTimeout property.
I'm using an application which has the ability to create a backup from an sql server, but the size of it creates an error:
Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
The backup or restore was aborted.
What I am wondering is if I am able to change the time out time from Management Studio without altering the application.
And if there is no other way but to change the connecion string to the database, does adding a simple ;Connection Timeout=30 to the string solves this problem? The application is written in C#.
What I am wondering is if I am able to change the time out time from Management Studio without altering the application.
Yes, you can change the timeout in Management Studio. See this article.
does adding a simple ;Connection Timeout=30 to the string solves this problem?
No, that is the timeout when you connect to your SQL Server, not the query execution timeout.
So, it seems that it is not possible to set the timeout for each single step in a SQL Server job (article from StackExchange).
MSDN points out that you can of course set the Agent timeout:
Sql Server Agent properties.
Set Job execution shutdown.
Questions
How does Agent time-out work?
Is there any other way (preferably by configuration) to setup the single step timeout?
Is there any other way (preferably by configuration) to setup the whole job timeout?
To answer question 2, I'm not sure if this is the best option but you could use OPENROWSET to control a single step timeout.
http://msdn.microsoft.com/en-us/library/ms190312.aspx
Just because OPENROWSET is normally used to access remote servers doesn't mean it has to be.
Probably this is similar to how agent timeout works.
You could even use this to control the whole job timeout although if you want to do it by configuration you'd have to create your own tables.
I'm not sure this is the best solution but it's a solution at least.
I'm using SQL 2000 for my application. My application is using N tables.
My application has a wrapper for SQL server called Database server. It is running as a 24/7 windows service.
If I have checked the integrity check option in the SQL maintenance plan, when this task is running one time after that one of my tables has been locked and it has been never unlocked.
So my history of the database transaction has been lost.
Please provide your suggestion how to solve this problem.
What if you have a client-side command timeout? And the locks are your own locks as a result of the DBCC?
Your code will timeout waiting for the DBCC to finish, but any locks it's already issued are not rolled back.
A command timeout tells SQL Server to simply stop processing. To release locks you need to either ROLLACK on the connection or close the connection.
Options:
Use SET XACT_ABORT in the SQL: Do I really need to use “SET XACT_ABORT ON”? (SO)
On client error, try and rollback yourself (Literally IF ##TRANCOUNT > 0 ROLLBACK TRAN)
In a scripting step in a scheduled task in SQL Server Agent 2005, I need to trigger a webscript that is running on a different server. I'm doing this:
Dim ie
Set ie = CreateObject( "InternetExplorer.Application" )
ie.navigate "...to my dreamscript"
' Wait till IE is ready
Do While ie.Busy
(1)
Loop
ie.Quit
set ie = Nothing
At (1) I would like to "sleep" (e.g. WScript.sleep(..)), but WScript is not available in this environment. Is there another way to "sleep" for a while?
If you're only trying to have the SQL SErver Agent task that waits for a time period use a T-SQL Task with the script
WAITFOR DELAY '01:00:00' -- wait for an hour
and change the time to the duration that you'd like to wait.
HTH
Andy
You can write a console applicaton and execute the console app in SQL agent job.
You could execute the wscript by using a SQL Server Agent task with a type of "Operpating System (CmdExec)". This requires that xp_cmdshell be enabled and it is often disabled (by default) due to security concerns. However, it does allow you to initiate programs, such as wscript, that are run at the command prompt.
You could move the code into SQLCLR where you can write a stored procedure in C# or VB.Net. The VB.Net SQLCLR Code would be pretty similar to your original wscript.