0
votes

I am trying to connect to SQL Server Database.

This is my script:

import sys
import pandas as pd
import pysftp
import pyodbc



sq_conn = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
                        "Server=someserver.com/;"
                        "Database=SomeDB;"
                        "uid=myid;pwd=password;"
                        "Trusted_Connection=yes;")

    
print("Starting to load data")
        
sql = "select top 100 * from table"
df = pd.read_sql(sql, sq_conn)
df.head(3)

And I am getting the following error:

sq_conn = pyodbc.connect("Driver={SQL Server Native Client 11.0};" pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'SQL Server Native Client 11.0' : file not found (0) (SQLDriverConnect)")

What am I missing?

Thank you.

1
Have you installed SQL Server Native Client 11.0 and configured it in /etc/odbcinst.ini? SNC dates from SQL Server 2005-2012 era, though. Consider installing ODBC 17 on Linux for newer development. - AlwaysLearning
@AlwaysLearning I did install ODBD17 for MacOS. It still gives me the same error. What am I missing or doing wrong? - dataeng
i changed the Driver to ODBC Driver 17 for SQL Server Now I get this error: 'pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')' - dataeng
Sorry, I did not notice this before... do you really have http://someserver.com/ in your connection string? Try using just someserver.com instead. - AlwaysLearning
Sorry for the confusion. I don't have http in my actual script, I fixed the question above. Still the same error. - dataeng

1 Answers

0
votes

It was a SQL Server Access issue. It is resolved now. All I had to do is get a user created under my name for that server, I was trying to use my windows credentials in the above script before which obviously was failing.

Thank you for all the help.