Running sqlcmd locally - Error Locating Server

12,992

Solution 1

You should try this:

sqlcmd -S Server -d DbName -E -i C:\data.sql

You need to specify the server after the -S and the database separately, with a -d parameter.

If you're using a non-standard/non-default server instance, then you need to specify that with the -S parameter, e.g. if you're using the default SQL Server Express instance, use this:

sqlcmd -S Server\SQLEXPRESS -d DbName -E -i C:\data.sql

Here, Server\SQLEXPRESS is the server instance name - not the server+database name!

Solution 2

Check, if service SQL server browser is running. This settings is visible in SQL server configuration manager.

Solution 3

The above answers didn't help me. What helped me with this seemingly bizarre error was going into Microsoft SQL Server Management Studio, right-clicking the server node → Properties → Security → setting Server authentication to "Windows Authentication mode" (not a mixed form).

Share:
12,992
Dave New
Author by

Dave New

Updated on June 16, 2022

Comments

  • Dave New
    Dave New almost 2 years

    I am trying to run a SQL script locally using sqlcmd, but I keep getting the following response:

    HResult 0xFFFFFFFF, Level 16, State 1
    SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].

    Sqlcmd : error : Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

    Sqlcmd : error : Microsoft SQL Server Native Client 10.0 : Login timeout expired

    I am running the following command:

    sqlcmd -S Server\DbName -E -i C:\data.sql
    

    I have also tried with 127.0.0.1\DbName and localhost\DbName. Same result. I have also looked in the configuration manager and made sure Named Pipes and TCP are enabled for SQL Native Client 10.0.

    How do I get this script to run?

  • disasterkid
    disasterkid almost 5 years
    This, unfortunately, does not work for me. I wrote a new question here. stackoverflow.com/questions/56562982/…
  • Panagiotis Kanavos
    Panagiotis Kanavos almost 5 years
    The error isn't bizarre. Looks like you used the wrong authentication mode. The answer that, completely different, problem is to pass the username and password in the command line, not change the server's authentication mode. I'd bet the error you got was different too, as this questions error clearly complains about network connectivity.