<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Ujjwal Patel's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/ujpat/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/ujpat/feed.xml</link>
    <description>A to Z about SQL AND Azure SQL VM&amp;#039;s</description>
    <lastBuildDate>Tue, 16 Apr 2019 05:35:47 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Using Backup to URL in SQL Server 2012 instance</title>
      <link>https://docs.microsoft.com/archive/blogs/ujpat/using-backup-to-url-in-sql-server-2012-instance</link>
      <pubDate>Tue, 24 Jan 2017 03:33:53 GMT</pubDate>
      <dc:creator><![CDATA[Ujjwal Patel]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ujpat/?p=285</guid>
      <description><![CDATA[&nbsp; In this post, we would like to explain on how we can overcome the limitation of using the...]]></description>
      <content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"></span>&nbsp;</p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal">In this post, we would like to explain on how we can overcome the limitation of using the feature “backup to URL” in Maintenance Plan wizard in SQL 2012 </p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"></span>&nbsp;</p> <p class="MsoNormal" style="background: white;margin: 0cm 0cm 7.5pt;line-height: normal"><span style="font-family:;color:"><font face="Segoe UI Light"><font style="font-size: 22.5pt">Symptoms</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal">We cannot take backups from maintenance plans using backup to URL to Azure Blob Storage using SQL 2012 Engine instance with 2012/2014/2016 SSMS.</p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font color="#000000">&nbsp;</font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><b><u><span style="font-family:;color:">Error:</span></u></b><b><span style="font-family:;color:"> -</span></b></p> <p>With SQL 2012, We do not have the option to backup to URL. With 2014/2016 SSMS we do have the option to backup to URL in maintenance plans but that would execute with success but not back up files on the blob.</p> <p>The Maintenance plan gets executed successfully but does not give any error.<br></p> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span>Cause </span><span></span></h2> <p>Maintenance plans in SQL 2012 does not have the option to use “Backup to URL” Feature. If we install SSMS 2014/2016 on the 2012 Engine instance, we will see the option but the backup will still not work to the azure blob.<br>By default, the backups will go to the disk even if we select the “backup to url” option.</p> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span>Resolution</span><span></span></h2> <ul> <li>I have written a T-SQL script to do the same. We can create an Agent Job and set up a schedule to back this up (Note: We can also you TSQL step and use the below script if we need to use Maintenance plan)  <li>We need to first create a credential in SQL Server which will authenticate to the blob storage to save the files. Use the below script for the same:</li></ul> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Create a credential for the blob storage to be used during backup:<br></p> <table class="MsoNormalTable" style="border-collapse: collapse;margin-left: 36pt;line-height: normal" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td style="border-top: windowtext 1pt solid;border-right: windowtext 1pt solid;border-bottom: windowtext 1pt solid;padding-bottom: 0cm;padding-top: 0cm;padding-left: 5.4pt;border-left: windowtext 1pt solid;padding-right: 5.4pt" valign="top" width="623"> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-family:;color:"><font face="Consolas"><font color="#008000" size="2">--Identity is the storage account name, whereas secret is the access key to the storage account</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">IF</font></span><span style="font-family:"><font color="#000000"> </font><span style="color:"><font color="#808080">NOT</font></span><font color="#000000"> </font><span style="color:"><font color="#808080">EXISTS(</font></span><span style="color:"><font color="#0000ff">SELECT</font></span><font color="#000000"> </font><span style="color:"><font color="#808080">*</font></span><font color="#000000"> </font><span style="color:"><font color="#0000ff">FROM</font></span><font color="#000000"> </font><span style="color:"><font color="#008000">sys</font></span><span style="color:"><font color="#808080">.</font></span><span style="color:"><font color="#008000">credentials</font></span><font color="#000000"> </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-family:"><font face="Consolas"><font size="2"><font color="#000000">&nbsp;</font><span style="color:"><font color="#0000ff">WHERE</font></span><font color="#000000"> credential_identity </font><span style="color:"><font color="#808080">=</font></span><font color="#000000"> </font><span style="color:"><font color="#ff0000">' bkuptourl'</font></span><span style="color:"><font color="#808080">)</font></span><font color="#000000"> </font></font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">CREATE</font></span><span style="font-family:"><font color="#000000"> </font><span style="color:"><font color="#0000ff">CREDENTIAL</font></span><font color="#000000"> bkuptourl </font><span style="color:"><font color="#0000ff">WITH</font></span><font color="#000000"> </font><span style="color:"><font color="#0000ff">IDENTITY</font></span><font color="#000000"> </font><span style="color:"><font color="#808080">=</font></span><font color="#000000"> </font><span style="color:"><font color="#ff0000">'2012bckup'</font></span><font color="#000000"> </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-family:"><font face="Consolas"><font size="2"><font color="#000000">&nbsp;</font><span style="color:"><font color="#808080">,</font></span><span style="color:"><font color="#0000ff">SECRET</font></span><font color="#000000"> </font><span style="color:"><font color="#808080">=</font></span><font color="#000000"> </font><span style="color:"><font color="#ff0000">'TvAra31QMlCfBRpTyX9/1wMJglNFdGW+9NX5OOVp5uU3kbMeC18Pq8Rt7iJ552oU2tGM6rzmKOkiUcaZxwDtwQ=='</font></span><span style="color:"><font color="#808080">;</font></span></font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-family:;color:"><font face="Consolas"><font style="font-size: 9.5pt" color="#808080">&nbsp;</font></font></span></p></td></tr></tbody></table> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 36pt;line-height: normal">&nbsp;</p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 36pt;line-height: normal">Navigate to SQL Jobs and create a new Job with T-SQL, set up a schedule and add the below script to back up all the databases except tempdb:</p> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 36pt;line-height: normal"><span style="font-family:;color:"><font color="#000000"></font></span>&nbsp;</p> <table class="MsoNormalTable" style="border-collapse: collapse;margin-left: 36pt;line-height: normal" cellspacing="0" cellpadding="0" border="0"> <tbody> <tr style="height: 232.05pt"> <td style="border-top: windowtext 1pt solid;border-right: windowtext 1pt solid;border-bottom: windowtext 1pt solid;padding-bottom: 0cm;padding-top: 0cm;padding-left: 5.4pt;border-left: windowtext 1pt solid;padding-right: 5.4pt" height="309" valign="top" width="908"> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">DECLARE</font></span><span style="font-family:;color:"><font color="#000000"> @DB_name </font></span><span style="font-family:;color:"><font color="#0000ff">VARCHAR</font></span><span style="font-family:;color:"><font color="#808080">(</font></span><span style="font-family:;color:"><font color="#000000">50</font></span><span style="font-family:;color:"><font color="#808080">)</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#008000">-- database name&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">DECLARE</font></span><span style="font-family:;color:"><font color="#000000"> @BackupLoc </font></span><span style="font-family:;color:"><font color="#0000ff">VARCHAR</font></span><span style="font-family:;color:"><font color="#808080">(</font></span><span style="font-family:;color:"><font color="#000000">256</font></span><span style="font-family:;color:"><font color="#808080">)</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#008000">-- path for backup files&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">DECLARE</font></span><span style="font-family:;color:"><font color="#000000"> @BackupfileName </font></span><span style="font-family:;color:"><font color="#0000ff">VARCHAR</font></span><span style="font-family:;color:"><font color="#808080">(</font></span><span style="font-family:;color:"><font color="#000000">256</font></span><span style="font-family:;color:"><font color="#808080">)</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#008000">-- filename for backup&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">DECLARE</font></span><span style="font-family:;color:"><font color="#000000"> @fileDate </font></span><span style="font-family:;color:"><font color="#0000ff">VARCHAR</font></span><span style="font-family:;color:"><font color="#808080">(</font></span><span style="font-family:;color:"><font color="#000000">20</font></span><span style="font-family:;color:"><font color="#808080">)</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#008000">-- used for file name</font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-family:;color:"><font face="Consolas"><font color="#008000" size="2">-- specify database backup container location</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">SET</font></span><span style="font-family:;color:"><font color="#000000"> @BackupLoc </font></span><span style="font-family:;color:"><font color="#808080">=</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#ff0000">'https://SQLServerBackup.blob.core.windows.net/Prod/'</font></span><span style="font-family:;color:"><font color="#000000">&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">set</font></span><span style="font-family:;color:"><font color="#000000"> @fileDate</font></span><span style="font-family:;color:"><font color="#808080">=</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#ff00ff">replace</font></span><span style="font-family:;color:"><font color="#808080">(</font></span><span style="font-family:;color:"><font color="#ff00ff">replace</font></span><span style="font-family:;color:"><font color="#808080">(</font></span><span style="font-family:;color:"><font color="#ff00ff">convert</font></span><span style="font-family:;color:"><font color="#808080">(</font></span><span style="font-family:;color:"><font color="#0000ff">nvarchar</font></span><span style="font-family:;color:"><font color="#808080">(</font></span><span style="font-family:;color:"><font color="#000000">50</font></span><span style="font-family:;color:"><font color="#808080">),</font></span><span style="font-family:;color:"><font color="#ff00ff">getdate</font></span><span style="font-family:;color:"><font color="#808080">()),</font></span><span style="font-family:;color:"><font color="#ff0000">' '</font></span><span style="font-family:;color:"><font color="#808080">,</font></span><span style="font-family:;color:"><font color="#ff0000">'_'</font></span><span style="font-family:;color:"><font color="#808080">),</font></span><span style="font-family:;color:"><font color="#ff0000">':'</font></span><span style="font-family:;color:"><font color="#808080">,</font></span><span style="font-family:;color:"><font color="#ff0000">'_'</font></span><span style="font-family:;color:"><font color="#808080">)</font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">DECLARE</font></span><span style="font-family:;color:"><font color="#000000"> db_cursor </font></span><span style="font-family:;color:"><font color="#0000ff">CURSOR</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">FOR</font></span><span style="font-family:;color:"><font color="#000000">&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">SELECT</font></span><span style="font-family:;color:"><font color="#000000"> name </font></span><span style="font-family:;color:"><font color="#0000ff">FROM</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">master</font></span><span style="font-family:;color:"><font color="#808080">.</font></span><span style="font-family:;color:"><font color="#00ff00">sys</font></span><span style="font-family:;color:"><font color="#808080">.</font></span><span style="font-family:;color:"><font color="#00ff00">databases</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">WHERE</font></span><span style="font-family:;color:"><font color="#000000"> database_id </font></span><span style="font-family:;color:"><font color="#808080">&lt;&gt;</font></span><span style="font-family:;color:"><font color="#000000">2 </font></span><span style="font-family:;color:"><font color="#808080">and</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">state</font></span><span style="font-family:;color:"><font color="#808080">=</font></span><span style="font-family:;color:"><font color="#000000">0</font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">OPEN</font></span><span style="font-family:;color:"><font color="#000000"> db_cursor&nbsp;&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">FETCH</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">NEXT</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">FROM</font></span><span style="font-family:;color:"><font color="#000000"> db_cursor </font></span><span style="font-family:;color:"><font color="#0000ff">INTO</font></span><span style="font-family:;color:"><font color="#000000"> @DB_name&nbsp;&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">WHILE</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#ff00ff">@@FETCH_STATUS</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#808080">=</font></span><span style="font-family:;color:"><font color="#000000"> 0&nbsp;&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">BEGIN</font></span><span style="font-family:;color:"><font color="#000000">&nbsp;&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="font-family:;color:"><font color="#0000ff">SET</font></span><span style="font-family:;color:"><font color="#000000"> @BackupfileName </font></span><span style="font-family:;color:"><font color="#808080">=</font></span><span style="font-family:;color:"><font color="#000000"> @BackupLoc </font></span><span style="font-family:;color:"><font color="#808080">+</font></span><span style="font-family:;color:"><font color="#000000"> @DB_name </font></span><span style="font-family:;color:"><font color="#808080">+</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#ff0000">'_'</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#808080">+</font></span><span style="font-family:;color:"><font color="#000000"> @fileDate </font></span><span style="font-family:;color:"><font color="#808080">+</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#ff0000">'.BAK'</font></span><span style="font-family:;color:"><font color="#000000">&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="font-family:;color:"><font color="#0000ff">BACKUP</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">DATABASE</font></span><span style="font-family:;color:"><font color="#000000"> @DB_name </font></span><span style="font-family:;color:"><font color="#0000ff">TO</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">URL</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#808080">=</font></span><span style="font-family:;color:"><font color="#000000"> @BackupfileName&nbsp; </font></span><span style="font-family:;color:"><font color="#0000ff">WITH</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">CREDENTIAL</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#808080">=</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#ff0000">'bkuptourl'</font></span><span style="font-family:;color:"><font color="#808080">,</font></span><span style="font-family:;color:"><font color="#0000ff">COMPRESSION</font></span><span style="font-family:;color:"><font color="#000000">&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="font-family:;color:"><font color="#0000ff">print</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#ff0000">'BACKUP DATABASE '</font></span><span style="font-family:;color:"><font color="#808080">+</font></span><span style="font-family:;color:"><font color="#000000">@DB_name</font></span><span style="font-family:;color:"><font color="#808080">+</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#ff0000">' TO URL ='''</font></span><span style="font-family:;color:"><font color="#808080">+</font></span><span style="font-family:;color:"><font color="#000000"> @BackupfileName&nbsp; </font></span><span style="font-family:;color:"><font color="#808080">+</font></span><span style="font-family:;color:"><font color="#ff0000">''' WITH CREDENTIAL = ''bkuptourl'',COMPRESSION '</font></span><span style="font-family:;color:"><font color="#000000"> </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span><span style="font-family:;color:"><font color="#0000ff">FETCH</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">NEXT</font></span><span style="font-family:;color:"><font color="#000000"> </font></span><span style="font-family:;color:"><font color="#0000ff">FROM</font></span><span style="font-family:;color:"><font color="#000000"> db_cursor </font></span><span style="font-family:;color:"><font color="#0000ff">INTO</font></span><span style="font-family:;color:"><font color="#000000"> @DB_name&nbsp;&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">END</font></span><span style="font-family:;color:"><font color="#000000">&nbsp;&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">CLOSE</font></span><span style="font-family:;color:"><font color="#000000"> db_cursor&nbsp;&nbsp; </font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><font face="Consolas"><font size="2"><span style="font-family:;color:"><font color="#0000ff">DEALLOCATE</font></span><span style="font-family:;color:"><font color="#000000"> db_cursor</font></span></font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt"><span style="font-family:;color:"><font face="Consolas"><font style="font-size: 9.5pt" color="#000000">&nbsp;</font></font></span></p></td></tr></tbody></table> <p class="MsoListParagraph" style="margin: 0cm 0cm 0pt 36pt;line-height: normal"><span style="font-family:;color:"><font color="#000000">&nbsp;</font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Segoe UI Light"><font style="font-size: 22.5pt" color="#404040">Sample Output</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><font face="Calibri"><font style="font-size: 11pt" color="#000000">&nbsp;</font></font></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><a href="https://msdnshared.blob.core.windows.net/media/2017/01/clip_image0019.jpg"><img title="clip_image001" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;padding-top: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px" border="0" alt="clip_image001" src="https://msdnshared.blob.core.windows.net/media/2017/01/clip_image001_thumb7.jpg" width="735" height="519"></a></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font color="#000000">&nbsp;</font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font color="#000000">&nbsp;</font></span></p> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><font face="Segoe UI"><b><u><span><font style="font-size: 10.5pt">Related articles:</font></span></u></b><span></span></font></h2> <ul> <li>Backup to URL with SQL 2012/Limitations: <a href="https://technet.microsoft.com/en-us/library/jj919148(v=sql.110).aspx">https://technet.microsoft.com/en-us/library/jj919148(v=sql.110).aspx</a>  <li>Backup to URL Configuration/Troubleshooting: <a href="https://msdn.microsoft.com/en-us/library/jj919149.aspx">https://msdn.microsoft.com/en-us/library/jj919149.aspx</a>  <li>Backup and Restore with Blob Storage: <a href="https://technet.microsoft.com/en-us/library/jj919148(v=sql.110).aspx">https://technet.microsoft.com/en-us/library/jj919148(v=sql.110).aspx</a> </li></ul> <p><strong>Written by – Ujjwal Patel, Support Engineer.<br>Reviewed by – Raghavendra Srinivasan, Sr. Support Engineer.</strong><br></p><span style="font-family:;line-height: normal"><font face="Calibri"><font style="font-size: 11pt" color="#000000">&nbsp;</font></font></span>]]></content:encoded>
    </item>
    <item>
      <title>Error: Could not deploy package. Unable to connect to target server.</title>
      <link>https://docs.microsoft.com/archive/blogs/ujpat/error-could-not-deploy-package-unable-to-connect-to-target-server</link>
      <pubDate>Sun, 22 Jan 2017 10:13:01 GMT</pubDate>
      <dc:creator><![CDATA[Ujjwal Patel]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ujpat/?p=225</guid>
      <description><![CDATA[In this post we would like to explain one of the interesting issue that we encountered while...]]></description>
      <content:encoded><![CDATA[<p>In this post we would like to explain one of the interesting issue that we encountered while deploying a DACPAC from sqlpackage.exe.  <h4><font size="5">Symptoms</font></h4> <p>Cannot Deploy DACPAC Extracted from SQL 2012 Server from .NET custom code or from SQLPackage.exe command to SQL 2014  <p><a href="https://msdnshared.blob.core.windows.net/media/2016/10/image392.png"><img title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/10/image_thumb361.png" width="1024" height="144"></a>  <p>C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin&gt;SqlPackage.exe /Action:Publish /SourceFile:”C:\temp\AgentLink2_11.0.6020.dacpac” /tsn:”RAGHAVSDC” /TargetDatabaseName:TestACM  <p>Publishing to database ‘TestACM’ on server ‘RAGHAVSDC’.<br>The dac history table will not be updated.<br>Initializing deployment (Start)<br>Initializing deployment (Failed)<br><font color="#ff0000">*** Could not deploy package.<br>Unable to connect to target server.</font>  <h4><font size="5">Cause </font></h4> <p>We don’t have a DAC Folder at location <u>C:\Program Files (x86)\Microsoft SQL Server\120\</u> in the system but have the folder<u> C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin</u> (We can successfully publish to SQL 2012 but not SQL 2014)  <h4><font size="5">Resolution</font></h4> <p>To reproduce the issue, please find a DAC folder at location <u>C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin</u>  <p>Open a CMD with administrator privileges and navigate to this path and run the sqlpackage.exe to publish it to a SQL 2014/2016 server and we will get the same exact error  <p><font color="#ff0000">“*** Could not deploy package. </font> <p><font color="#ff0000">Unable to connect to target server.”</font>  <p>The above looks like to be a connectivity error at our first glance but this is not the case here. We tested the connectivity for this on multiple machines and didn’t find an issue with it. The solution to the problem is we need to install the DAC Framework <a href="https://www.microsoft.com/en-in/download/details.aspx?id=42293">https://www.microsoft.com/en-in/download/details.aspx?id=42293 </a>and once installed, we will be able to see the DAC Folder at <u>C:\Program Files (x86)\Microsoft SQL Server\120\DAC\</u>  <p>We then can try to publish the DACPAC from sqlpackage.exe from the 120 Location and it gets published successfully.  <h6><a href="https://msdnshared.blob.core.windows.net/media/2016/10/image393.png"><img title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/2016/10/image_thumb362.png" width="1117" height="259"></a></h6> <h6><b><u><font size="3">More Information:</font></u></b></h6> <p>In the above scenario, we noticed that we can only publish the DACPAC for the version the DACPAC file was created for.  <p>If we have taken a DACPAC for SQL 2012, then we can publish is to any higher version of SQL but it needs to be published from the 120 folder (<u>C:\Program Files (x86)\Microsoft SQL Server\120\DAC\Bin</u>) if we want to publish to SQL 2014. If we are trying to publish the DACPAC taken from SQL 2012 to 2016 then we need to publish the package from the 130 Folder (<u>C:\Program Files (x86)\Microsoft SQL Server\130\DAC\Bin</u>)  <p>DACPAC is a feature of our Data Tier application which will allow us to backup the schema of our database. In simple terms, it is only database schema (definition without the data) which can be used on higher versions of SQL Server. SQLPackage.exe is a utility which allows us to automate database development and projects in our environment.  <h6><b><u><font size="3">Related articles:</font></u></b></h6> <p>SQLPackage.exe: <a href="https://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx">https://msdn.microsoft.com/en-us/library/hh550080(v=vs.103).aspx</a>  <p>Data Tier Applications: <a href="https://msdn.microsoft.com/en-us/library/ee210546.aspx">https://msdn.microsoft.com/en-us/library/ee210546.aspx</a>  <p>Design and Implementation for DACPAC: <a href="https://technet.microsoft.com/en-us/library/ee210546(v=sql.110).aspx">https://technet.microsoft.com/en-us/library/ee210546(v=sql.110).aspx</a>  <p>DAC Framework download: <a href="https://www.microsoft.com/en-in/download/details.aspx?id=42293">https://www.microsoft.com/en-in/download/details.aspx?id=42293 </a> <p><strong>Written by – Ujjwal Patel, Support Engineer.<br>Reviewed by – Raghavendra, , Sr. Support Engineer.</strong>]]></content:encoded>
    </item>
    <item>
      <title>SQL Server Service fails to start after applying patch. Error: CREATE SCHEMA failed due to previous errors.</title>
      <link>https://docs.microsoft.com/archive/blogs/ujpat/sql-server-service-fails-to-start-after-applying-patch-error-create-schema-failed-due-to-previous-errors</link>
      <pubDate>Sun, 22 Jan 2017 10:09:10 GMT</pubDate>
      <dc:creator><![CDATA[Ujjwal Patel]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ujpat/?p=215</guid>
      <description><![CDATA[&nbsp; In this post we would like to explain one of the interesting issues that we encountered while...]]></description>
      <content:encoded><![CDATA[<p>&nbsp; <p>In this post we would like to explain one of the interesting issues that we encountered while upgrading a SQL Server Instance.  <h4><font size="5">Symptoms</font></h4> <p>SQL Server Service fails to start after applying SQL patch due to misconfiguration in MSDB.  <p><b><u><font size="3">Error:-</font></u></b>  <p><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; </i><i>Script level upgrade for database ‘master’ failed because upgrade step </i><b><i><u>‘msdb110_upgrade.sql’</u></i></b><i> encountered error 2714, state 6, severity 25.</i> <i>Severity: 16, State: 0.</i><i></i><br><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; <strong><font color="#ff0000">CREATE SCHEMA failed due to previous errors.</font></strong></i><i></i><strong><br></strong><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; Error: 912, Severity: 21, State: 2.</i><i></i><br><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; Script level upgrade for database ‘master’ failed because upgrade step ‘msdb110_upgrade.sql’ encountered error 2714, state 6, severity 25. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the ‘master’ database, it will prevent the entire SQL Server instance from starting. Examine the previous error log entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.</i><i></i>  <p><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; Error: 3417, Severity: 21, State: 3.</i><i></i><br><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.</i><i></i>  <p><i>2016-06-28 19:23:41.22 spid5s&nbsp;&nbsp;&nbsp; SQL Server shutdown has been initiated</i>·  <h4><font size="5">Cause </font></h4> <ul> <li>The upgrade script [<b><i><u>msdb110_upgrade.sql</u></i></b><b><i><u>]</u></i></b> executes during the first restart of SQL after the service pack installation.  <li>This script hits an exception during recreation of database role called “<b><u>DatabaseMailUserRole</u></b>”.  <li>This is due to the fact that the schema named “<b><u>DatabaseMailUserRole</u></b>” was owned by other database role then “<b><u>DatabaseMailUserRole</u></b>” – DBO role in our case. </li></ul> <h4><font size="5">Resolution </font></h4> <p>1. Start the SQL server service using Trace flag -T902 ( 902 : Used to skip execution of any scripts during SQL Startup)  <blockquote> <p><a href="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image0024.jpg"><img title="clip_image002" border="0" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image002_thumb2.jpg" width="700" height="166"></a></p></blockquote> <p>Or follow these steps:  <blockquote> <p>· Open SQL Server Configuration Manager.  <p>· In SQL Server Configuration Manager, click <b>SQL Server Services</b>.  <p>· Double-click the SQL Server service.  <p>· In the <b>SQL Server Properties </b>dialog box, click the <b>Advanced </b>tab.  <p>· On click the <b>Advanced </b>tab, locate the <b>Startup Parameters </b>item.  <p>· Add ;-T902 to the end of the existing string value, and then click <b>OK</b>.  <p>· Restart the SQL server service</p></blockquote> <p>2. Connect to the SQL instance and backup the MSDB database  <p>3. Manually delete the schema named “<b><u>DatabaseMailUserRole</u></b>”  <p><b></b> <p>Management studio &gt; Expand <b>MSDB</b> Database &gt; Go to <b>Security</b> &gt; <b>Schemas</b> &gt; Look for <b>DatabaseMailuserRole</b>  <p><a href="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image0044.jpg"><img title="clip_image004" border="0" alt="clip_image004" src="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image004_thumb4.jpg" width="421" height="499"></a>  <p>4. Now delete the schema named <b><u>DatabaseMailuserRole</u></b>.  <p>5. Restart the SQL Server service.  <p><a href="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image0064.jpg"><img title="clip_image006" border="0" alt="clip_image006" src="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image006_thumb4.jpg" width="712" height="225"></a>  <h4><font size="5">More information</font> </h4> <ul> <li>Starting SQL Server 2008 onwards, whenever we upgrade or apply a patch on SQL, it upgrades only the binaries and not the database and its objects.  <li>Once the upgrade completes and the service restarts for the first time, it starts the database upgrade using script <b>msdb110_upgrade.sql </b>which is located under </li></ul> <blockquote> <p>C:\Program Files\Microsoft SQL Server\MSSQLXX.YYYY\MSSQL\Install\  <p>XX : SQL Version&nbsp; <br>SQL 2008/R2&nbsp; &gt;10 <br>SQL 2012&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt;11 <br>SQL 2014&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &gt; 12 </p></blockquote> <p><b></b> <p><b></b> <p><em>————————————————————– <br>— Database Mail roles and permissions <br>————————————————————– <br>— Create the DatabaseMailUserRole role <br>IF (EXISTS (SELECT * <br>FROM msdb.dbo.sysusers <br>WHERE (name = N’DatabaseMailUserRole’) <br>AND (issqlrole = 1))) <br>BEGIN — there are no members in the role, then drop and re-create it <br>IF ((SELECT COUNT(*) <br>FROM msdb.dbo.sysusers&nbsp;&nbsp; su, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; msdb.dbo.sysmembers sm <br>WHERE (su.uid = sm.groupuid) <br>AND (su.name = N’DatabaseMailUserRole’) <br>AND (su.issqlrole = 1)) = 0) <br>BEGIN <br>EXECUTE msdb.dbo.sp_droprole @rolename = N’DatabaseMailUserRole’&nbsp;&nbsp; <br>EXECUTE msdb.dbo.sp_addrole @rolename = N’DatabaseMailUserRole’&nbsp; <strong>&lt;&lt; **************Point of failure</strong><br>END <br>END <br>ELSE <br>EXECUTE msdb.dbo.sp_addrole @rolename = N’DatabaseMailUserRole’ <br></em> <ul> <li>The command “SP_ADDROLE” fails as it also creates schema named “<b>DatabaseMailUserRole</b>” which already exists in the MSDB database.  <li>The previous command “SP_DROPROLE” was unable to delete the schema “<b>DatabaseMailUserRole</b>” as it was owned by other database role– DBO role in our case. </li></ul> <p><b><u><font size="3">Steps to repro the error:-</font></u></b>  <p>1. Change the schema owner of “<b><u>DatabaseMailUserRole</u></b>” to DBO  <p><em>USE [msdb] <br>GO <br>ALTER AUTHORIZATION ON SCHEMA::[DatabaseMailUserRole] TO [dbo] <br>GO </em> <p>2. Try to execute the below statement&nbsp; and we hit the same error:  <p><i>EXECUTE msdb.dbo.sp_droprole @rolename = N’DatabaseMailUserRole’&nbsp;&nbsp; <br></i><i>EXECUTE msdb.dbo.sp_addrole @rolename = N’DatabaseMailUserRole’&nbsp; <strong>&lt;&lt;&lt;**************Point of failure</strong></i><strong> </strong> <p><b><i></i></b> <p><b><i><a href="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image0085.jpg"><img title="clip_image008" border="0" alt="clip_image008" src="https://msdnshared.blob.core.windows.net/media/2016/07/clip_image008_thumb5.jpg" width="648" height="203"></a></i></b>  <p><b><i></i></b> <p><b><u><font size="3">Related articles:</font></u></b>  <ul> <li>Using the SQL Server Service Startup Options <a href="https://msdn.microsoft.com/en-us/library/ms190737(v=sql.105).aspx">https://msdn.microsoft.com/en-us/library/ms190737(v=sql.105).aspx</a>  <li>How to: Configure Server Startup Options (SQL Server Configuration Manager) <a href="https://msdn.microsoft.com/en-us/library/ms345416(v=sql.105).aspx">https://msdn.microsoft.com/en-us/library/ms345416(v=sql.105).aspx</a>  <li>ALTER AUTHORIZATION (Transact-SQL) <a href="https://msdn.microsoft.com/en-us/library/ms187359.aspx">https://msdn.microsoft.com/en-us/library/ms187359.aspx</a>  <li>sp_addrole (Transact-SQL) <a href="https://msdn.microsoft.com/en-us/library/ms189743.aspx">https://msdn.microsoft.com/en-us/library/ms189743.aspx</a></li></ul> <h6><br><font style="font-weight: bold">Written by:</font><br><font style="font-weight: bold">Ujjwal Patel, Support Engineer, SQL Server Support</font></h6> <h6><font style="font-weight: bold">Reviewed by:</font><br><font style="font-weight: bold">Raghavendra Srinivasan, Support Engineer, SQL Server Support</font></h6>]]></content:encoded>
    </item>
    <item>
      <title>Automated backups configuration fails when configured from Azure portal</title>
      <link>https://docs.microsoft.com/archive/blogs/ujpat/automated-backups-configuration-fails-when-configured-from-azure-portal</link>
      <pubDate>Thu, 19 Jan 2017 08:41:45 GMT</pubDate>
      <dc:creator><![CDATA[Ujjwal Patel]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ujpat/?p=205</guid>
      <description><![CDATA[&nbsp; In this post, we would like to explain one of the interesting issues that we encountered...]]></description>
      <content:encoded><![CDATA[<p>&nbsp; <p>In this post, we would like to explain one of the interesting issues that we encountered while using the automated backup feature for a VM from the azure portal (We can find the option once we click on VM &gt; SQL Server Configuration&gt; Automated Backup)  <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font color="#000000"></font></span>&nbsp;</p> <p class="MsoNormal" style="background: white;margin: 0cm 0cm 7.5pt;line-height: normal"><span style="font-family:;color:"><font face="Segoe UI Light"><font style="font-size: 22.5pt">Symptoms</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal">&nbsp;</p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal">Cannot Configure Automated backups in azure VM from the portal which was created on ARM (Azure Resource Manager Model)</p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font color="#000000"></font></span>&nbsp;</p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><b><u><span style="font-family:;color:">Error:-</span></u></b></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">• TYPE</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">Microsoft.Compute/virtualMachines/extensions</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">• RESOURCE ID</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font color="#ff0000"><font style="font-size: 9pt">/subscriptions/6c28b945-6d98-403d-8936-5e658f228a0f/resourceGroups/Group/providers/Microsoft.Compute/virtualMachines/LTO-CT-SQL/extensions/</font><span><font style="font-size: 9pt;background-color: #ffff00">SqlIaasExtension</font></span></font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">• STATUSMESSAGE</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font color="#ff0000"><font style="font-size: 9pt">{ "status": </font><span><font style="font-size: 9pt;background-color: #ffff00">"Failed", "error": { "code": "ResourceDeploymentFailure", "message": "The resource operation completed with terminal provisioning state 'Failed'.", "details": [ { "code": "VMExtensionHandlerNonTransientError", "message": "Handler 'Microsoft.SqlServer.Management.SqlIaaSAgent' has reported failure for VM Extension 'SqlIaasExtension' with terminal error code '1009' and error message: 'Enable failed for plugin (name: Microsoft.SqlServer.Management.SqlIaaSAgent, version 1.2.10.0) with exception Command C:\\Packages\\Plugins\\Microsoft.SqlServer.Management.SqlIaaSAgent\\1.2.10.0\\enable.cmd of Microsoft.SqlServer.Management.SqlIaaSAgent has exited with Exit code: 255'" } ] } }</font></span></font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt;background-color: #ffff00" color="#ff0000">• RESOURCE</font></font></span><span style="font-family:;color:"></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">LTO-CT-SQL/SqlIaasExtension</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">• OPERATION ID</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">B3B967D4EF42741A</font></font></span></p> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span>Cause </span></h2> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span><font face="Segoe UI"><font style="font-size: 10.5pt" color="#000000">SQL IAAS Agent Service was disabled and did not starts due to insufficient permissions.</font></font></span></h2> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span>Resolution</span></h2> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span><font face="Segoe UI"><font style="font-size: 10.5pt" color="#000000">To reproduce the issue,</font></font></span></h2> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span><font face="Segoe UI"><font style="font-size: 10.5pt" color="#000000">We deployed a VM on our end and navigated to VM &gt; SQL Server Configuration&gt; Automated Backup and this failed with a similar error:</font></font></span></h2> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span><a href="https://msdnshared.blob.core.windows.net/media/2017/01/clip_image00241.jpg"><img title="clip_image002[4]" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;padding-top: 0px;padding-left: 0px;margin: 0px;padding-right: 0px;border-top-width: 0px" border="0" alt="clip_image002[4]" src="https://msdnshared.blob.core.windows.net/media/2017/01/clip_image0024_thumb.jpg" width="576" height="634"></a></span><span></span></h2> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><span><font face="Segoe UI"><font style="font-size: 10.5pt">&nbsp;</font></font></span></h2> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">Error", "message": "Handler <span><font style="background-color: #ffff00">'Microsoft.SqlServer.Management.SqlIaaSAgent' has</font></span> reported failure for VM Extension 'SqlIaasExtension' with terminal error code '1009' and error message: 'Enable failed for plugin (name: Microsoft.SqlServer.Management.SqlIaaSAgent, version 1.2.10.0) with exception </font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">statusMessage:{"status":"Failed","error":{"code":"ResourceDeploymentFailure","message":"The resource operation completed with terminal provisioning state 'Failed'.","details":[{"code":"VMExtensionHandlerNonTransientError","message":"Handler 'Microsoft.SqlServer.Management.SqlIaaSAgent' has <span><font style="background-color: #ffff00">reported failure for VM Extension 'SqlIaasExtension' with terminal error code '1009' and error message: 'Enable failed for plugin (name: Microsoft.SqlServer.Management.SqlIaaSAgent, version 1.2.10.0) with exception Command C:\\Packages\\Plugins\\Microsoft.SqlServer.Management.SqlIaaSAgent\\1.2.10.0\\enable.cmd</font></span> of Microsoft.SqlServer.Management.SqlIaaSAgent has exited with Exit code: -532462766'"}]}}</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="color:"><font face="Calibri"><font style="font-size: 11pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal">We then went to the VM and checked the event viewer application and system logs and found the below errors:</p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font color="#000000">&nbsp;</font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">The Microsoft SQL Server IaaS Agent service failed to start due to the following error: </font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">The service did not start due to a logon failure.</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">The SQLIaaSExtension service was unable to log on as <span><font style="background-color: #ffff00">NT Service\SQLIaaSExtension with the currently configured password</font></span> due to the following error: </font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">Logon failure: the user has not been granted the requested logon type at this computer.</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">Service: SQLIaaSExtension </font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">Domain and account: NT Service\SQLIaaSExtension</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font style="font-size: 9pt" color="#ff0000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font face="Courier New"><font color="#ff0000"><font style="font-size: 9pt">This service </font><span><font style="font-size: 9pt;background-color: #ffff00">account does not have the required user right "Log on as a service."</font></span></font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="color:"><font face="Calibri"><font style="font-size: 11pt" color="#000000">&nbsp;</font></font></span></p> <p>The above clearly indicates that SQLIAASEXTENSION account needs to have the permissions in security policy.</p> <p>We went to Run&gt; Secpol.msc&gt; Under Security settings looked for Local Policies &gt; User Rights Assignment &gt; Log on as a service (In right pane) &gt;Right click and go to its properties and this account with Admin permissions<br></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:"><font color="#000000"></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="color:"><font face="Calibri"><font style="font-size: 11pt" color="#000000">&nbsp;</font></font></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><a href="https://msdnshared.blob.core.windows.net/media/2017/01/clip_image00341.jpg"><img title="clip_image003[4]" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;padding-top: 0px;padding-left: 0px;margin: 0px;padding-right: 0px;border-top-width: 0px" border="0" alt="clip_image003[4]" src="https://msdnshared.blob.core.windows.net/media/2017/01/clip_image0034_thumb.jpg" width="624" height="232"></a><span style="color:"></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="color:"><font face="Calibri"><font style="font-size: 11pt" color="#000000">&nbsp;</font></font></span></p> <p>We then again tried to create automated backup and did not see the error in event viewer.</p> <p>Now to figure out where is this account used, we looked at services.msc and found the account is used by Microsoft SQL IAAS Agent service. </p> <p>We saw the service is in a stopped state.</p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><a href="https://msdnshared.blob.core.windows.net/media/2017/01/clip_image00441.jpg"><img title="clip_image004[4]" style="border-left-width: 0px;border-right-width: 0px;border-bottom-width: 0px;padding-top: 0px;padding-left: 0px;padding-right: 0px;border-top-width: 0px" border="0" alt="clip_image004[4]" src="https://msdnshared.blob.core.windows.net/media/2017/01/clip_image0044_thumb.jpg" width="624" height="67"></a><span style="color:"></span></p> <p class="MsoNormal" style="margin: 0cm 0cm 0pt;line-height: normal"><span style="color:"><font face="Calibri"><font style="font-size: 11pt" color="#000000">&nbsp;</font></font></span></p> <p>Now researching on this, we found SQL Server IAAS Agent service can help us to automate some administrative tasks, for example run jobs, monitors SQL Server, and processes alerts. When we enable Automated Backup on virtual machine, the extension will be automatically installed but somehow it didn’t start in our scenario due to the account permission issues.We started the service and then tried to configure the automated backups from the azure portal and saw it completed successfully without any errors.</p> <p>In case if it still fails even after that then the next step is to Look at the locations <strong>C:\WindowsAzure\Logs </strong>and <strong>C:\Packages\Plugins</strong> for any errors in the IAAS VM.</p> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><font face="Segoe UI"><b><u><span><font style="font-size: 10.5pt">More Information:</font></span></u></b><span><font style="font-size: 10.5pt"> </font></span></font></h2> <p>We require the Microsoft SQL IAAS Agent service in running state for enabling automated backups and its functioning. When we enable Automated Backup on our virtual machine, the extension will be automatically installed.</p> <p>Automated Backup automatically configures Managed Backup to Microsoft Azure for all existing and new databases on an Azure VM running SQL Server 2014 Standard or Enterprise. This enables us to configure regular database backups that utilize durable Azure blob storage. Automated Backup depends on the SQL Server IaaS Agent Extension.</p> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><font face="Segoe UI"><font color="#000000"><span lang="EN"><font style="font-size: 10.5pt"></font></span><span></span></font></font></h2> <h2 style="background: white;margin: 15pt 0cm 7.5pt;line-height: normal"><b><u><span><font face="Segoe UI"><font style="font-size: 10.5pt">Related articles:</font></font></span></u></b></h2> <p class="MsoNormal" style="background: white;margin: 0cm 0cm 0pt;line-height: normal"><span style="font-family:;color:">More information on Automated Backups: </span><a><span style="font-family:"><font color="#0563c1"><u>https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-sql-automated-backup/</u></font></span></a><span style="font-family:;color:"> </span></p> <p><span style="font-family:;color:;line-height: normal">More information on IAAS Agent Service: </span><span style="font-family:;line-height: normal"><a href="https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-sql-server-agent-extension/"><span style="font-family:"><font color="#0563c1"><u>https://azure.microsoft.com/en-in/documentation/articles/virtual-machines-windows-sql-server-agent-extension/</u></font></span></a></span></p> <p><strong><font size="3">Written by – Ujjwal Patel, Support Engineer. </font></strong></p> <p><strong><font size="3">Reviewed by – Raghavendra, , Sr. Support Engineer.</font></strong></p>]]></content:encoded>
    </item>
    <item>
      <title>Automate SQL server backup file removal/deletion from Azure blob storage</title>
      <link>https://docs.microsoft.com/archive/blogs/ujpat/automate-sql-server-backup-file-removaldeletion-from-azure-blob-storage</link>
      <pubDate>Thu, 19 Jan 2017 07:48:35 GMT</pubDate>
      <dc:creator><![CDATA[Ujjwal Patel]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/ujpat/?p=55</guid>
      <description><![CDATA[&nbsp;

In this post, we would like to explain one of the interesting issues that we encountered...]]></description>
      <content:encoded><![CDATA[&nbsp;

In this post, we would like to explain one of the interesting issues that we encountered while working with azure backups and restore.

<span style="font-family: segoe ui light;font-size: xx-large">Symptoms</span>

Cannot delete the .bak files from azure blob storage through maintenance plans or any other options from SQL which have been backed up using backup to URL or managed backup.

<span style="font-family: segoe ui light;font-size: xx-large">Cause </span>

No Such functionality available where you can delete all backup files which are less than one week/two weeks’ old from SQL.

<span style="font-family: segoe ui light;font-size: xx-large">Resolution    </span>

You can backup and restore using maintenance plans to azure blob storage but you cannot use the maintenance cleanup task to clear the data from blob storage like you can do for your on premise.

The only way out to achieve this is by using PowerShell script. We developed the below script which will delete the files which have been modified earlier than one day in the below script from the date it’s called. The date can be changed 1 day to any number needed per requirements. In the below example, we have deleted the files which are older than one day.

We created a new storage account for testing this by using the below script. Please test this before deploying( This will delete all files with all extensions from blob storage)

[code language="powershell"]
CLS
$Days =7 # for file older than 7 days
$backuptype = &quot;bak&quot;  # for file extension .BAK
#$backuptype = &quot;trn&quot; # for file extension .trn
$container=&quot;backup&quot;
$StorageAccountName=&quot;agdiag558&quot;
$StorageAccountKey=&quot;qZ8Q3Sj6jnsxLx4oN2eWDyEGhDIdQEOlO4URX/a3Uk3goHtm/eWiLMslLowCxA+WvfxnGiz6STvI9B7Kx4YsRQ==&quot;
$context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
$filelist = Get-AzureStorageBlob -Container $container -Context $context
$filelist = $filelist  | Where-Object {$_.Name -like '*.'+$backuptype}
foreach ($file in $filelist | Where-Object {$_.LastModified.DateTime -lt ((Get-Date).AddDays(-$Days))})
{
     if ($file.Name -ne $null)
     {
     Write-Host &quot;Removing file: $file.Name&quot;
     Remove-AzureStorageBlob -Blob $file.Name -Container $container -Context $context
     $flag=1
     }
}
if ($flag -eq 0 -or $flag -eq $null) { Write-Host &quot;No files found which are older than:&quot;,(Get-Date).AddDays(-$Days)}
[/code]

<span style="font-family: segoe ui light;font-size: xx-large">Sample Output:</span>

<a href="https://msdnshared.blob.core.windows.net/media/2018/04/clip_image00218.jpg"><img width="728" height="348" title="clip_image002" alt="clip_image002" src="https://msdnshared.blob.core.windows.net/media/2018/04/clip_image002_thumb17.jpg" border="0" /></a>

You can alternatively use the below script which also does the same job:
[code language="powershell"]
$CleanupTime = [DateTime]::UtcNow.AddHours(-72)
$context = New-AzureStorageContext -StorageAccountName ujpat2012test -StorageAccountKey zImjHXPe8aK5eY8CJnjSPdy8HcWHLG6dmtaamTkMa1jlzthICNAIhEGAvzLJV1FBi+V/3XNdAhrAZP5Dadsaii+A==
Get-AzureStorageBlob -Container &quot;sqlbackup&quot; -Context $context | Where-Object { $_.LastModified.UtcDateTime -lt $CleanupTime -and $_.BlobType -eq &quot;PageBlob&quot; -and $_.Name -like &quot;*.bak&quot;} |Remove-AzureStorageBlob
[/code]

<strong>Written by – Ujjwal Patel, Support Engineer.</strong>

<strong>Reviewed by – Raghavendra Srinivasan , Support Escalation Engineer.</strong>]]></content:encoded>
    </item>
  </channel>
</rss>