A Rose by Any Other Name..
Posted
by Geoff N. Hiten
on SQL Team
See other posts from SQL Team
or by Geoff N. Hiten
Published on Tue, 29 Nov 2011 14:45:36 GMT
Indexed on
2011/11/29
17:55 UTC
Read the original article
Hit count: 635
It is always a good start when you can steal a title line from one of the best writers in the English language. Let’s hope I can make the rest of this post live up to the opening.
One recurring problem with SQL server is moving databases to new servers. Client applications use a variety of ways to resolve SQL Server names, some of which are not changed easily <cough SharePoint /cough>. If you happen to be using default instances on both the source and target SQL Server, then the solution is pretty simple. You create (or bug the network admin until she creates) two DNS “A” records. One points the old name to the new IP address. The other creates a new alias for the old server, since the original system name is now redirected. Note this will redirect ALL traffic from the old server to the new server, including RDP and file share connection attempts.
Figure 1 – Microsoft DNS MMC Snap-In
Figure 2 – DNS New Host Dialog Box
Both records are necessary so you can still access the old server via an alternate name.
Server Role | IP Address | Name | Alias |
Source | 10.97.230.60 | SQL01 | SQL01_Old |
Target | 10.97.230.80 | SQL02 | SQL01 |
Table 1 – Alias List
If you or somebody set up connections via IP address, you deserve to have to go to each app and fix it by hand. That is the only way to fix that particular foul-up.
If have to deal with Named Instances either as a source or a target, then it gets more complicated. The standard fix is to use the SQL Server Configuration Manager (or one of its earlier incarnations) to create a SQL client alias to redirect the connection. This can be a pain installing and configuring the app on multiple client servers. The good news is that SQL Server Configuration Manager AND all of its earlier versions simply write a few registry keys. Extracting the keys into a .reg file makes centralized automated deployment a snap.
If the client is a 32-bit system, you have to extract the native key. If it is a 64-bit, you have to extract the native key and the WoW (32 bit on 64 bit host) key.
First, pick a development system to create the actual registry key. If you do this repeatedly, you can simply edit an existing registry file. Create the entry using the SQL Configuration Manager. You must use a 64-bit system to create the WoW key. The following example redirects from a named instance “SQL01\SQLUtiluty” to a default instance on “SQL02”.
Figure 3 – SQL Server Configuration Manager - Native
Figure 3 shows the native key listing.
Figure 4 – SQL Server Configuration Manager – WoW
If you think you don’t need the WoW key because your app is 64 it, think again. SQL Server Management Server is a 32-bit app, as are most SQL test utilities. Always create both keys for 64-bit target systems.
Now that the keys exist, we can extract them into a .reg file. Fire up REGEDIT and browse to the following location: HKLM\Software\Microsoft\MSSQLServer\Client\ConnectTo. You can also search the registry for the string value of one of the server names (old or new).
Right click on the “ConnectTo” label and choose “Export”. Save with an appropriate name and location. The resulting file should look something like this:
Figure 5 – SQL01_Alias.reg
Repeat the process with the location: HKLM\Software\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo
Note that if you have multiple alias entries, ALL of the entries will be exported. In that case, you can edit the file and remove the extra aliases.
You can edit the files together into a single file. Just leave a blank line between new keys like this:
Figure 6 – SQL01_Alias_All.reg
Of course if you have an automatic way to deploy, it makes sense to have an automatic way to Un-deploy. To delete a registry key, simply edit the .reg file and replace the target with a “-“ sign like so.
Figure 7 – SQL01_Alias_UNDO.reg
Now we have the ability to move any database to any server without having to install or change any applications on any client server. The whole process should be transparent to the applications, which makes planning and coordinating database moves a far simpler task.
© SQL Team or respective owner