Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Understanding DNS for SQL Server
Message
De
22/04/2021 14:40:13
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01679952
Message ID:
01679957
Vues:
56
"Hostname" is the computer (host) name. You can find this in Settings...System...About, "Device name". You can also get it by starting up a CMD window, entering the "set" command to view environment variables, then inspecting the "COMPUTERNAME" setting.

SQL Server runs as a process on a computer. Usually it's installed and run as a service, which is a process which runs under the credentials of a service account and doesn't require a signed in user to run.

Every SQL Server installation has its own "instance" name. A so-called "default" installation gets the instance name "MSSQLSERVER". It can also be installed with a custom instance name; this creates a so-called "named instance". SQL Server Express may get a default instance name "SQLEXPRESS".

It's possible to install multiple instances on a single host/computer. The instance names must all be unique. You may have:

- one "default" instance MSSQLSERVER plus one or more named instances
- two or more named instances (with no default instance)

Client software that wants to connect to a SQL Server instance needs to know how to find it. It needs to know:

- the IP address of the computer running the desired instance
- the name of the desired instance

If DNS can resolve a hostname (i.e. translate it to an IP address) you can use the hostname instead of the computer's IP address. If the instance is running on the same computer as the client, there are some special ways to specify an IP address:

- localhost
- 127.0.0.1

Instance name: as I understand it, with early versions (last century) of SQL Server you could only have a single instance on one computer and its instance name was always "MSSQLSERVER". Client software only needed to specify the hostname or IP address; it always used the default instance name. As a convenience, and to prevent ancient software from breaking, this behaviour remains today with modern versions of SQL Server.

If the instance you're connecting to is not named "MSSQLSERVER" you need to explicitly specify it. This applies to a "default" installation of SQL Server Express if that instance's name is anything other than "MSSQLSERVER" (e.g. "SQLEXPRESS").

For some examples, let's suppose:

- your computer's name is "DL_PC"
- its LAN IPv4 address is 192.168.1.100. You can find this by running "ipconfig" in a CMD window and inspecting the "IPv4 Address" entry for the active LAN connection (wired or wireless)

Case 1: Default installation of SQL Server Standard on local computer - instance name "MSSQLSERVER"

You can connect to it using any of the following:

localhost
localhost\MSSQLSERVER (explicitly specifying instance name)
127.0.0.1
127.0.0.1\MSSQLSERVER
192.168.1.100
192.168.1.100\MSSQLSERVER
DL_PC
DL_PC\MSSQLSERVER

Case 2: Default installation of SQL Server Express on local computer - instance name "SQLEXPRESS"
Because this instance is not named "MSSQLSERVER" you must explicitly specify the instance name. There are several ways to get instance name(s) if you don't know them already: https://stackoverflow.com/questions/141154/how-can-i-determine-installed-sql-server-instances-and-their-versions , the services.msc one is reasonably user-friendly.

You can connect to it using any of the following:

localhost\SQLEXPRESS
127.0.0.1\SQLEXPRESS
192.168.1.100\SQLEXPRESS
DL_PC\SQLEXPRESS

Cases 3 and 4: as 1 and 2 above, but on a remote computer. In those cases you can't use the "localhost" or "127.0.0.1" options.

It's worth pointing out that named instances may use non-default TCP ports or named pipes for incoming client connections. If the client doesn't explicitly specify those non-standard parameters, the connection will fail unless the SQL Browser service is running on the same host as the SQL Server instance: https://docs.microsoft.com/en-us/sql/tools/configuration-manager/sql-server-browser-service?view=sql-server-ver15 . As the article points out, the SQL Browser service is also required for apps that need to enumerate instances and their parameters.

Named instances in particular may use non-standard TCP ports, and these may be dynamic by default i.e. change each time the service is restarted. Client software won't be informed of such changes unless the SQL Browser service is running.

In a way, the SQL Browser service is like DNS for non-default connection parameters.

>I want to be sure I understand the term hostname as far as SQL Server is concerned.
>
>My application connects to the SQL Server using the SQL Server name. E.g. "MySQLExpress"
>So, the application does not use the SQL Server IP address.
>When the application starts and connects to the SQL Server, does DNS lookup take place?
>
>And would the SQL Server name I use when connecting is the same as 'hostname'?
>
>TIA
>
>UPDATE: I want to test my app connecting the SQL Server by IP and not name. How do I find out what is the IP of the SQLExpress installed on my PC? so that I can test it. TIA
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform