{"id":92109,"date":"2021-09-13T17:00:48","date_gmt":"2021-09-13T17:00:48","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/?p=92109"},"modified":"2021-09-21T17:51:11","modified_gmt":"2021-09-21T17:51:11","slug":"azure-sql-extended-events-and-the-use-of-slash","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/azure-sql-extended-events-and-the-use-of-slash\/","title":{"rendered":"Azure SQL: Extended Events and the use of slash &#8220;\/&#8221;"},"content":{"rendered":"<p><strong>Extended Events<\/strong> is a very important feature to monitor Azure SQL. Recently I faced a very interesting behavior of this feature in relation to the use of the slash (&#8220;\/&#8221;).<\/p>\n<p>URL&#8217;s use the &#8220;\/&#8221; on it. However, the &#8220;\/&#8221; has different meanings depending on where in the URL it appears.<\/p>\n<h2>\nCreate a credential for authentication<\/h2>\n<p>Some features don&#8217;t support a direct link with a credential object to enable the authentication to private storage.<\/p>\n<p>The work-around created for these features was to create a credential name equal to the URL of the storage. When <strong>SQL Server<\/strong> tries to access the storage, it identifies the credential and uses it for the authentication. <strong>Extended Events<\/strong> is one of the features which needs this work around.<\/p>\n<p>I discovered on the worst way the problem a simple slash can cause: The credential can&#8217;t have a slash in the end. The syntax to create the credential is this:<\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> <span style=\"color: blue;\">CREATE<\/span>\u00a0<span style=\"color: blue;\">database<\/span>\u00a0<span style=\"color: maroon;\">scoped<\/span>\u00a0<span style=\"color: maroon;\">CREDENTIAL<\/span>\u00a0<span style=\"color: maroon;\">[https:\/\/maltacentralstorage.blob.core.windows.net\/extendedevents]<\/span> <br \/>\n<span style=\"color: blue;\">WITH<\/span>\u00a0<span style=\"color: blue;\">IDENTITY<\/span><span style=\"color: silver;\">=<\/span><span style=\"color: red;\">&#8216;SHARED\u00a0ACCESS\u00a0SIGNATURE&#8217;<\/span> <br \/>\n<span style=\"color: silver;\">,<\/span>\u00a0<span style=\"color: maroon;\">SECRET<\/span>\u00a0<span style=\"color: silver;\">=<\/span>\u00a0<span style=\"color: red;\">&#8216;***\u00a0SAS\u00a0KEY\u00a0***&#8217;<\/span> <\/span><\/div>\n<p>However, if you include the slash in the end of the credential <em>[https:\/\/maltacentralstorage.blob.core.windows.net\/extendedevents\/]<\/em>, it doesn&#8217;t work. When you try to enable an <strong>Extended Events<\/strong> session linked to this credential, <strong>SQL Server<\/strong> returns the following error message:<\/p>\n<h6>Msg 25602, Level 16, State 1, Line 26<br \/>\nThe target, &#8220;5B2DA06D-898A-43C8-9309-39BBBE93EBBD.package0.event_file&#8221;, encountered a configuration error during initialization. Object cannot be added to the event session. (null)<\/h6>\n<p>This message means the target of <strong>Extended Events<\/strong> could not be initialized, because the credential is wrong.<\/p>\n<h2>\nExtended Events Target URL<\/h2>\n<p>The syntax to create a simple <strong>Extended Events<\/strong> Session is this:<\/p>\n<div><span style=\"font-family: Courier New; font-size: 10pt;\"> CREATE\u00a0<span style=\"color: maroon;\">EVENT<\/span>\u00a0<span style=\"color: maroon;\">SESSION<\/span>\u00a0<span style=\"color: maroon;\">[BlockedProcess2]<\/span>\u00a0<span style=\"color: blue;\">ON<\/span>\u00a0<span style=\"color: blue;\">DATABASE<\/span> <br \/>\n<span style=\"color: blue;\">ADD<\/span>\u00a0<span style=\"color: maroon;\">EVENT<\/span>\u00a0<span style=\"color: maroon;\">sqlserver<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">blocked_process_report<\/span> <br \/>\n<span style=\"color: blue;\">ADD<\/span>\u00a0<span style=\"color: maroon;\">TARGET<\/span>\u00a0<span style=\"color: maroon;\">package0<\/span><span style=\"color: silver;\">.<\/span><span style=\"color: maroon;\">event_file<\/span><span style=\"color: maroon;\">(<\/span><span style=\"color: blue;\">SET<\/span>\u00a0<span style=\"color: maroon;\">filename<\/span><span style=\"color: silver;\">=<\/span><span style=\"color: red;\">N&#8217;https:\/\/maltacentralstorage.blob.core.windows.net\/extendedevents\/queries&#8217;<\/span><span style=\"color: maroon;\">)<\/span> <br \/>\n<span style=\"color: blue;\">WITH<\/span>\u00a0<span style=\"color: maroon;\">(<\/span><span style=\"color: maroon;\">STARTUP_STATE<\/span><span style=\"color: silver;\">=<\/span><span style=\"color: blue;\">ON<\/span><span style=\"color: maroon;\">)<\/span><span style=\"color: maroon;\">GO<\/span> <\/span><\/div>\n<p>\nOn this example we are using the <strong>URL<\/strong> on the filename attribute of the target element on the session. The core question about this URL is: What exactly <em>&#8216;queries&#8217;<\/em> means, a file name or a folder?<\/p>\n<p>In order to understand the answer, we need to understand how XE will save the files in the destination. The events are saved in many files, not a single one. The default configuration will create 1GB files. Extended Events builds the name of the files dynamically.<\/p>\n<p>Here comes the answer to the questions: What <em>&#8220;queries&#8221;<\/em> is? What difference the slash makes in this example?<\/p>\n<p>If the <strong>URL<\/strong> has a slash in the end, <em>&#8220;queries&#8221;<\/em> will be considered to be a folder. The files will be stored inside the folder and the names will all start with <em>&#8220;_&#8221;<\/em> and have a generated code.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-92111\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/XE2.png\" alt=\"\" width=\"566\" height=\"188\" \/><\/p>\n<p>If the <strong>URL<\/strong> hasn&#8217;t a slash in the end,\u00a0 XE will use\u00a0<em>&#8220;queries&#8221; <\/em>\u00a0as part of the file name. The files will be stored directly inside <em>&#8220;extendedevents&#8221;<\/em> container and the file names will start with <em>&#8220;queries_&#8221;<\/em> and a generated code.<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-92110\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/2021\/08\/XE1.png\" alt=\"\" width=\"586\" height=\"219\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>A simple slash can send the files to a different place.<\/p>\n<h2>Conclusion<\/h2>\n<p>Different features can use the slash in different ways and this can get quite confusing sometimes. In this blog I mentioned only <strong>Extended Events<\/strong>, there are many more with different uses for a slash.<\/p>\n<p>One additional detail about this is that <strong>Extended Events<\/strong> don&#8217;t support <strong>Azure Blob Storage<\/strong> with <strong>Hierarchical Namespaces<\/strong> enabled.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many DBA skills transfer when moving to the cloud, but you&#8217;ll have to make some adjustments in many cases. In this post, Dennes Torres explains one of the differences when setting up Extended Events sessions in Azure SQL Database.&hellip;<\/p>\n","protected":false},"author":50808,"featured_media":92446,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[5364,136322,5679,4151],"coauthors":[6810],"class_list":["post-92109","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blogs","tag-azure","tag-azure-sql","tag-extended-events","tag-sql-server"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/92109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/50808"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=92109"}],"version-history":[{"count":5,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/92109\/revisions"}],"predecessor-version":[{"id":92462,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/92109\/revisions\/92462"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media\/92446"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=92109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=92109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=92109"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=92109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}