开发者

Automating the creation of a SQL Server Alias on a Client's desktop

开发者 https://www.devze.com 2023-03-28 12:45 出处:网络
Does anyone know how would I go about automating the creation of an alias for a client that uses SQL Server (something you would normally use Sql Server Client N开发者_运维知识库etwork Utility to do m

Does anyone know how would I go about automating the creation of an alias for a client that uses SQL Server (something you would normally use Sql Server Client N开发者_运维知识库etwork Utility to do manually)?

Many thanks


The aliases are stored in the registry, so a registry file would do the trick. Some options

  • deploy a .reg file for the user to double-click
  • use remote registry to create the entry
  • in your setup utility, include the register entry
  • etc


Here's a base BAT script that I use as a starting point:

set DBSERVERALIAS=AliasName
set DBSERVER=RealServerName
rem %windir%\system32\cliconfg.exe
reg add HKLM\Software\Microsoft\MSSQLServer\Client\ConnectTo /v %DBSERVERALIAS% /t REG_SZ /d "DBMSSOCN,%DBSERVER%" /f
reg query HKLM\Software\Microsoft\MSSQLServer\Client\ConnectTo
rem 64-bit support for database alias
rem %windir%\SysWOW64\cliconfig.exe
if /i NOT "%PROCESSOR_ARCHITECTURE%" == "X86" (
    reg add HKLM\Software\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo /v %DBSERVERALIAS% /t REG_SZ /d "DBMSSOCN,%DBSERVER%" /f
    reg query HKLM\Software\Wow6432Node\Microsoft\MSSQLServer\Client\ConnectTo

)


Can you not use DNS to avoid an alias on each client machine? So if anything changes it's one DNS CNAME change rather then updating every client?

An example here: One SQL Server Instance, Two Server Names

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号