bcp cannot connect to AWS SQL Server but SSMS can - sql-server

Anyone know a good reason why bcp cannot connect to a sql server hosted by AWS while SSMS can?
I have double checked the server and user account details and they both match.
I'm using the generic command to import a csv file:
bcp DB_Name.dbo.Table in "somefile_file.csv" -c -S xxx.rds.amazonaws.com -U username -P xxx -b 1000
The error is:
SQLState = 08001, NativeError = 53
Error = [Microsoft][ODBC Driver 13 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53].
SQLState = 08001, NativeError = 53
Error = [Microsoft][ODBC Driver 13 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.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired
Is bcp using a different port maybe?

The first error shows that bcp uses the Named Pipes protocol to connect to the server. Apparently, this protocol is inaccessible for network connections.
On the client workstation where bcp is run, check SQL Server Configuration Manager and ensure that, in the client configuration list TCP/IP is enabled and prioritised. Strangely enough, bcp doesn't have a command line switch for protocol selection, so this is the only way to manage it I can think of.
P.S. Another option is to specify the server address in the form ip_address,port_number, but I don't think you will find this option particularly attractive.

Related

Pyodbc: Login timeout expired

I am trying to connect to MS SQL Server using pyodbc on local system and on connect to instance i get error:
[2020-06-21 15:39:04.110750]: ('08001', '[08001] [Microsoft][ODBC Driver 13 for SQL Server]SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. (-1) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 13 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. (-1)')
My SQL Server is Express 2005 and try with drivers:
{ODBC Driver 13 for SQL Server}
{ODBC Driver 17 for SQL Server}
{SQL Native Client}
I test in sqlcmd with this command:
C:\Users\Moein>sqlcmd -S '.\Moein' -U 'sa' -P 'xxxx'
HResult 0xFFFFFFFF, Level 16, State 1
SQL Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
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.
My Code :
import pyodbc
conn = pyodbc.connect(f'DRIVER={SQL Native Client};SERVER=.\Moein;DATABASE=Moein;UID=sa;PWD=xxxx',autocommit=True)
cursor = conn.cursor()
More:
Test -l 600 switch for login timeout more in sqlcmd > not answer recived
Test computername\instance and 127.0.0.1\instance > Not changed
Try full reinstall sql server on local > noting changed things
i found my problem
i use this connection string with pipe mode:
conn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};ServerName=Provider=SQLOLEDB.1;SERVER=.\testsv;DATABASE=test;Persist Security Info=False;UID=sa;PWD=xxxxx;Data Source=np:\\.\pipe\MSSQL$testsv\sql\query',autocommit=True)

Suddenly getting "Login timeout expired" error when connecting to SQL Server

Other people have asked this question, but I didn't find an answer that specifically addresses the problem I was getting nor that solved the issue. So I'm posting the question and answer.
A few days ago I had a couple automated scripts that connect to SQL Server and export some data, suddenly stop working. They've been running fine for like 7 years, so that this was odd. Both scripts use different methods to connect. One uses a Perl library, the other uses the bcp command. But both were getting the same error. I'll just show the bcp command for brevity. This is all running on Windows Server 2008, with SQL Server 2008 R2, v10.50. This is what I was running:
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe" "<my query>" queryout "<output file name>" -T -S MYSERVER -c -k
This is the error I was getting:
SQLState = 08001, NativeError = 10061
Error = [Microsoft][SQL Server Native Client 10.0]TCP Provider: No connection could be made because the target machine actively refused it.
SQLState = 08001, NativeError = 10061
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.
SQLState = S1T00, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0]Login timeout expired
The solution was pretty simple. I just added the port number to the server name (changed MYSERVER to MYSERVER,1433). So my final bcp command looked like:
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\bcp.exe" "<my query>" queryout "<output file name>" -T -S MYSERVER,1433 -c -k
I'm not sure what changed to require including the port. But that's all it took.
It's kinda weird that this isn't just the default port. You'd think bcp would use that without needing to explicitly set it. Though, this could just be some weird server configuration thing that suddenly requires the port.

Enforce SQL Server NAtive Client 11.0 while using SQLCMD

SQLCMD is by default using SQL Server Native Client 10.0 which is throwing below eror
T:\mno\pqr>sqlcmd -S 192.168.29.3 -U abc -P def -d ghi -i "jkl.sql"
HResult 0x15, Level 16, State 1
Encryption not supported on the client.
Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : Client unable to establish connection.
HResult 0x80090331, Level 16, State 1
SSL Provider: The client and server cannot communicate, because they do not possess a common algorithm.
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..
I need to reinforce SQL Server Native client 11.0 which fixes this issue (tried and tested via SSIS) but cant find the procedure. Please help
Try this folder: C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\130\Tools\Binn
It works on mine:

Can not connect to remote SQL Server using sqlcmd

I have a Microsoft SQL Server, running in a Window Server 2012 R2 Standard. The configuration for this SQL Instance is: Servername: IP\SQLEXPRESS( IP here is the IP address of the Window Server) with SQL authentication username and password.
I would like to connect to this remote database from my local machine, so I installed sqlcmd on my local machine Win 7, and tried the syntax to connect to this remote server: sqlcmd -S IP\SQLEXPRESS -U username -P password, but then I got some error messages:
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : SQL Server
Network Inte rfaces: Error Locating Server/Instance Specified
[xFFFFFFFF]. .
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : Login timeout
expired.
Sqlcmd: Error: Microsoft ODBC Driver 13 for SQL Server : 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..
I searched some solutions in the Internet and did some configurations for the SQL Server, such as: enabled remote connection in SQL Server, activate TCP/IP Protocol, open incoming TCP Port 1433 by defining new rule in Windows Firewall of remote server, open outgoing TCP Port 1433 in my local Win 7 machine. But it seems there changes are not work in my case. Can anyone give me some hints here to fix this remote connecting problem?
Thank you in advance!
try use only sqlcmd -S IP
not IP\SQLEXPRESS

Sqlcmd: Error: Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while

i have this error:
Password: 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 try to connect by cmd to sql server and i use this command:
sqlcmd -U sa -S server\istance_name
The prompt requires the password, but when i Insert the password, i receive the error message.
I see the Sql server configuration manager and the TCP/IP in Enabled.
I try a telnet connection on port 1443 and it is ok.
Have someone solution?
My psychic powers are telling me that the SQL Server Browser service is disabled or firewalled on your server. Without that, servers with instance names cannot be resolved.

Resources