Как узнать имя сервера sql
Перейти к содержимому

Как узнать имя сервера sql

  • автор:

How to find server name of SQL Server Management Studio

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's user avatar

20 Answers 20

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 .

Программирование на C, C# и Java

Уроки программирования, алгоритмы, статьи, исходники, примеры программ и полезные советы

ОСТОРОЖНО МОШЕННИКИ! В последнее время в социальных сетях участились случаи предложения помощи в написании программ от лиц, прикрывающихся сайтом vscode.ru. Мы никогда не пишем первыми и не размещаем никакие материалы в посторонних группах ВК. Для связи с нами используйте исключительно эти контакты: vscoderu@yandex.ru, https://vk.com/vscode

Как узнать имя сервера Microsoft SQL Server

Для выполнения запросов к локальной базе данных Microsoft SQL Server из программы необходимо знать имя экземпляра сервера. Из статьи вы узнаете, как его получить.

Способ первый. Самый надежный

В Microsoft SQL Server предусмотрен специальный SQL запрос, возвращающий имя экземпляра сервера:

Выполнив данный запрос, например, в SQL Server Management Studio, вы получите имя вашего экземпляра сервера.

Как узнать имя сервера Microsoft SQL Server с помощью SQL-запроса

В данном случае было возвращено имя установленного экземпляра Microsoft SQL Server равное: SQLEXPRESS.

Способ второй

Другим способом получения имени SQL-сервера является поиск записи службы SQL Server.

Запустите классическое приложение Windows «Службы» на вашем компьютере и найдите в списке служб объект SQL Server.

В скобках будет указано имя экземпляра.

Как узнать имя сервера Microsoft SQL Server - c помощью имени службы Windows

В этом же меню можно остановить, запустить и перезапустить экземпляр установленного Microsoft SQL Server.

Стоит отметить, что второй способ получения имени сервера — менее достоверен. В скобках не всегда указано истинное имя сервера, пригодное для обращения к нему при подключении. Поэтому при наличии возможности лучше всего использовать первый способ получения имени с помощью SQL-запроса.

2 Ways to Return the Server Name in SQL Server (T-SQL)

Here are a couple of T-SQL methods you can use to return the server name in SQL Server.

@@SERVERNAME

The @@SERVERNAME configuration function is designed specifically for returning the name of the local server that is running SQL Server.

To get the server name, you simply select it using a SELECT statement.

Result on my system:

This tells me that my server name is mssql2019_1 .

SERVERPROPERTY(ServerName)

The SERVERPROPERTY() metadata function can also be used to return the server name, as well as many other properties.

To return the server name, you need to pass ServerName as an argument.

In my case, it’s the same output.

Difference Between These Two Functions

The two functions above produce the same output on my machine, but you might find that they produce slightly different output on yours.

The two functions are similar, but slightly different. Here’s the difference:

  • @@SERVERNAME provides the currently configured local server name.
  • The ServerName property provides the Windows server and instance name that together make up the unique server instance.

So for example, on a Windows system, if your computer name is Felix , and your SQL Server instance is called sql1 , running SERVERPROPERTY(‘ServerName’) might return Felix\sql1 .

The Machine Name & Instance Name

The SERVERPROPERTY() function can also be used to return the machine name as well as the SQL Server instance name.

However, the results you get will depend on a couple of things (mentioned below).

First, the MachineName property returns the machine name. Microsoft’s explanation is that it returns the Windows computer name on which the server instance is running.

Microsoft also states that “For a clustered instance, an instance of SQL Server running on a virtual server on Microsoft Cluster Service, it returns the name of the virtual server”.

As far as the InstanceName property goes, it returns the name of the instance to which the user is connected.

However, it returns NULL if the instance name is the default instance, if the input is not valid, or error.

How to Find SQL Server Instance Name

There are multiple ways on getting the SQL Server instance name. You can refer any of below methods.

Below example were tested on SQL Server 2012 R2 version but the steps will be similar to other SQL Server versions.

Method 1

Launch the SQL Server Management Studio. You will get the Connect to Server dialog box. From here, you can obtain the instance name, which is at the Server name.

If it’s does not appear, click on Server name drill down list and click Browse for more. Once clicked, you will get below screen and you will get the instance name under the Database Engine.

Method 2

Use below query.

Method 3

Login to the SQL server operating system, open the command prompt and execute below command line.

Method 4

Open the SQL Server Configuration Manager, click on SQL Server Services and double click on SQL Server (MSSQLSERVER).

Go to Service tab and you will get the instance name from here, as per below screenshot.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *