I'm running an Ubuntu 14.04.1 86_x64 server, and I've been trying to figure out how to connect to a MSSQL 2012 Contained Database. I've been trying with pymssql 2.1.0 which uses the FreeTDS driver. Based on the pymssql website I've determined that the problem is with the FreeTDS driver.
I've used tsql -H SERVER -p PORT -U USERNAME -P PASSWORD -D DATABASE
and I get the error:
Msg 18456 (severity 14, state 1) from SERVER Line 1:
"Login failed for user 'USERNAME'."
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
I don't have the same problem connecting to a MSSQL 2008 database, which does not support contained databases. Also, I have no control over that setting on the database.
Found that pymssql 2.1.1 fixes this as part of their 'Compatibility with Azure'.
The code that fixes it was in lines 606-613 in _mssql.pyx, which can be found on github. I've put the lines here just for reference.
# Put the DB name in the login LOGINREC because it helps with connections to Azure
if database:
if FREETDS_SUPPORTS_DBSETLDBNAME:
dbname_bytes = database.encode('ascii')
dbname_cstr = dbname_bytes
DBSETLDBNAME(login, dbname_cstr)
else:
log("_mssql.MSSQLConnection.__init__(): Warning: This version of FreeTDS doesn't support selecting the DB name when setting up the connection. This will keep connections to Azure from working.")