0

I use management studio and SQL Server. How to change server name from (LocalDbs)\MSSQLLocalDB to localhost? When I connect to server in connection string I want to call: server='localhost

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • 1
    If you are connecting to a named instance like this you have to specify the name of the instance. That is how named instances work. – Sean Lange Aug 06 '19 at 19:42
  • Can you even rename localdb? Either way the "recommended" way to rename an instance is normally to reinstall it. A lot hands off the instance names once configured, and renaming *can* break things. – Thom A Aug 06 '19 at 19:50
  • You can't change it. It is an installed named instance and you are wanting it to be the root instance. As already stated you need to reinstall. This means uninstalling sql server from the box completely and installing it from scratch. Why are you so concerned that it must be localhost? – Sean Lange Aug 06 '19 at 20:00
  • If there is already an existing default instance (localhost), you can't. But you might be able to jump through some hoops to create an alias? Not sure you'd really want to do this though, imo. https://serverfault.com/questions/60738/how-to-create-an-alias-for-a-named-sql-server-instance – LaraRaraBoBara Aug 06 '19 at 22:26

1 Answers1

1

I believe, it's not good idea to change named instance to default instance as it might conflict with existing default instance, and considering consequences. However, \InstanceName is really concern for the connection string, you could have custom port assigned to that SQL Instance so that your connection string would be server=localhost,portnumber.

Please have a look at this answer at DBA.StackExchange to learn more on connecting SQL Server with custom port and how to change the port#

If you still have concern to use port number in connection string server=localhost,portnumber. My advise is to restore the database on SQL default instance (need to be installed if not existed already), then you could re-direct the application to communicate with default SQL Instance, this case your connection string would look like server=localhost

You could do following, if you want rename the Server in any case:

sp_dropserver <old_name>;  
GO  
sp_addserver <new_name>, local;  
GO  

Shekar Kola
  • 1,287
  • 9
  • 15