Create Alias in Microsoft SQL Server Configuration Manager using batch file

 

In this article we discuss about how to create alias to Microsoft SQL Server from client computer by using SQL Server Configuration Manager. Aliases can be used from any client applications. By using aliases we can connect to multiple servers using different network protocols, without having to specify the protocol and connection details for each.

In this article we discuss about how to create Alias for Microsoft SQL Server from client machine SQL Configuration Manager.

Open Microsoft SQL Server Configuration Manager => Expand SQL Native Client 11.0 Configuration, right click on Aliases and select “New Alias” as shown below. Here we have two SQL Native Client 11.0 Configurations, one is for 32-bit & another is for 64-bit.

             

Enter alias name, port, and server as per your requirements. Here we enter alias as “AliasServer”, port as 5562, and Server as 10.218.79.42 as shown below and click on Ok.

                            

Now connect to 10.218.79.42 server by entering alias name as AliasServer in SQL Server Management studio as shown below.

                             

Sometimes we may have requirement to create Alias programmatically. For example if we have many users for our Microsoft SQL Server and if we want to create alias for our Server in all users machines, it is very tedious process to create alias manually. In this type situation we can create alias programmatically through command prompt as shown below.

REGEDIT4

 

; @ECHO OFF

; CLS

; REGEDIT.EXE /S "%~f0"

; EXIT

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo]

"[AliasName]"="DBMSSOCN,[Server],[Port]"

 

Place this code in notepad and save it as batch file like install.bat. Replace AloasName, Server, and Port details as per your requirements as shown below.

REGEDIT4

 

; @ECHO OFF

; CLS

; REGEDIT.EXE /S "%~f0"

; EXIT

 

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo]

"[AliasServer]"="DBMSSOCN,10.218.79.425562"

 

Save this as .bat file and Run this batch file in all users machines, it creates the alias for 10.218.79.42 server with alias name as AliasServer.