Skip to content

Commit ae7b15a

Browse files
committed
use convert syntax for adodbapi
1 parent 751af58 commit ae7b15a

File tree

1 file changed

+25
-9
lines changed
  • sqlserver/datadog_checks/sqlserver/xe_collection

1 file changed

+25
-9
lines changed

sqlserver/datadog_checks/sqlserver/xe_collection/base.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,33 @@ def _query_ring_buffer(self):
234234
if self._is_azure_sql_database:
235235
level = "database_"
236236

237-
# Get raw XML data without server-side parsing
238-
query = f"""
239-
SELECT CAST(t.target_data AS XML) AS target_xml
240-
FROM sys.dm_xe_{level}sessions s
241-
JOIN sys.dm_xe_{level}session_targets t
242-
ON s.address = t.event_session_address
243-
WHERE s.name = ?
244-
AND t.target_name = 'ring_buffer'
245-
"""
237+
# Determine if we need to use CONVERT based on connector type
238+
use_convert = False
239+
if self._check.connection.connector == "adodbapi":
240+
use_convert = True
241+
self._log.debug("Using CONVERT syntax for Windows/adodbapi compatibility")
246242

247243
try:
244+
# Choose the appropriate query based on connector type
245+
if use_convert:
246+
query = f"""
247+
SELECT CONVERT(NVARCHAR(MAX), t.target_data) AS target_xml
248+
FROM sys.dm_xe_{level}sessions s
249+
JOIN sys.dm_xe_{level}session_targets t
250+
ON s.address = t.event_session_address
251+
WHERE s.name = ?
252+
AND t.target_name = 'ring_buffer'
253+
"""
254+
else:
255+
query = f"""
256+
SELECT CAST(t.target_data AS XML) AS target_xml
257+
FROM sys.dm_xe_{level}sessions s
258+
JOIN sys.dm_xe_{level}session_targets t
259+
ON s.address = t.event_session_address
260+
WHERE s.name = ?
261+
AND t.target_name = 'ring_buffer'
262+
"""
263+
248264
cursor.execute(query, (self.session_name,))
249265
row = cursor.fetchone()
250266
if row and row[0]:

0 commit comments

Comments
 (0)