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)")'
server_nameshould be just the server name or IP, notservername\SQLEXPRESS