locked
Is scripting a SQL Server alias possible? RRS feed

  • Question

  • I'm not sure which forum is best to ask this, but I want to know if it is possible to script the crreation of SQL Server aliases?  I know how to set them up in configuration manager, but I want to script it somehow.

    Thanks!


    Clint
    Monday, April 19, 2010 3:38 PM

Answers

  • Unfortunately, it does not look like SMO provides the abstraction for adding aliases to a client.  This is probably reasonable, since SMO is only installed with the database engine.  The clients don't seem to provide a simple function to script this either.  However, there is always regedit and an alias is just a registry entry like this:

    HKLM\SOFTWARE\Microsoft\MSSQLServer\Client\ConnectTo\[ALIAS NAME] {value = PROTLIB, SERVER, ADDTL}

    {and the WoW equivalent}

    where PROTLIB is one of:

    DBMSSOCN -- tcp

    DBNMPNTW -- named pipes

     

    for TCP, just do DBMSSOCN, server, port

    for NP, just do DBMNMPNTW, pipename (i.e. \\server\PIPE\sql\query)

     

    If you just jam that registry key in, you should see the alias show up in Configuration Manager and your apps should see it.  Remember to consider both 64 and 32 bit registry hives, though.

     

    Hope that helps,

     

    John


    This post is provided 'as is' and confers no express or implied warranties or rights.
    Monday, April 19, 2010 9:14 PM