SQL Server Network Interfaces: Connection string is not valid [87] - sql-server

When I am running this from cmd on my SQL Server 2008 instance:
sqlcmd -U sa -S mymachinen_name\MSSQLSERVER
(where MSSQLSERVER is my instance name)
I get prompt for password and after that I get this:
Password:
HResult 0x57, Level 16, State 1 SQL Server Network Interfaces: Connection string is not valid [87].
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 have my SQL Server browser service started and also I can login through Management Studio with Windows authentication.
Also found this KB article, but this is for SQL Server 2005/2000.

Typically, the MSSQLSERVER service is the service of a un-named default instance.
Therefore, try this:
sqlcmd -U sa -S mymachine_name
(without specifying any instance name - just the machine name)

I encountered this error trying to connect to the server through Jenkins and resolved it this way:
sqlcmd -e -S "SERVER_NAME,PORT_NUMBER" -U %USER% -P %PASSWORD% -i "D:\\test.sql"

Please note that when connecting via sqlcmd to another server, if the target server is part of a HA cluster group, you will want to specify -M. Also, you will want to not specify the DB that is using the AG. (this is useful for installing jobs via sqlcmd to remote locations, among other things)
sqlcmd -S SERVERNAME,1433 -d msdb -Q "SELECT job_id FROM msdb.dbo.sysjobs WHERE (name =
N'RANDOM_JOB_NAME')" -M

It is set on installation, there is no default. Try to log on without a username

Related

Getting Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server When trying to run a batch script

I am using XAMPP for creating a local SQL Server instance to run a SQL script. the issue here is, when I run the script I get the following error. What is going wrong here?
Code:
sqlcmd -S localhost -d mysqldb -U uname -P pass -i C:\query2.sql
PAUSE
Error:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Named Pipes Provider: Could not open a connection to SQL Server [2].
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : 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 is for SQL Server, you i couldn't connect to MySQL with it as #james Z mentioned. They are completely different database products. I tried using mysql commmand
C:\Software\XAMPP\mysql\bin\mysql --host=hostname --port=portnumber -D dbname -u username --password=**** < path to sql file

Login failed when I trying to connect to a SQL Server using sqlcmd (from Ubuntu command line)?

I am finding some problem trying to connect to a SQL Server instance from an Ubuntu machine using sqlcmd. The SQL server instance run on another server that is an always on MS-SQL Server cluster.
So I installed sqlcmd as explained here: https://learn.microsoft.com/it-it/sql/linux/sql-server-linux-setup-tools?view=sql-server-ver15#ubuntu
The SQL server seems to be reachable because I can successfully connect to the 1433 port of its IP via Telnet.
Then I tried to connect to one of my database on this server, in this way:
./sqlcmd -S MY-IP-ADDRESS -d ESB_WSO2_USER_DB -U datacenter\\wso2DBAdmin
Where:
ESB_WSO2_USER_DB is the DB name
datacenter\wso2DBAdmin is the domain\username
It ask me the password, I insert the password (pretty sure that the credential should be ok) but I am obtaining this error message:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed
for user 'datacenter\wso2DBAdmin'..
Assuming that username and password are correct: what could be the problem? Is it something that could be related to my sqlcmd installation (maybe some missconfiguration), or the driver? or something related to my connection string? or something related to the SQL Server database?

How can I log into SQL Server via SQLCMD using Git Bash?

In my command prompt this seems working perfectly:
sqlcmd -S .\sqlexpress
But in my Git Bash this does not seem to work. It's giving:
Named Pipes Provider: Could not open a connection to SQL Server [53].
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.
As I stay in my Git Bash a lot, how can I log into my SQL Server via Git Bash without moving around often?
You need to escape the backslash separating the instance name in the git bash shell with an additional backslash:
SQLCMD -S .\\sqlexpress
I guess I needed winpty for making login working:winpty sqlcmd -S .\\sqlexpress

Not able to login to sql server

I am not able to login to sql server 2012
error
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Named Pipes Provider: C
ould not open a connection to SQL Server [67]. .
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login timeout expired.
Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : A network-related or in
stance-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 i
f SQL Server is configured to allow remote connections. For more information see
SQL Server Books Online..
Command I am using to login "sqlcmd -S MSSQLSERVER -E"
I also tried enabling TCP/IP under sql server configuration manager.
Thanks
If you are are running the SQLCMD from the machine where the SQL Server is installed, you need to use the below command.
SQLCMD -E
If the SQL Server is on another machine, you need to use the below command. The <ServerName> is the machine name, but not the instance name.
SQLCMD -E -S <ServerName>
You need to check if SQL Server is running or not. Press Win + R and enter services.msc and press enter. (You need to do it on the machine where SQL Server is installed)
This will open the Services window. Scroll through and find SQL Server (MSSQLSERVER) and select it.
On the left side of it, you should be able to see the status. Check if the process is already running or now. If not, you need to start it before using the SQL Server.
If the SQL Server is up and running, you need to check if SQL Server is accessible from your machine. You can check it by executing below command from cmd prompt.
TELNET <ServerName> 1433
If this command does not give you any error, and opens a blank window, that means you are able to reach SQL Server machine. This will rule out any firewall issues. All you need to check is if the SQL Server instance is running or not.

Connect to SQL Server from cygwin window times out, from DOS prompt works

I can connect to my SQL Server database via sqlcmd from a DOS command window, but not from a Cygwin window. From DOS:
F:\Cygnus>sqlcmd -Q "select 'a test'" -S .\SQLEXPRESS
a test
(1 rows affected)
F:\Cygnus>
====================================================
From Cygwin:
$ sqlcmd -Q "select 'a test'" -S .\SQLEXPRESS
HResult 0x35, Level 16, State 1 Named Pipes Provider: Could not
open a connection to SQL Server [53]. Sqlcmd: Error: Microsoft SQL
Native Client : An error has occurred while establishing a connection
to the server. When connecting to SQL Server 2005, this failure may be
caused by the fact that under the default settings SQL Server does not
allow remote connections.. Sqlcmd: Error: Microsoft SQL Native Client
: Login timeout expired.
The backslash is being eaten by cygwin's bash shell. Try doubling it:
sqlcmd -Q "select 'a test'" -S .\\SQLEXPRESS
You may have to allow remote connections for this, and give the full server name i.e SERVER\SQLEXPRESS
You can also pass query/instruction to db and receive output in shell if you use "-Q" switch:
sqlcmd -Q "select * from nice.dbo.TableName ac ORDER BY 1 DESC" -S server_name\\db_name

Resources