Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running sqlcmd locally - Error Locating Server

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?

like image 322
Dave New Avatar asked May 18 '14 12:05

Dave New


People also ask

How do I fix Error Locating server instance specified?

Make sure your server name is correct, e.g., no typo on the name. When you try to connect to an SQL Server instance on another server, make sure the server machine is reachable, e.g, DNS can be resolve correctly, you are able to ping the server (not always true). Make sure SQL Browser service is running on the server.

Why is my SQL Server not connecting?

Make sure that Allow Remote Connections is enabled on sql server properties. Check if TCP/IP is enabled. Configure to allow SQL Server in Firewall Settings. Check for working fine SQL Server Browser.

How do I connect to SQL Server with Sqlcmd?

Connect to a SQL Server instance using Windows Authentication. Open the Command Prompt and switch to the location of the sqlcmd utility. Then, execute the following command by replacing the connection parameters with the server ( server_name ) and instance ( instance_name ) names to which you want to connect.


2 Answers

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!

like image 60
marc_s Avatar answered Oct 05 '22 02:10

marc_s


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

like image 38
Libor Avatar answered Oct 05 '22 02:10

Libor