{"id":163,"date":"2012-06-13T01:11:46","date_gmt":"2012-06-12T19:11:46","guid":{"rendered":"http:\/\/markwheeler.com\/wordpress\/?p=163"},"modified":"2012-06-13T01:11:46","modified_gmt":"2012-06-12T19:11:46","slug":"rename-sql-server-2008-r2-reporting-server-databases","status":"publish","type":"post","link":"https:\/\/www.markwheeler.com\/?p=163","title":{"rendered":"Rename SQL Server 2008 R2 Reporting Server Databases"},"content":{"rendered":"<p>Had a task to move the default SQL Reporting Services ReportServer and ReportServerTempDB databases to a new SQL cluster which required a rename to avoid any potential conflicts.<\/p>\n<p>These instance of the databases are being used in Sharepoint-Integrated Mode. You could do Step 7 below before you do Steps 4 &#8211; 6.<\/p>\n<p>1. Stop old SSRS<\/p>\n<p>2. Detach ReportServer, ReportServerTempDB<\/p>\n<p>3. Rename the MDF\/LDF files; in this case ReportServer_MySite, ReportServer_MySiteTempDB<\/p>\n<p>4. Copy\/Attach these databases into new SQL server.<\/p>\n<p>5. In my case, SSRS is Sharepoint-Integrated. In Central Admin; modify your Reporting Services integration as applicable.<\/p>\n<p>6. Make sure new SSRS Configuration Manager is pointing to new database names.<\/p>\n<p>7. Drop\/Create script all Stored Procedures and the ExtendedCatalog Function and the ExtendedDatasource and Extended DataSet views.<\/p>\n<p>Now for happy fun-time.<\/p>\n<p>If it&#8217;s not enabled already; enable xp_cmdshell<\/p>\n<p>EXECUTE SP_CONFIGURE &#8216;show advanced options&#8217;, 1<br \/>\nRECONFIGURE WITH OVERRIDE<br \/>\nGO<\/p>\n<p>EXECUTE SP_CONFIGURE &#8216;xp_cmdshell&#8217;, &#8216;1&#8217;<br \/>\nRECONFIGURE WITH OVERRIDE<br \/>\nGO<\/p>\n<p>EXECUTE SP_CONFIGURE &#8216;show advanced options&#8217;, 0<br \/>\nRECONFIGURE WITH OVERRIDE<br \/>\nGO<\/p>\n<p>Execute the following Stored Procedure &#8220;FindandReplace&#8221;; this will find all references to your old ReportServerTempDB in the existing Stored Procedures in ReportServer.<\/p>\n<p>USE [ReportServer_MySite]<br \/>\nGO<\/p>\n<p>\/****** Object: StoredProcedure [dbo].[FindAndReplace] Script Date: 06\/12\/2012 14:00:02 ******\/<br \/>\nSET ANSI_NULLS ON<br \/>\nGO<\/p>\n<p>SET QUOTED_IDENTIFIER ON<br \/>\nGO<br \/>\nCREATE procedure [dbo].[FindAndReplace]<br \/>\n(<br \/>\n@filepath varchar(500) =&#8217;c:temp&#8217;, &#8212; output filepath<br \/>\n@myfind varchar(500) = &#8216;ReportServerTempDB&#8217;, &#8212; keyword to be found<br \/>\n@myreplace varchar(500) = &#8216;ReportServer_MySiteTempDB&#8217; &#8212; replacement word<br \/>\n)<br \/>\nas<br \/>\nset nocount on<br \/>\ndeclare @cmd varchar(8000), @myobject_id int, @myproc varchar(100), @checksum0 int, @checksum1 int<\/p>\n<p>\/*<br \/>\nProcedure to identify any stored procedures, in a given database, with a given keyword<br \/>\nBCPs an &#8220;alter&#8221; script to modify the proc with the replacement word<br \/>\nAlso BCPs generates a &#8220;backup&#8221; script<br \/>\nCompatible with SQL2005 only<br \/>\nLouis Nguyen 2008<br \/>\n*\/<\/p>\n<p>&#8212; BCP requires permanent tables<br \/>\ncreate table temptable0 (definition nvarchar(max))<br \/>\ncreate table temptable1 (definition nvarchar(max))<\/p>\n<p>&#8212; init filepath<br \/>\nif right(@filepath,1) &lt;&gt; &#8221;<br \/>\nselect @filepath = @filepath + &#8221;<\/p>\n<p>&#8212; cursor over procedures<br \/>\ndeclare mycur cursor fast_forward for<br \/>\nselect b.object_id, a.name<br \/>\nfrom sys.objects a<br \/>\njoin sys.sql_modules b<br \/>\non a.type=&#8217;p&#8217; and a.object_id = b.object_id<br \/>\nwhere a.name &lt;&gt; &#8216;FindAndReplace&#8217;<br \/>\nopen mycur<br \/>\nfetch next from mycur into @myobject_id, @myproc<\/p>\n<p>&#8212; begin cursor<br \/>\nwhile @@fetch_status = 0 begin<\/p>\n<p>&#8212; write to permanent table(s)<br \/>\ndelete temptable0<br \/>\ninsert temptable0(definition)<br \/>\nselect definition from sys.sql_modules<br \/>\nwhere object_id= @myobject_id<\/p>\n<p>delete temptable1<br \/>\ninsert temptable1(definition)<br \/>\nselect replace(definition,@myfind,@myreplace) from sys.sql_modules<br \/>\nwhere object_id= @myobject_id<\/p>\n<p>&#8212; compare checksums<br \/>\nselect @checksum0=checksum(definition) from temptable0<br \/>\nselect @checksum1=checksum(definition) from temptable1<\/p>\n<p>if @checksum0&lt;&gt;@checksum1 begin<\/p>\n<p>print &#8216;!! MATCH FOUND: &#8216; + @myproc<\/p>\n<p>&#8212; bcp out unadulterated contents<br \/>\nselect @cmd=&#8217;bcp &#8220;select definition from &#8216;+db_name()+&#8217;..temptable0&#8221; queryout &#8220;&#8216;<br \/>\n+@filepath<br \/>\n+replace(@@servername,&#8221;,&#8217;_&#8217;) +&#8217;_&#8217; +db_name()<br \/>\n+&#8217;____&#8217;+@myproc + &#8216;.sql&#8217;<br \/>\n+&#8217;.backup&#8221;&#8216;<br \/>\n+&#8217; -S&#8217;+@@servername<br \/>\n+&#8217; -T -c&#8217;<br \/>\nexec master.dbo.xp_cmdshell @cmd, no_output<\/p>\n<p>&#8212; add use database &amp; drop procedure to beginning of file<br \/>\ndelete temptable1<br \/>\ninsert temptable1<br \/>\nselect &#8216;use [&#8216;+db_name()+&#8217;]&#8217;<br \/>\nunion all<br \/>\nselect &#8216;go&#8217;<br \/>\nunion all<br \/>\nselect &#8216;drop procedure [&#8216;+@myproc +&#8217;]&#8217;<br \/>\nunion all<br \/>\nselect &#8216;go&#8217;<br \/>\nunion all<br \/>\nselect replace(definition,@myfind,@myreplace) from temptable0<\/p>\n<p>&#8212; bcp out modified contents<br \/>\nselect @cmd=&#8217;bcp &#8220;select definition from &#8216;+db_name()+&#8217;..temptable1&#8221; queryout &#8220;&#8216;<br \/>\n+@filepath<br \/>\n+replace(@@servername,&#8221;,&#8217;_&#8217;) +&#8217;_&#8217; +db_name()<br \/>\n+&#8217;____&#8217;+@myproc + &#8216;.sql&#8217;<br \/>\n+'&#8221;&#8216;<br \/>\n+&#8217; -S&#8217;+@@servername<br \/>\n+&#8217; -T -c&#8217;<br \/>\nexec master.dbo.xp_cmdshell @cmd, no_output<\/p>\n<p>end<br \/>\nelse begin<br \/>\nprint &#8216;No match found: &#8216; + @myproc<br \/>\nend<\/p>\n<p>&#8212; end cursor<br \/>\nfetch next from mycur into @myobject_id, @myproc<br \/>\nend<br \/>\nclose mycur<br \/>\ndeallocate mycur<\/p>\n<p>&#8212; cleanup<br \/>\ndrop table temptable0<br \/>\ndrop table temptable1<\/p>\n<p>GO<\/p>\n<p>Once the SP is created; Execute it.<\/p>\n<p>You will be prompted for a temporary path, eg. C:temp and your string to look for: &#8220;ReportServerTempDB&#8221; and the value you want to change it to: &#8220;ReportServer_MySiteTempDB&#8221;<\/p>\n<p>This will backup existing SPs and create new SPs scripts with the new value.<\/p>\n<p>From C:temp call all the new scripts into SQL Management Studio and execute.<\/p>\n<p>You will manually need to modify the Function and View mentioned above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Had a task to move the default SQL Reporting Services ReportServer and ReportServerTempDB databases to a new SQL cluster which required a rename to avoid any potential conflicts. These instance of the databases are being used in Sharepoint-Integrated Mode. You could do Step 7 below before you do Steps 4 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[2,11],"tags":[105,106,111],"class_list":["post-163","post","type-post","status-publish","format-standard","hentry","category-computer","category-software","tag-sql-2008-r2","tag-sql-reporting-services","tag-ssrs"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=163"}],"version-history":[{"count":0,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}