Best way to track SQL Server stored procedure timeout exceptions in SQL Server (error logs table) itself? - sql-server-2012

I want to track all the SQL Server stored procedure timeout errors or any other kind of exceptions in SQL Server itself. Mostly in error logs table instead of logging it in the server side code.
I tried doing it via Sql profiler (for creating server side trace), but I dont know what options to select for SP timeout trace.

Related

I'm using a Linked Server to pull data from Google BigQuery to SQL Server using the Simba Driver but larger recordsets kill my SQL Server service

I'm running SQL Server 2016 (13.0.5850.14) with a linked server connection to Google BigQuery using the Simba BigQuery driver v2.4.1.1009 (64 bit). I have multiple queries that I'm using to bring data back to our premise operational data store. The solution works fine for small record sets but there seems to be a point where larger record sets kill the SQL Service.
One of my queries returns a record set within a few seconds when limited to 40,000 records but kills the service when returning the full record set of approx 47,000 records.
SQL traces don't show any errors, neither does the event log. The SQL log does say:
Message
SQL Server is terminating because of fatal exception 40000015. This error may be caused by an unhandled Win32 or C++ exception, or by an access violation encountered during exception handling. Check the SQL error log for any related stack dumps or messages. This exception forces SQL Server to shutdown. To recover from this error, restart the server (unless SQLAgent is configured to auto restart).
I've already extended the timeout on the connections but that doesn't seem to have made any difference and I suspect its more some sort of memory issue with the driver but I really don't know what more I can do? Appreciate any suggestions

Stored Procedures in SQL Database in Azure Timeout randomly once every two months

Scenario: System in a VM in Azure using MVC and a SQL Database (not in the VM) working under normal conditions for 2 or 3 months. Suddenly, stored procedures called from my MVC web app or SQL Management Studio return Time Out. Queries like Select * from Table work perfect.
EDIT: Timeouts while executing Alter or Create SP queries happened too.
No proper solutions or explanations found.
Workaround: Restore old backup in a new SQL Database and change the connection string to the new Database. While the system is running in the backup, try to backup the database with issues (first close all connections to that DB like Management Studio). It may take some time and some retries. After the backup is done, restore it in a new DB and change back the connectionString. You will lose a few minutes of data and some downtime but you will have your system working again in Azure.
Any ideas about this issue in the Stored Procedures in Azure?
At first glance, this smells like a parameter sniffing issue; it is probably not related to Azure.
Check this thread for details on what the issue is, and how to resolve it: Parameter Sniffing (or Spoofing) in SQL Server

How can I capture queries that fail on the SQL Server due to connection drops/failures?

How can I capture queries that fail on the SQL Server due to connection drops/failures?
Profiler doesnt seem to capture if there is a connectivity loss.
Without catching the exception in the code this is not the easiest thing to do.
Have you checked the error logs in SQL? DA has a related answer for doing this: https://dba.stackexchange.com/questions/10364/sql-server-error-log-monitoring
You can check that your profiler is set up correctly:
http://support.microsoft.com/kb/224587
There are a number of sql monitoring tools out there, just google 'SQL server monitoring'.

What tool to capture values passed into SQL Server procedure

I have a DLL, for which I do not have the source code. It is making calls to a stored procedure in a SQL Server 2005 database. I need to know what values it is passing in as the parameters of the call.
Is there a free tool, or one that comes with SQL Server that is able to monitor and record the calls into a database?
Thanks.
You can use for this SQL Server Profiler which comes with SQL Server.
If you have an access to Microsoft SQL Server Management Studio, you find it by clicking Tools → SQL Server Profiler.
When it starts, click Connect. On Trace properties dialog, click Run. It then collects every call to the SQL Server and displays the summary at the top, and the query with its parameters at the bottom of the window.
You can also:
Pause or stop the profiler (icons in the toolbar),
Clear the current trace.
Do not forget to clear the trace before launching the action which will call the stored procedure and do not forget to pause/stop the profiling after you get the results to avoid getting too much information to analyze.
As pointed in the comments, if you are using SQL Server Express, the profiler may be missing. You may want to install a third party profiler for SQL Express instead.
Check the [Tools] menu in SQL Server Management Studio:
If you don't see this option, you most likely have SQL Server EXPRESS which does not come with Profiler.

Setting query timeout on a stored procedure in SQL Server 2005

Does anyone know how to set the timeout on a stored procedure? Found some examples on the NET, e.g sp_configure 'remote Query Timeout', 5, but this did not work. Also found some commands "DBPROP_COMMANDTIMEOUT" and "DBPROP_GENERALTIMEOUT" but i don't know if they are the right ones to use and if they are, how to use them in my transact-SQL code.
As Chris Tybur said, you can not the the query timeout for a stored proc in the stored proc or on the SQL Server.
CommandTimeout is a client concept: the client will abort the query after a certain amount of time. There is no dead man's timer or mechanism for a stored proc to abort itself /or any query). SQL server will allow a query to run forever.
The "Remote Query Timeout" is exactly that: timeout when SQL Server makes a remote call, when SQL Server itself is the client of another server. It says in the description:
This value applies to an outgoing
connection initiated by the Database
Engine as a remote query. This value
has no effect on queries received by
the Database Engine.
A recent question with good info: timeout setting for SQL Server
I have never heard of setting a timeout for executing a stored procedure on the server side. Usually you would specify the timeout for the command that runs the procedure in the data provider you are using, such as ADO.NET.
Wait - the real question is, "What is happening that you want to prevent?" Everyone has focused on server-side, client-side but in truth we don't know why you are asking this question (and it's important).
And another "why": why do you want to set a timeout on a "stored procedure"? Why not a view, a function, or a query? Did you use the term "stored procedure" for a particular reason or would you just be interested in learning how to set a timeout in T-SQL?
I'm asking because I wonder if you are having locking issues and perhaps SET LOCK_TIMEOUT 1000 or WITH(NOLOCK) might be what you really need. Without more info though I can't say. If you can give us more feedback on why you are asking, what is happening, and what ultimately you want to have happen if your "timeout" is reached, maybe we can help more.
Bottom line: Yes, you can set a timeout in T-SQL and yes you can stop the execution of a stored procedure with T-SQL. But I don't know enough about what you want to offer advice on where to look or to give you more info. I'm kinda scared that I've already said too much :)
This article has a very good explanation on query timeouts and how they're a client-side concept only. You can set the query timeout in SQL Server management studio from the Tools|Options menu.
You have to set the timeout when you execute the stored procedure on the client. As far as the SQL Server goes, it'll let the stored procedure run for ever unless told to cancel it.