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

Miguel Riano Abril 21 Reputation points
2022-04-28T16:41:06.547+00:00

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
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,691 questions
0 comments No comments
{count} votes

Accepted answer
  1. CathyJi-MSFT 21,086 Reputation points Microsoft Vendor
    2022-04-29T02:14:13.127+00:00

    Hi @Miguel Riano Abril ,

    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 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Erland Sommarskog 100.9K Reputation points MVP
    2022-04-28T21:47:27.717+00:00

    @@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.

    0 comments No comments

  2. Miguel Riano Abril 21 Reputation points
    2022-04-28T23:03:02.913+00:00

    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?