1

I'm trying to connect a raspberry pi 3 to a local SQL Server.

I did this:

sudo apt-get install unixodbc
sudo apt-get install unixodbc-dev
sudo apt-get install freetds-dev
sudo apt-get install tdsodbc
sudo apt-get install freetds-bin 

sudo pip3 install pyodbc
sudo apt-get install python-pyodbc


sudo nano /etc/freetds/freetds.conf

Added this block

[sqlserver]
      host = 192.168.0.109   # Sql Server's IP addr
      port = 1433           #  default
      tds version = 7.0     # 
      instance = Database1     # Database name 

now in /etc/odbcinst.ini

[FreeTDS]
Description = FreeTDS unixODBC Driver
Driver = /usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Setup = /usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
UsageCount = 1

and in /etc/odbc.ini file as follows:

[NAME1]
Driver = /usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Description = MSSQL Server
Trace = No
Server = ServerName1    
Database = Database 1
Port = 1433          
TDS_Version = 7.4

when I run

tsql -S sqlserver -U username 

I can connect t the database and run queries, but When I try

tsql isql NAME1 user 'password' 

I get

[ISQL]ERROR: Could not SQLConnect

I got a python script with

class SQL:

cnxn = None
cursor= None
def __init__(self):
try:
self.cnxn = pyodbc.connect('DRIVER={FreeTDS}; SERVER= ws2016_01; DATABASE=databasename; UID=user; PWD=password;TDS_Version=7.2;')
self.cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
self.cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
self.cnxn.setencoding(encoding='utf-8')

And I keep getting the error

[08001] [FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)

Thanks for reading, any help would be deeply appreciated!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
altdave
  • 108
  • 1
  • 10
  • Try `isql NAME1 username password -v` to see if you get a more descriptive error message. – Gord Thompson Nov 08 '19 at 20:43
  • You will probably also want to find what TDS Version you are using, and use the same on everywhere. It depends on your version of SQL Server and FreeTDS: https://www.freetds.org/userguide/choosingtdsprotocol.htm Depending on your version of Ubuntu, you may not have support to version 7.4. Try 7.3 or 7.2 in your `odbc.ini`. – FlipperPA Nov 10 '19 at 03:10
  • Use this: sudo dpkg-reconfigure tdsodbc https://raspberrypi.stackexchange.com/questions/60792/install-python-module-pyodbc-on-pi – Jace Dec 17 '19 at 22:02

0 Answers0