tôi đã thiết lập SQL Server mở rộng các sự kiện để bắt cuối năm 1000 đã thất bại truy vấn trong cơ sở dữ liệu cụ thể vào một vòng đệm:Chụp các giá trị tham số trong các phiên mở rộng của SQL Server?
Create Event Session [Errors] on Server
Add Event sqlserver.error_reported (
Action(
sqlos.task_time,
sqlserver.sql_text
)
Where sqlserver.database_name=N'MyDatabase'
And error_number<>5701 -- Ignore changed db context messages
)
Add target package0.ring_buffer(Set max_memory=102400)
With (
MAX_MEMORY=4096 KB,
EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,
MAX_DISPATCH_LATENCY=30 SECONDS,
MAX_EVENT_SIZE=0 KB,
MEMORY_PARTITION_MODE=NONE,
TRACK_CAUSALITY=OFF,
STARTUP_STATE=ON
)
Go
bây giờ tôi có thể truy vấn các lỗi như vậy:
Select
xmldata = Cast(xet.target_data as xml)
Into #rbd
From sys.dm_xe_session_targets xet
Join sys.dm_xe_sessions xe ON (xe.address = xet.event_session_address)
Where xe.name='errors' and target_name='ring_buffer'
; With Errors as (
Select
e.query('.').value('(/event/@timestamp)[1]', 'datetime') as "TimeStamp",
e.query('.').value('(/event/data[@name="message"]/value)[1]', 'nvarchar(max)') as "Message",
e.query('.').value('(/event/action[@name="sql_text"]/value)[1]', 'nvarchar(max)') as "SqlText",
e.query('.').value('(/event/action[@name="task_time"]/value)[1]', 'bigint')/@@TIMETICKS as "Duration"
From #rbd
Cross Apply XMLData.nodes('/RingBufferTarget/event') as Event(e)
)
Select * from Errors
Where SqlText is not null
Drop Table #rbd
Cho đến nay, như vậy tốt:
này đã được một trợ giúp lớn trong việc theo dõi chi tiết hơn về lỗi tha t bị ném ở cấp ứng dụng.
Điều gì sẽ làm cho nó hữu ích hơn nữa, mặc dù, sẽ là nếu chúng ta có thể thấy các giá trị tham số được truyền cho các truy vấn này, cách bạn có thể trong SQL Profiler. Vì vậy, khi chúng ta thấy một lỗi như thế này ...
Conversion failed when converting date and/or time from character string.
cho SQL này ...
(@NewValue nvarchar(10),@KeyValue int)
Update SomeTable
Set [email protected] Where [email protected]
... nó sẽ là thông tin để biết những gì các giá trị của các thông số @NewValue
và @KeyValue
là .
Bất kỳ ý tưởng nào mà tôi có thể tìm thấy thông tin này?
điều này có thể/không thể trợ giúp: http://www.brentozar.com/archive/2013/08/what-queries-are-failing-in-my-sql-server/ – Tanner
@Tanner - không, không có gì trong có về các thông số. –
Tôi sẽ đề nghị chỉ sử dụng [SQL Server Profiler] (http://msdn.microsoft.com/en-us/library/ms181091.aspx). – Brian