Im using Debian machine and I was trying to connect to remote sql server, but encounter the error when I try to connect via isql:
root#debian:~/installtest# isql -v SQLServer-Conn
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[37000][unixODBC][FreeTDS][SQL Server]Login failed for user ''.
[ISQL]ERROR: Could not SQLConnect
Here is my odbc.ini
[SQLServer-Conn]
Description=MS SQL connection to remote db
Driver=FreeTDS
Server=10.xx.xx.xx
Port=49xxx
User=username
Password=password
Database=remotedb
Trace=No
Here is my odbcinst.ini
[FreeTDS]
Description = ODBC for SQL Srv
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
UsageCount = 1
The db was fine as I was able to connect using this same machine via tsql command. So i'm not sure if im missing something on the .ini files
Thanks for the help
You need to pass isql a username and password in addition to your DSN.
isql -v SQLServer-Conn username password
Give that a try - good luck!
Related
I am trying to connect to MS SQL Server using pyodbc from a remote machine running Ubuntu 16.04.
import pyodbc
conn = pyodbc.connect(r'DRIVER=ODBC Driver 17 for SQL Server; SERVER=xxxTest-SRV; PORT=51333; DATABASE=TestDB; UID=xxxx; PWD=xxxx;')
I'm getting following error:
pyodbc.OperationalError: ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC
Driver 17 for SQL Server]Login timeout expired (0)
(SQLDriverConnect)')
I tried using the server IP in the connection string but still no luck.
However, I am able to connect to using sqlcmd from the terminal
Following works:
sqlcmd -S xxxTest-SRV, 51333 -d TestDB -U xxxx -P xxxx
I didn't find any issue that gave an answer to my problem.
odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-17.1.so.1.1
UsageCount=1
There's always seems to be an issue connecting to MS SQL Server using pyodbc from a linux machine. Is there a way to connect to SQL Server from Python. I'll appreciate your help in solving this error. Thank you.
[UPDATE]
As per the below answer, I updated the connection string. But, now I get following error:
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open
lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.0.so.1.1' : file
not found (0) (SQLDriverConnect)")
My odbcinst.ini file driver definition:
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.0.so.1.1
UsageCount=1
It has always been a nightmare to connect to MS SQL Server from a Linux machine. Can you please tell which pyodbc, unixODBC and Driver version is the most stable?
I have installed the driver following this Microsoft instructions. My pyodbc version is 4.0.23
Microsoft's ODBC drivers for SQL Server do not use a PORT= parameter. The port number, if any, is appended to the server name/IP with a comma, e.g.,
SERVER=xxxTest-SRV,51333;
I ran into the same kind of issue, but my scenario is connecting to SQL server hosted on ec2 instance through AWS Lambda function using PyOdbc module. For me, replacing the host name with IP address of ec2 instance fixed it.
I found out that it was not able to resolve dns. So if any of the above steps didn't work for you, please try using the ip address and comment here
I ran into same problem when working with SQL Server docker container inside VS Code development container. Finding the IP of SQL Server container (credits for that goes to freecodecamp.org How to get docker container IP address) and replacing server name with IP solved the problem
conn = pyodbc.connect(
"DRIVER={ODBC Driver 17 for SQL Server};" + "SERVER=172.xx.x.x;"
"DATABASE=xxx;"
"UID=sa;"
"PWD=xxx;")
What solved in my case was to configure in the "SQL Configuration Manager" --> SQL Server Network Configuration --> Protocols for XYX --> TCP/IP --> Properties --> IP Addresses --> IPAII (Here set empty in TCP Dynamic Ports and 1433 (or the port that you want to use) at TCP Port)
You can have more details here
Microsoft's ODBC drivers for Linux cannot resolve instance names, so this won't work from a Linux client:
Server = mydbserver.mycompany.com\SQLEXPRESS
If you need to connect to a named instance you can use the (free) sqlserverport (https://github.com/gordthompson/sqlserverport) module.
import pyodbc
import sqlserverport
servername = 'myserver'
serverspec = '{0},{1}'.format(
servername,
sqlserverport.lookup(servername, 'SQLEXPRESS'))
conn = pyodbc.connect('DRIVER=ODBC Driver 17 for SQL Server;SERVER={};...'.format(serverspec))
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?
My OS is Scientific Linux 7.5 and wants to connect to MS SQL server using python 2.7.5 i have configured unixODBC 2.3.1 and Microsoft ODBC Driver 13 for SQL Server
But when i use the following code:
import pyodbc
cnxn = pyodbc.connect(
'Driver={/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.1.so.9.2};'
'Server=localhost;'
'User=sa;'
'Password=xxx;'
'Database=yyy;'
'Trusted_Connection=yes;')
i get the following error
pyodbc.Error: ('HY000', u'[HY000] [unixODBC][Microsoft][ODBC Driver 13 for SQL Server]SSPI Provider: No Kerberos credentials available (default cache: KEYRING:persistent:1000) (851968) (SQLDriverConnect)')
and got the same error when used 'Driver={ODBC Driver 13 for SQL Server};'
if i use 'Driver={SQL Server};' i got stuck on following error
pyodbc.Error: ('01000', u"[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")
You should remove 'Trusted_Connection=yes;' from your connection string. It is used for Windows authentication, while you are trying to connect with SQL authentication (providing user name and password).
An alternate cause and solution, in case anyone ends up here for this reason:
If you're relying on an env file to populate the Username and Password components of the pyodbc connection string, and something goes wrong with your execution such that those values are not accessible, then you will get that No Kerberos credentials available error message.
Check the value of the connection string; in my case, the username and password were missing from the SQLAlchemy engine string when I printed it. Running my docker container with the proper --env-file= flag addressed this case.
I am having issue with unixODBC. I need multiple connections to different Sql server instances and all of them are working except one. It has additional parameter in host.
All host are ip or just host name, but one which is ont working has IP\smth
I have tried:
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0
Database=dbname
Server=192.168.1.1/PARAM
Port=1433
Also tried escaping, quotes, etc.
isql -v returns:
[S1T00][unixODBC][Microsoft][ODBC Driver 13 for SQL Server]Login timeout expired
[08001][unixODBC][Microsoft][ODBC Driver 13 for SQL Server]MAX_PROVS: Error Locating Server/Instance Specified [xFFFFFFFF].
[08001][unixODBC][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.
[ISQL]ERROR: Could not SQLConnect
I could connect from MAC OSX (Sierra) via unixODBC to SQL Server 2017 (installed in a docker container using this image: https://hub.docker.com/r/microsoft/mssql-server-linux/) by following these steps:
Install the ODBC driver as described here: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server
Find out in which odbc.ini config file the system DSNs are stored and where to find the ODBC driver name:
odbcinst -j
...
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
...
Remember the exact driver name from the odbcinst.ini file (preconfigured from the driver installation from step 1):
...
[ODBC Driver 13 for SQL Server]
...
Edit the odbc.ini file and add a DSN to your database (all allowed keywords are described here: https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/connection-string-keywords-and-data-source-names-dsns):
...
[MSSQLTest]
Driver = ODBC Driver 13 for SQL Server
Server = 192.168.178.1,1433
...
Note: Use your server IP address (or server name) and port number here.
Test the connection (it should work now):
isql MSSQLTest sa Password12345 -v
Note: Replace the user name "sa" and the password "Password12345" with your own credentials!
You should see then:
Connected!
Enjoy your hot caffeinated beverage ;-)
I am trying to connect to SQL Server running on Windows from a Redhat machine. I can login to the server through the "SQL Server" account but not from a "Windows Authentication" account. I tried all sorts of tricks - but none worked:
# isql FBI_MS CORP\\Kapilv kapil
# isql FBI_MS 192.168.14.158\\CORP\\Kapilv kapil
# isql FBI_MS 'CORP\Kapilv' kapil
I also googled and came across: https://askubuntu.com/questions/167491/connecting-ms-sql-using-freetds-and-unixodbc-isql-no-default-driver-specified
I have unixODBC drivers but do not have freetds. I should still be able to connect without freetds. Or is it impossible to connect with just unixODBC drivers?
-- I installed freetds as suggested by Benny Hill and followed the configurations - I could still not get it to work.
odbc.ini:
[FBI_MSW]
Description = FBI MS SQL Server database using freetds
Driver = freetds
Database = FBI
ServerName = 192.168.14.158
TDS_Version = 8.0
odbcinst.ini (RedHat installation of freetds does not come with a Set Up file
[freetds]
Description = MS SQL database access with Free TDS
Driver = /usr/local/freetds/lib/libtdsodbc.so
Setup =
TraceFile = /tmp/freetds.log
FileUsage = 1
UsageCount = 1
Now, when I try to connect - I get the following error messages:
[root#localhost sqlncli-11.0.1790.0]# isql -v FBI_MSW CORP\\Kapilv kapil
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect
I cannot even connect to SQL Server account through freetds (which i could without freetds) - what can i say about Windows Authentication account?
What is the error message you got?
It is better to be sure, if you can reach the MS SQL server, so try: telnet 192.168.14.158 1433 (or the port it is running on)
You will need to install FreeTDS.
Look at this question and the answer I submitted there to see configuration examples.