{"id":554,"date":"2011-05-20T20:53:00","date_gmt":"2011-05-20T20:53:00","guid":{"rendered":"\/blogs\/bobb\/post\/What-appears-in-DMVs-for-SQLCLR.aspx"},"modified":"2013-01-03T23:59:32","modified_gmt":"2013-01-04T07:59:32","slug":"what-appears-in-dmvs-for-sqlclr","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/","title":{"rendered":"What appears in DMVs for SQLCLR?"},"content":{"rendered":"<p>\nA variation of the following question came up in a mail list that I&rsquo;m on. Can you see currently executing SQLCLR code statements (i.e. the underlying C# code) in any of the sys.dm_exec&hellip; DMVs? Or anywhere else? This turned out to be more interesting than I thought.\n<\/p>\n<p>\nAs far as the engine internals are concerned, there is no CLR code but IL (.NET intermediate language). The assembly&rsquo;s IL code is available (it&rsquo;s stored in sys.assembly_files) and there are tools (e.g. an add-in for Reflector) that can extract it and decompile it to the language of your choice. But, even if you catalog the source as a &ldquo;related file&rdquo; (using ALTER ASSEMBLY&hellip;ADD FILE&hellip;, VS autodeploy does this) there&rsquo;s no lookup into related files by the DMVs (that&rsquo;s not what this feature is for, it&rsquo;s for <a href=\"http:\/\/3.209.169.194\/blogs\/bobb\/whats-that-source-code-doin-in-there\/\" class=\"broken_link\">this reason<\/a>), so the underlying C#, VB.NET, or IL code is never displayed.&nbsp;\n<\/p>\n<p>\nIf your SQLCLR code issues a T-SQL statement however, this statement (via sql_handle) does appear in DMVs. You can see the task executing in sys.dm_clr_tasks, for example, but the sys.dm_exec-* ones can be more interesting. For example, if I have a SQLCLR proc that issues a SQL statement this can appear in sys.dm_exe.query_stats, and sys.dm_exec_cached_plans. In cached_plans, this appears as a plan for a SQLCLR proc (with no SQL handle) and a plan for a Prepared Stmt (for the T-SQL statement). If you happen to query sys.dm_exec_requests while the T-SQL statement is executing, there is a sql_handle that points to the T-SQL statement, otherwise the sql_text is NULL.\n<\/p>\n<p>\nInterestingly, sys.dm_exec_cached_plans contains a sql_text for the SQLCLR stored procedure, with a text of &ldquo;exec myproc&rdquo; and a cacheobjtype of CLR_Compiled_Proc. But sys.dm_exec_query_stats contains no entries for the stored procedure (with or without text), although the is a line for the executed T-SQL. In my simple sample (a single T-SQL SELECT statement using Pipe.ExecuteAndSend), only the executed T-SQL statement. This means that you don&rsquo;t see any statistic in query_stats for the &ldquo;clr_time&rdquo; series of counters in any entry of sys.dm_exec_query_stats with a stored procedure.\n<\/p>\n<p>\nUsing a SQLCLR UDF (I used a&nbsp;scalar UDF)&nbsp;in a T-SQL statment would contain non-zero values for those counters, because its part of the T-SQL statement that uses it. And, for a UDF that doesn&#39;t use T-SQL, there is no entry in sys.dm_exec_cached_plans for the UDF. For a SQLCLR UDF that does use T-SQL, you get a cached_plan for both the T-SQL statement and one for the function, of type CLR Compiled Func, with the function&#39;s name as the T-SQL text. There also appears to be two cache entries for Parse Tree\/Check with NULL text after executing the UDF containing T-SQL statements.\n<\/p>\n<p>\n&nbsp;@bobbeauch<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A variation of the following question came up in a mail list that I&rsquo;m on. Can you see currently executing SQLCLR code statements (i.e. the underlying C# code) in any of the sys.dm_exec&hellip; DMVs? Or anywhere else? This turned out to be more interesting than I thought. As far as the engine internals are concerned, [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-554","post","type-post","status-publish","format-standard","hentry","category-sqlclr"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What appears in DMVs for SQLCLR? - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What appears in DMVs for SQLCLR? - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"A variation of the following question came up in a mail list that I&rsquo;m on. Can you see currently executing SQLCLR code statements (i.e. the underlying C# code) in any of the sys.dm_exec&hellip; DMVs? Or anywhere else? This turned out to be more interesting than I thought. As far as the engine internals are concerned, [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2011-05-20T20:53:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-01-04T07:59:32+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/\",\"name\":\"What appears in DMVs for SQLCLR? - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2011-05-20T20:53:00+00:00\",\"dateModified\":\"2013-01-04T07:59:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQLCLR\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sqlclr\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"What appears in DMVs for SQLCLR?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What appears in DMVs for SQLCLR? - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/","og_locale":"en_US","og_type":"article","og_title":"What appears in DMVs for SQLCLR? - Bob Beauchemin","og_description":"A variation of the following question came up in a mail list that I&rsquo;m on. Can you see currently executing SQLCLR code statements (i.e. the underlying C# code) in any of the sys.dm_exec&hellip; DMVs? Or anywhere else? This turned out to be more interesting than I thought. As far as the engine internals are concerned, [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/","og_site_name":"Bob Beauchemin","article_published_time":"2011-05-20T20:53:00+00:00","article_modified_time":"2013-01-04T07:59:32+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/","name":"What appears in DMVs for SQLCLR? - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2011-05-20T20:53:00+00:00","dateModified":"2013-01-04T07:59:32+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/what-appears-in-dmvs-for-sqlclr\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"SQLCLR","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/sqlclr\/"},{"@type":"ListItem","position":3,"name":"What appears in DMVs for SQLCLR?"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=554"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/554\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}