question

MiguelRianoAbril avatar image
0 Votes"
MiguelRianoAbril asked MiguelRianoAbril commented

Where can I find SERVERNAME and INSTANCE name to usethem in sqlcmd command

in cmd shell i see "COMPUTERNAME=BASEDATOS", in SSMS I see the instancename = BASEDATOS, using select @@servername return BASEDATOS.
When I try to use

sqlcmd -S BASEDATOS\BASEDATOS -Usa -Pp4ssw0rd5tr0ng

Server is not found or not accessible.


sqlcmd -S BASEDATOS -Usa -Pp4ssw0rd5tr0ng

work well.

sql-server-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Cathyji-msft avatar image
0 Votes"
Cathyji-msft answered MiguelRianoAbril commented

Hi @MiguelRianoAbril,

Full agree with Erland, you installed a default SQL server instance, not a named instance. So when you using sqlcmd to start your SQL server instance, the instance name is BASEDATOS not BASEDATOS\BASEDATOS.

Quote from MS document Lesson 1: Connecting to the Database Engine

For the default instance of SQL Server, the server name is the computer name. For a named instance of SQL Server, the server name is the <computer_name>\<instance_name>

You can check whether the instance you installed is a default instance from SQL server configuration manager or windows service. If the SQL instance name is shown as MSSQLSERVER, this is default SQL server instance.
197559-screenshot-2022-04-29-110005.jpg
197450-screenshot-2022-04-29-110049.jpg

In your case SOMMERWALD\SJUTTON your COMPUTERNAME is SOMMERWALD and instance name is SJUTTON?

Yes, you are correct.


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Excellent explanation, thank you very much for the support. I am new to SQL Server, I know very well SAP-ASE (Sybase) and I want to know Microsoft server as well.

0 Votes 0 ·
TomPhillips-1744 avatar image
0 Votes"
TomPhillips-1744 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ErlandSommarskog avatar image
0 Votes"
ErlandSommarskog answered

@@servername does not return the instance name. It returns the servername and also the instance name, if the instance is a not default instance. For instance, when run SELECT @@servername on my machine I see SOMMERWALD\SJUTTON.

In your case, where was no backslash in the name, and thus you have a default instance.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MiguelRianoAbril avatar image
0 Votes"
MiguelRianoAbril answered OlafHelper-2800 commented

excelent ErlandSommarskog, than you. I execute in cmd shell the "set" command in order to know the machine name so use it in -S option "COMPUTERNAME=BASEDATOS". In your case SOMMERWALD\SJUTTON your COMPUTERNAME is SOMMERWALD and instance name is SJUTTON?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

In your case SOMMERWALD\SJUTTON your COMPUTERNAME is SOMMERWALD and instance name is SJUTTON?

Quite right. Default instance of SQL Server don't have a instance name, only named instance; you can have up to 50 per machine.
See https://docs.microsoft.com/en-us/sql/sql-server/install/work-with-multiple-versions-and-instances-of-sql-server?view=sql-server-ver15
0 Votes 0 ·