11 Feb 2008

How To: Change Instance Name Of SQL Server

27 Comments Uncategorized

Recently I change the network name of one of my servers at work, because the box changed its job from a virtual machine server to the database server. Everything was going great until I decided to setup the server for replication and received the following error message.

New Publication Wizard
——————————

SQL Server replication requires the actual server name to make a connection to the server. Connections through a server alias, IP address, or any other alternate name are not supported. Specify the actual server name, ‘old_name’. (Replication.Utilities)

——————————
OK
——————————

So with a little hunting and SQL queries I found out that SQL Server doesn’t use the network name, it only excepts that as an alias. My SQL Server instance was still named “old_name”. I found that out by running these two queries:

sp_helpserver
select @@servername

So in order to get the network name and the SQL Server instance name back in sync I had do these steps:

  1. Run this in Microsoft SQL Server Management Studio:
    sp_dropserver 'old_name'
    go
    sp_addserver 'new_name','local'
    go
  2. Restart SQL Server service. I prefer the command prompt for this, but you can just as easily do it in Services under the Control Panel
    net stop mssqlserver
    net start mssqlserver

Then after that is done run this again, to make sure everything is changed:

sp_helpserver
select @@servername

I don’t understand why SQL Server uses it’s own name versus the network name, might be due to the fact you can have multiple SQL Server instances install on one machine. It wasn’t too hard to change and probably stems from the days when SQL Server was known as Sybase, all in all, I learned something new and it only took 30 minutes of my day to fine the answer.

Tags: , , , , ,
written by
Nick Berardi
subscribe
If you found this post valuable and would like to see more like it you can follow me.

27 Responses to “How To: Change Instance Name Of SQL Server”

  1. Reply Greg Harris says:

    Well lucky for me you found it a few months before I needed it. It only took me 5 minutes on Google to find your post.

    Thanks!!!

  2. Reply Ramy Mahrous says:

    Thank you so much, it really helped me :)

  3. Reply Satish says:

    Hi

    I did previously but it won’t worked, and then i did it by cool mind using same procedure, then it worked for me.Thank you so much.

    Thank you
    Satish

  4. Reply blase says:

    The “# select @@servername” tells it is changed, but the ssms not, and I can only connect to it with the old name.
    regards

  5. Reply Rao says:

    Hi

    Are you using SQL express edition?
    regards

  6. Reply amj says:

    You are not changing the instance name, you are only changing the computer’s name. You need to change the title of this post and change reference to “network name” to “computer name”.

    http://msdn.microsoft.com/en-us/library/ms143799.aspx

  7. Reply Nick Berardi says:

    Thanks amj,

    You are right, I changed my computer name, which is the same as my network name. So that is not wrong, because I was describing my situation. I clarified that later on, by saying “SQL Server doesn’t use the network name, it only excepts that as an alias”. And then when on to describe how to change the server name.

    I make it a policy to not modify posts, I don’t consider my blog a wiki, so everything written is a glimpse in to a point of time in my life.

    Thanks for you input,
    Nick Berardi

  8. Reply Thangnc says:

    Thanks Nick,

    It’s great!

  9. Reply RelentlessMike says:

    Nick,

    “amj” is correct, the title is misleading. I found my way to this post when looking for information on what the ramifications of changing the instance name of SQL Server, and the title definitely implies that this post has to do with changing the instance name. I mean look at it – “How To: Change Instance Name Of SQL Server”

    Having said that, I like your below statement. A lot.

    “I make it a policy to not modify posts, I don’t consider my blog a wiki, so everything written is a glimpse in to a point of time in my life.”

    I like the honesty that this gives your post, even if it is misleading, and I like it. :)

  10. Reply Jitesh says:

    Great it work fine.

  11. Reply Keny says:

    Thnx … It’s work for me.

  12. Reply Eric says:

    This is exactly what I needed. There were a ton of other things I found on Google but all were more complex and none worked. Thanks. By the way I’m adding this in case it helps others in searches: Amazon Web Services AWS EC2. Thanks.

  13. Reply Michael B says:

    Does it affect all the database objects, e.g. databases, users, maintenance plans, etc.? Thanx!

  14. Reply James says:

    This might help some of you:

    When you have more than one instance of SQL Server on the computer, change the sysservers system table information by running the stored procedures this way:

    sp_dropserver old_servername\instancename
    GO
    sp_addserver new_servername\instancename, local
    GO

    http://msdn.microsoft.com/en-us/library/Aa197071

    peace

    • Reply mbourgon says:

      This is NOT guaranteed to work, especially when you’re doing things like replication with the server. It will work in a pinch, but I’m about to tear down and rebuild a server rather than go through that again. You will see weird little errors.

  15. Reply Akshat Saxena says:

    It worked for me..
    Thanks,
    Akshat

  16. Reply abutmah says:

    for testing purposes, i have cloned a production VM that contains SQL server, as a result of this clone the result of

    select @@ServerName (which is ‘production’) is not the same as running cmd hostname (which is ‘testing’)

    and when i tried to run

    EXEC Sp_dropserver @@ServerName,’droplogins’
    GO

    EXEC Sp_addserver ‘testing’ , ‘local’
    GO

    i got the following error:

    Msg 20582, Level 16, State 1, Procedure sp_MSrepl_check_server, Line 31

    Cannot drop server ‘production’ because it is used as a Publisher in replication.

    Msg 15028, Level 16, State 1, Procedure sp_addserver, Line 74

    The server ‘testing’ already exists.

    i tried to run exec sp_droppublication @publication =’all’ and it was completed successfully, but when i tried to run the above script i’m still getting the same error

  17. Reply Mohammad Nouman says:

    I was struggling to figure out why the publisher is not recognizing the subscriber although i put the host file entry with the server name and IP and i was able to connect through management studio to the subscriber without any issues but when i wanted to add a new subscriber to setup replication , i was not able to do that .

    Thumbs up to you Nick . Very good post . Keep up the good work .

  18. Reply Gary Woodfine says:

    I remember reading this article about a year ago, and I even submitted it to Dot Net Kicks. Only today did I have to actually use it! Thanks for keeping this post up on the web. I just couldn’t remember the syntax, I could remember it was possible and I knew this post was somewhere on the web !!

  19. Reply Ariana says:

    Hi Nick,
    I have changed the name of the server before with now issues but only where I have default instance.
    Will this work for named instances too?

    Thank you
    Ariana

  20. Reply RM says:

    Hi,

    Thank you for taking the time to read this.

    I have a remote machine on which there are several instance of sql server running (SQL 2008). From my local sql server I would like to be able to query one of the remote instances of sql server. To do so, I understand that I need to specify a 4-part name.

    Since there are multiple instances running on the remote machine, how do I specify the remote machine’s IP/name and the instance name when I have just one slot available in the above 4-part name.

    Thank you for your help.

  21. Reply Dylan says:

    RM, you can do it like this:

    select * from [hostname\instancename].databasename.dbo.tablename

    Be sure to add the linked server using sp_addlinkedserver and sp_addlinkedsrvlogin, or use SSMS under Server Objects.

    Dylan

Leave a Reply