<?xml version="1.0" encoding="UTF-8"?><item><title>Moving SQL Server databases</title><description>&lt;P&gt;I spent a lot of last night and this morning moving an SQL Server database from one computer to another.&amp;nbsp; This is much more complex than it needs to be.&lt;/P&gt;&#13;
&lt;P&gt;I'm using &lt;A href="http://www.rainbowportal.net"&gt;Rainbow&lt;/A&gt; as a portal engine, and I'm using the &lt;A href="http://yetanotherforum.net"&gt;yetanotherforum.net&lt;/A&gt; forum engine and a few other pieces of software.&amp;nbsp; I set up SQL Server a long time ago and I decided to move the database to a different computer.&amp;nbsp; &lt;/P&gt;&#13;
&lt;P&gt;Here are some of the issues, and the solutions I found:&lt;/P&gt;&#13;
&lt;UL&gt;&#13;
&lt;LI&gt;When you install MSDE, it defaults to not having any network connectivity.&amp;nbsp; I guess this is a good thing, except when you're trying to connect to it over a network.&amp;nbsp; No problem, run the &amp;#8220;srvnetcn.exe&amp;#8221; tool that comes with MSDE and enable the protocols you like.&lt;BR&gt;&lt;/LI&gt;&#13;
&lt;LI&gt;I tried to use the &amp;#8220;Copy Database Wizard&amp;#8221; but had zero luck with it.&amp;nbsp; It would lock up and not actually do anything.&amp;nbsp; Probably something misconfigured, but still, it didn't help me find out what was wrong.&amp;nbsp; I never did end up getting it to work.&lt;/LI&gt;&lt;/UL&gt;&#13;
&lt;P&gt;I ended up using Backup and Restore to get the job done.&amp;nbsp; Backup is simple enough - the SQL Server Enterprise Manager makes it really easy to backup and restore databases, so I asked it to backup to a file, and it did. I copied the file over to the other computer, and tried to restore.&amp;nbsp; This led to:&lt;/P&gt;&#13;
&lt;UL&gt;&#13;
&lt;LI&gt;When you make a backup of a database, the file location where the database originally lived is apparently stored in the backup.&amp;nbsp; Trying to restore using the Enterprise Manager led to errors that the physical path to the database files that worked on the original server didn't work on the new server.&amp;nbsp; &lt;BR&gt;&lt;BR&gt;To get around this I had to manaually execute the SQL to restore my database.&amp;nbsp; Here's what it ended up being:&lt;BR&gt;&amp;nbsp;&#13;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;RESTORE DATABASE Rainbow&lt;/P&gt;&#13;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;FROM DISK = 'e:\Rainbow.bkp'&lt;/P&gt;&#13;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;WITH RECOVERY, &lt;/P&gt;&#13;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt;MOVE 'Rainbow' TO 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\Rainbow.mdf', &lt;/P&gt;&#13;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; mso-outline-level: 2"&gt;MOVE 'Rainbow_log' TO 'D:\Program Files\Microsoft SQL Server\MSSQL\Data\Rainbow_log.ldf', file = 2&lt;/P&gt;&lt;BR&gt;The MOVE clauses are what tells it the physical location for the files in the backup.&amp;nbsp; &lt;BR&gt;&lt;BR&gt;The 'file = 2' says that the backup to be restored is the 2nd backup in the file.&amp;nbsp;&amp;nbsp;The first time I&amp;nbsp;did this I assumed it would restore the most recent backup in the file, but no, it defaults to restoring the first backup it finds, so I had a nice working&amp;nbsp;copy of my site from some time ago.&amp;nbsp; Doh!&lt;/LI&gt;&lt;/UL&gt;&#13;
&lt;P&gt;I had another problem that ended up being related to permissions - some tables belonged to the wrong owner.&amp;nbsp; This caused Rainbow to start up and connect to the database, but decide it needed to be set up.&amp;nbsp; To get around this, I&amp;nbsp;found an SQL script that sets the owner of every&amp;nbsp;user object to 'dbo'.&amp;nbsp; Very useful.&amp;nbsp; You can find it &lt;A href="http://www.rainbowportal.net/Rainbow/DesktopModules/Articles/ArticlesView.aspx?TabID=0&amp;amp;Alias=Rainbow&amp;amp;Lang=en-US&amp;amp;ItemID=36&amp;amp;mid=10440"&gt;here&lt;/A&gt;.&amp;nbsp; Most of the problems I've had moving databases around with SQL Server&amp;nbsp;end up being related to permissions, so this is a very useful script to have around.&lt;/P&gt;&#13;
&lt;P&gt;I've&amp;nbsp;moved about half my databases to the other computer so far; it's painful because once I've moved it, I have to&amp;nbsp;hunt down connection strings in the various&amp;nbsp;applications that connect to the databases, but I'm getting there.&lt;/P&gt;&#13;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description><pubDate>Thu, 01 Sep 2005 19:17:07 GMT</pubDate></item>