0

I have tried multiple ways to create a connection but have been unsuccessful. I have attempted to install unixobdc. I get it downloaded but I cannot seem to get a driver... I am unsure what I am doing wrong.

I am using a Raspberry Pi 3 running Linux Debian 11 ARM.

For SQL I am using SQLEXPRESS on a 2022 MS Server

This is my connection string: import pyodbc


conn = pyodbc.connect('Driver={SQL Server};'
                      'Server=myservername\SQLEXPRESS'
                      'Database=mydatabasename;'
                      'Trusted_Connection=yes;')

The error message I receive:

conn = pyodbc.connect('Driver={SQL Server};'

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found (0) (SQLDriverConnect)")

I have tried editing my odbcinst file for the driver and did still did not work.

I am not sure what else I should try doing. I have even tried pointing my Driver to the name of the ini that I changed it to, still with no luck.

For Example

GNU nano 5.4 /etc/obdc.ini

[Name Here]
Description = Description
Driver = /etc/odbcinst.ini
Database = Databasename
Servername = ServerName
UID = Username
PWD = Password

This us the error I receive:

conn = pyodbc.connect('Driver={Name Here};'
pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'Name Here' : file not found (0) (SQLDriverConnect)")

Any help would be greatly appreciated!

Thank you.


UPDATE 06/26/23

I still have not had any luck fully getting this implemented. Although I am running into a different error code with trying SQLServerport.

I have done the following:

edited the obdcinst.ini to this:

'[ODBC Driver 17 for SQL Server]
 Description=Microsoft ODBC Driver 17 for SQL Server
 Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql- 
 17.4.so.1.1
 UsageCount=1'

OBDC.ini

'[MSSQLServerDatabase]
  Driver      = ODBC Driver 17 for SQL Server
  Description = Connect to my SQL Server instance
  Trace       = No
  Server      = *Servername*\SQLEXPRESS'

python code:

'# test data
server_name = "*Servername*\SQLEXPRESS"
instance_name = "SQLEXPRESS"

try:
  result = r"Instance {0}\{1} is listening on port 
  {2}.".format(
    server_name,
    instance_name,
    sqlserverport.lookup(server_name, instance_name),
    )
except sqlserverport.BrowserError as err:
    result = err.message
except sqlserverport.NoTcpError as err:
    result = err.message

print(result)'

with this I am getting the following error :

'Traceback (most recent call last):
 File "/home/kshaw/Test.py", line 59, in <module>
 sqlserverport.lookup(server_name, instance_name),
 File "/home/kshaw/.local/lib/python3.9/site- 
 packages/sqlserverport/sqlserverport.py", line 60, in 
 lookup
 sock.sendto(udp_message, (server, udp_port))
 socket.gaierror: [Errno -2] Name or service not known'

I am not sure what else I may have been missing, any help would be greatly appreciated and I truly appreciate the help this far!


UPDATE 6/27/23

After slightly rewriting my code I was able I was able to get it partially working.

'# Try to connect to SQL Server
 server_name = "xxx.xx.xx.xx"
 instance_name = "SQLEXPRESS"

 try:
    result = r"Instance {0}\{1} is listening on port 
    {2}.".format(
    server_name,
    instance_name,
    sqlserverport.lookup(server_name, instance_name),
    )
    except sqlserverport.BrowserError as err:
    result = err.message
    except sqlserverport.NoTcpError as err:
    result = err.message

    print(result)'

This is what prints:

'Instance xxx.xx.xx.xx\SQLEXPRESS is listening on port 
 1433.'

However, I think do the connection string and I get an error:

Connection String error:

'Traceback (most recent call last):
 File "/home/kshaw/test1.py", line 71, in <module>

pyodbc.connect('DSN=MSSQLServerDatabase;UID=myuid;PWD=mypwd')

'pyodbc.Error: ('01000', "[01000] [unixODBC][Driver 
 Manager]Can't open lib 
'/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.4.so.1.1' 
 : file not found (0) (SQLDriverConnect)")'
8
  • github.com/mkleehammer/pyodbc/wiki/… Commented Jun 25, 2023 at 14:41
  • Thank you, I will give it a try and let you know how it goes. Commented Jun 25, 2023 at 15:52
  • I have tried and still no luck, I will update the thread to show where I am stuck. Commented Jun 26, 2023 at 18:19
  • server_name should be just the server name or IP, not servername\SQLEXPRESS Commented Jun 26, 2023 at 19:46
  • Thank you it may be fixed, I messed with the Py code a little bit more. I am not at work and I will need to wait to have it on the internet there but I think this could be a good sign, I received this error. 'Traceback (most recent call last): File "/home/kshaw/Test.py", line 59, in <module> sqlserverport.lookup(server_name, instance_name), File "/home/kshaw/.local/lib/python3.9/site- packages/sqlserverport/sqlserverport.py", line 60, in lookup sock.sendto(udp_message, (server, udp_port)) socket.gaierror: [Errno -5] No address associated with hostname' Commented Jun 26, 2023 at 21:35

1 Answer 1

0

Just had a similar problem. Seems like the file odbcinst.ini does not get created. I followed this guide: https://forums.raspberrypi.com//viewtopic.php?t=172498

and changed SQL server in my code to FreeTDS and that worked for me

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, I will give it a try when I go in tomorrow and let you know how it goes. I have also been keeping a running log of all the things that I have tried and will work with your solution and also try to work with the one by Gord. I hope that between these 2 I should be good to go! :) thanks again for everyone's contribution.
I wish you good luck, my next step is trying to connect my sql server and the pi. I have the feeling my firewall is blocking it.
Have you looked at adding your Pi to the AD? I have found and saved some documentation on how to do so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.