214

I installed Microsoft SQL Server 2008.

When I start SQL Server Management Studio (SSMS), I get the Connect to Server login window with a blank textbox for Server name. I have tried a lot of names, but I couldn't solve it.

How can I find / get the server name?

Mwiza
  • 7,780
  • 3
  • 46
  • 42
Cantremember
  • 2,141
  • 2
  • 13
  • 3
  • See also: [How can I query the name of the current SQL Server database instance?](http://stackoverflow.com/questions/129861/) – Jeppe Stig Nielsen Sep 28 '16 at 13:18
  • I you wanted to know to which SQL-Server you are connected inside [tag:ssms] then see here [How to view connection string from within ssms](https://serverfault.com/questions/187465/can-i-view-my-mssql-connection-string-from-within-sql-server-management-studio/666344#666344) – surfmuggle Feb 07 '23 at 11:52

20 Answers20

200

Open up SQL Server Configuration Manager (search for it in the Start menu). Click on SQL Server Services. The instance name of SQL Server is in parenthesis inline with SQL Server service. If it says MSSQLSERVER, then it's the default instance. To connect to it in Management Studio, just type . (dot) OR (local) and click Connect. If the instance name is different, then use .\[instance name] to connect to it (for example if the instance name is SQL2008, connect to .\SQL2008).

Also make sure SQL Server and SQL Server Browser services are running, otherwise you won't be able to connect.

Edit:

Here's a screenshot of how it looks like on my machine. In this case, I have two instances installed: SQLExpress and SQL2008.

enter image description here

Arian Motamedi
  • 7,123
  • 10
  • 42
  • 82
  • 11
    What do I do if the list on the right hand side of the screen is empty for me? – Filip Vondrášek Jul 17 '15 at 18:58
  • @FilipB.Vondrášek That means you don't have a local instance installed on your computer. You'll need to rerun the setup.exe file to add a new instance. – Arian Motamedi Jul 20 '15 at 01:34
  • 5
    Turns out I installed only Management Studio which doesn't come with a server. I downloaded a version with Advanced Tools and now everything works as supposed. :) – Filip Vondrášek Jul 20 '15 at 10:02
  • @FilipVondrášek where did you install the advanced tools from? I just installed sql server 16 and 17 from [here](https://learn.microsoft.com/en-us/sql/ssms/sql-server-management-studio-changelog-ssms). I can't seem to get the local instance name – adiga Dec 17 '17 at 16:46
  • @adiga I'm afraid I won't be of much help here anymore, it's been a long time and I haven't used MS SQL Server for quite a long time as well now. :) – Filip Vondrášek Jan 02 '18 at 21:25
  • 2
    @FilipVondrášek that okay. I installed different versions of SQL server hoping to get an option to install the server. Finally worked when I installed SQL express, there was an option to create servers as well. Now it's working. Microsft, ¯\\_(ツ)_/¯ – adiga Jan 03 '18 at 07:05
  • @Filip Vondrášek it happens when you have only client-side like management studio but do not have SQL server express which has many services like creating an instance. – ScorpionPk Jan 30 '20 at 19:22
  • `.` worked with MSSQLSERVER 2019...THANKS – zac Nov 02 '21 at 01:15
  • I love how this is still not marked as the accepted answer lol. – Arian Motamedi Apr 28 '22 at 17:21
128

Run this Query to get the name

SELECT @@SERVERNAME

sansalk
  • 4,595
  • 2
  • 36
  • 37
  • 19
    If you cant login, You can use UserName <.> (Dot) and Password to initial login after you can use SELECT @@SERVERNAME to find Server name :) – sansalk Feb 26 '15 at 08:30
  • 14
    you cant run a query if you aren't loged in. – YongaJ Aug 23 '19 at 10:08
  • While this does not answer the exact question asked - it is exactly the answer I was looking for. I strongly suspect it will be useful to many others as well. In my case I have a Prod & Dev Server with very similar data, and at one point I was unsure which I was connected to c This was an elegant & clean way of finding out without disconnecting or closing my query window. Thanks! – kiltannen Feb 19 '21 at 02:07
  • Error running query: column "servername" does not exist LINE 250: SELECT @@SERVERNAME ^ – The Singularity May 18 '21 at 13:37
  • Surprisingly, doesn't work correctly. For me it returns DESKTOP-XXXXXXX which I think is the default PC name when I installed windows. The actual PC name is no longer that. So it's something to take into account. – Stevie Sep 30 '22 at 07:23
76

Open .exe (WINDOWS + R type cmd and press Enter)

and run this

SQLCMD -L

You will get list of SQL Server instance

3rd party edit

CMD.exe_with_SQLCMD_and_OSQL_Result

surfmuggle
  • 5,527
  • 7
  • 48
  • 77
Khaneddy2013
  • 1,301
  • 1
  • 17
  • 25
  • 1
    can you explain in cmd? – Aravin Apr 21 '16 at 11:36
  • 1
    I usually use Windows + R, type cmd and press Enter. Then use SQLCMD -L (You can use "osql -L" too at CMD) – Khaneddy2013 Apr 26 '16 at 07:56
  • 9
    +1 Did it fo rme. Not sure why others are telling you to run a query when you can't without connecting to an instance... – Lee Aug 22 '17 at 18:37
  • Yes this is the only right method... remaining all others are not always works... Its not always as like this... many more toss goes... In my example,eventhough it shows MSSQLSERVER, but it wont work with that... instead it works with (local) – Madhusudhan V Indian Jul 02 '23 at 04:49
55

the default server name is your computer name, but you can use "." (Dot) instead of local server name.

another thing you should consider is maybe you installed sql server express edition. in this case you must enter ".\sqlexpress" as server name.

Ali
  • 808
  • 1
  • 6
  • 11
  • 2
    I have installed sqlexpress and adding ".\sqlexpress" in server name worked for me – Amna Jan 13 '20 at 11:35
51

Note: To connect to server on SQL Server Management Studio(SSMS), we must first install SQL Server.

So steps to proceed are as

Step 1 : Downloads and Install Microsoft SQL Server 2022

Step 2 : Downloads and Install SQL Server Management Studio

If still not able to see the Server name on SSMS, have a look at these three screen:

enter image description here enter image description here enter image description here

mabdullahse
  • 3,474
  • 25
  • 23
30

As mentioned by @Khaneddy2013, the cmd SQLCMD -L returns no server name when I run. Bcz I only have installed the SSMS (local db and server were not installed). After tried installing SqlLocaLDB and SQLEXPR32_x86_ENU(32 bit OS) I was able to connect. And now the cmd window shows the server names too. enter image description here

SivaKtamilan
  • 423
  • 4
  • 8
  • 5
    just because its an old question doesnt mean we cant add to it. i found this to be the answer i was looking for. – Sotelo Mar 14 '18 at 00:01
  • Hi, can you explain more detail how server was installed. I already install localdb, sql server management studio and SQLEXPRADV_64_ENU (64 bit op). I still get no servername when execute command sqlcmd -L. – Trang Le Jul 28 '21 at 03:50
22

There are many ways mentioned above. But I use rather simple way (well not simple as SELECT @@SERVERNAME). When you start SQL server management studio you will prompt below GUI

enter image description here

In there Server name is your server name (There may have multiple servers according to you dev environment choose correct one). Hope this helps :)

Menuka Ishan
  • 5,164
  • 3
  • 50
  • 66
  • 1
    Not always true. You can type an alias in here, e.g. one held by DNS, to go to a defined server name. However SELECT @@SERVERNAME will report the server's computer name, not the alias you typed into the connection manager. – Paul Dec 19 '18 at 14:41
14

start -> CMD -> (Write comand) SQLCMD -L first line is Server name if Server name is (local) Server name is : YourPcName\SQLEXPRESS

11

given the following examples

  • SQL Instance Name: MSSQLSERVER
  • Port: 1433
  • Hostname: MyKitchenPC
  • IPv4: 10.242.137.227
  • DNS Suffix: dir.svc.mykitchencompany.com

here are your possible servernames:

  • localhost\MSSQLSERVER
  • localhost,1433\MSSQLSERVER
  • MyKitchenPC,1433\MSSQLSERVER
  • 10.242.137.227,1433\MSSQLSERVER
  • MyKitchenPC.dir.svc.mykitchencompany.com,1433\MSSQLSERVER
morethanyell
  • 316
  • 3
  • 10
6

Step1: Ensure SQLEXPRESS and LocalDB installed on your system Go to SQL SERVER Configuration Manager => SQL Server Service

If nothing listed for SQL Server services, install below components (for 64 bit OS) 1. SqlLocalDB 2. SQLEXPR_x64_ENU 3. SQLEXPRADV_x64_ENU 4. SQLEXPRWT_x64_ENU

Step2: Open Management Studios Enter . (Dot) as server name and click on Connect [enter image description here][2] Else Enter .\SQLEXPRESS as server name and click on connect

MV Sreedhar
  • 339
  • 2
  • 7
5

I also had this problem first time.

In the Connect to Server dialog box, verify the default settings, and then click Connect. To connect, the Server name box must contain the name of the computer where SQL Server is installed. If the Database Engine is a named instance, the Server name box should also contain the instance name in the format: computer_name\instance_name.

So for example i solved the problem like this: I typed in the server name: Alex-PC\SQLEXPRESS

Then it should work. for more see http://technet.microsoft.com/en-us/library/25ffaea6-0eee-4169-8dd0-1da417c28fc6

Akbar
  • 71
  • 1
  • 3
4

Try using a . or localhost as server name, might work a few times.

Shravya Mutyapu
  • 278
  • 2
  • 9
3

simply type .\sqlexpress as the Server Name

kiran
  • 46
  • 3
1

Typing sp_helpserver will give you a list. As others have noted, there are multiple ways, some with alias' and such. This stored proc may return multiple lines but could get you closer to your answer.

Grandizer
  • 2,819
  • 4
  • 46
  • 75
0

1.you can run following command.

EXEC xp_cmdshell 'reg query "HKLM\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL"';
GO

you can read instance name using Registry. Ingore null values.

2.using inbuilt standard Report.

select instance--> right click->Reports-->Standard Reports-->server Dashbords enter image description here

Vishe
  • 3,383
  • 1
  • 24
  • 23
0

Please Install SQL Server Data Tools from link (SSDT)

You can also Install it when you are installing Visual Studio there is Option "Data Storage and Processing" you must be select while installing Visual Studio

enter image description here

Minal Chauhan
  • 6,025
  • 8
  • 21
  • 41
Sanjay Dwivedi
  • 699
  • 7
  • 10
0

Make sure you have installed SQL Server.

If not, follow this link and download. https://www.microsoft.com/en-us/sql-server/sql-server-downloads

Once SQL server is installed successfully. You will get server name. Refer to the below picture:

enter image description here

Prem Sagar
  • 147
  • 2
  • 8
0

On installing the sql server 2019 management studio the default server name will be : localhost\SQLEXPRESS default connection string is : Server=localhost\SQLEXPRESS;Database=master;Trusted_Connection=True;

Anindya
  • 2,616
  • 2
  • 21
  • 25
0

only right method is by checking "SQLCMD -L" in cmd prompt... remaining all others are not always works... many more toss goes... In my example,eventhough it shows MSSQLSERVER in configuration manager, but it wont work with that... instead it works with (local) as per sqlcmd -L enter image description here

-1

my problem was that when connecting to SQL Database in the add reference wizard, to find the SERVERNAME. i found it by: running a query(SELECT @@SERVERNAME) inside SQL management studio and the reusl was my servername. I put that in my server name box and it worked all fine.