tsql login failed but management studio can connect - sql-server

I'm trying to connect to a MS SQL Server instance using tsql (to troubleshoot not being able to connect with django-pymssql).
I can connect fine to the server (running on Amazon RDS, latest SQL Server version from on there) from a VM running SQL Server management studio, but from my native Ubuntu 15.10 env I get a login failed error.
Using the following:
tsql -H <hostname> -p 1433 -U <user> -P <mypassword>
I get:
locale is "en_GB.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Msg 18456 (severity 14, state 1) from EC2AMAZ-U1TAK71 Line 1:
"Login failed for user 'sa'."
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
As I can connect in management studio with mixed mode auth using the same creds I'm suspecting this isn't the real error.
Anyone have any ideas how I can troubleshoot?
tsql -C shows:
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
Thanks loads for any pointers.!
(Accidentally posted this to AskUbuntu so have moved here. Sorry).

Answering my own question. Turns out it was down to the password being too long. I experimented with it, and any password longer than 30 characters didn't work. Seems to be a known issue with freetds.
Thanks.

Related

Error 20002 while trying to connect to a server through tsql (OS X)

I've been using this guide for connecting to database through pyodbc: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-SQL-Server-from-Mac-OSX
My config files look like this, in parallel with the tutorial:
In freetds.conf:
[MYMSSQL]
host = localhost
port = 1433
tds version = 7.3
In odbc.ini:
[MYMSSQL]
Description = Testing SQLServer
Driver = FreeTDS
Servername = MYMSSQL
In odbcinst.ini:
[FreeTDS]
Description=FreeTDS Driver for Linux & MSSQL
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsodbc.so
UsageCount=1
When I test the connection with "tsql -S MYMSSQL -U myuser -P mypassword", I get the error:
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
Likewise, "isql MYMSSQL myuser mypassword" returns an error as well:
[ISQL]ERROR: Could not SQLConnect
EDIT: In the query console:
"SELECT ##SERVERNAME" returns "4a70ffff1294"
"SELECT ##SERVICENAME" returns "MSSQLSERVER"
"SELECT ##VERSION" returns "Microsoft SQL Server 2019 (RTM-CU8) (KB4577194) - 15.0.4073.23 (X64)"
tsql -S MYMSSQL
returns
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
The server is running in a docker image. I am able to connect to it via pycharm's database tool with the 1433 port and the relevant password. Sadly, I'm not very experienced with managing servers. All help is much appreciated.
If you want to continue down that path, we need some more info. What's in your freetds.conf? Can you connect to your SQL Server from the machine you're trying to install FreeTDS on with telnet mssql.myhost.com 1433?
However, I find it easier to avoid using freetds.conf and odbc.ini, and just keep everything in Python. As long as you have properly configured odbcinst.ini, you should be able to do something like this:
import pyodbc
con = pyodbc.connect(
"DRIVER={FreeTDS};"
"SERVER=mssql.yourserver.com;"
"PORT=1433;"
"DATABASE=your_db;"
"UID=your_user;"
"PWD=your_pass;"
"TDS_Version=7.3;"
)
cursor = conn.cursor()
cursor.execute("SELECT 1")
for row in cursor.fetchall():
print(row)
Good luck!

FreeTDS Connector - SQLSTATE[01002] Adaptive Server connection failed (severity 9)

I'm facing an issue in API call due to DB connection failure. We have tried for concurrent 90 calls to fetch some details based on some code which got failed in 1 percentage due to DB connection failure. Here is the error message “SQLSTATE[01002] Adaptive Server connection failed (severity 9)” while connecting to the DB. There are so many failures happening recently in API call due to the DB connection failure.
Is there any work around or permanent fix for this issue?
Some info,
rpm -qa | grep freetds
freetds-0.91-2.el6.x86_64 freetds-devel-0.91-2.el6.x86_64
tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc
MS db-lib source compatibility: yes
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
Please give your hands to fix this issue.

connecting to remote mssql from linux plesk via php

I am trying to connect to remote Microsoft SQL server 2012 service pack 2 database from my Linux machine which is having php 5.3, php-mssql support and mysql version 5.5 enabled. Meanwhile I am getting below error message even if the login details are correct.
The ms-sql database is using Persian collation which cannot be changed. Is there any possible fix for this?
[root#i]# /usr/bin/tsql -H remove-server-ip -p 1433 -U mssql-user
locale is "en_IN"
locale charset is "UTF-8"
using default charset "UTF-8"
Msg 4075 (severity 16, state 1) from RAHKARAN Line 1:
"
The USE database statement failed because the database collation
Persian_100_CI_AI is not recognized by older client drivers. Try
upgrading the client operating system or applying a service update to
the database client software, or use a different collation. See SQL
Server Books Online for more information on changing collations."
Msg 18456 (severity 14, state 1) from RAHKARAN Line 1:
"Login failed for user 'mssql-user'."
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
Error 20002 (severity 9)
Freetds version is below
tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v0.91
freetds.conf directory: /etc
MS db-lib source compatibility: yes
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes

Symfony2 and Microsoft SQL Server on Mac and MAMP

I´m going to develop a Symfony2 application in my Mac OSX with MAMP, but the database (a Microsoft SQL Server one) is in another computer.
I setup everything (I followed this instruction http://jesusomar.com/2011/07/22/mamp-php-and-mssql )and if I check phpinfo() I see that mssql is active, but I´m getting this error:
[PDOException]
could not find driver
any help or clue? Thanks in advance
The first step is to check if FreeTDS is installed. You can run tsql -C to get information about MSSQL libraries in your computer. You should get something like this:
Version: freetds v0.91
freetds.conf directory: /usr/local/Cellar/freetds/0.91/etc
MS db-lib source compatibility: no
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 7.1
iODBC: no
unixodbc: no
SSPI "trusted" logins: no
Kerberos: no
If FreeTDS is not installed, you can do it with Homebrew (for example): brew install freetds.
Now you can use MssqlBundle to connect with your database.

FreeTDS problem connecting to SQL Server on Mac (Unexpected EOF from the server)

I have setup FreeTDS to connect to SQL Server database. When I try to open TSQL in terminal on Mac (lion) I get this error:
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Error 20017 (severity 9):
Unexpected EOF from the server
OS error 36, "Operation now in progress"
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
Does anybody have a clue what could be causing this?
I think I got it, it's the TDS configured version, I had 5.0, which caused the error
Try running tsql -C to check what version are you using, and then you can invoke tsql overriding the version with:
TDSVER=7.0 tsql -H hostname -p port -U domain\\\username -P password
and it worked!
To make this permenant I found I need to edit the freetds.conf file and set it globally in there
vim /usr/local/freetds/etc/freetds.conf
tds version = 8.0
running tsql -C still showed that the version was 5.0 but connecting now worked every time.
TDS version need to match the correct tds protocol to connect to your db server, see below -
http://www.freetds.org/userguide/choosingtdsprotocol.htm
Choosing a TDS protocol version
***DB SERVER | TDS VERSION ***
Microsoft SQL Server 6.x = 4.2
Sybase System 10 and above = 5.0
Sybase System SQL Anywhere = 5.0
Microsoft SQL Server 7.0 = 7.0
Microsoft SQL Server 2000 = 7.1
Microsoft SQL Server 2005 = 7.2
Microsoft SQL Server 2008 = 7.2
Also missing symlink on libtdsodbc.so in /usr/lib/odbc (for me)
sudo ln /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so libtdsodbc.so
should help
I was having the same problem. In my situation, the username for the Microsoft SQL Server database was in the form, DOMAIN\userid. However, when I typed it on the command line, I think it was interpreting the slash as an escape character. When I tried putting the slash the other direction, it still failed. Finally, I tried putting two slashes in the original direction and it worked. Thus the following worked for me:
tsql -S myhost -U DOMAIN\\userid
I encountered the same error. Then I did the following, and the error went away:
pip install pyodbc
Previously, I had used quotes for the DB server, username, and pwd in the TSQL command. This time, I removed the quotes.

Resources