InterfaceError: (pyodbc.InterfaceError) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

Addie, Andrew 6 Reputation points
2022-06-29T19:52:40.257+00:00

I was required to update Anaconda and now when I try to connect sqlalchemy to my database I get the error above. The command I previously used is below
engine = create_engine('mssql+pyodbc://' + server + '/' + database + '?driver=SQL Server?Trusted_Connection=yes', echo = True)
I am very much a NOOB with all these connection issues and appreciate the help. How do I fix this? What other information do you need to help?

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,655 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Una Fan 5 Reputation points
    2023-02-02T06:16:40.43+00:00

    You can use Anaconda Prompt to run cmd "conda install -c anaconda pyodbc" as admin and then run jupyter or python

    import pyodbc [x for x in pyodbc.drivers()]

    you will see 'SQL Server' in the result of the cmds and use "DRIVER={SQL Server};" for your DB connection

    1 person found this answer helpful.

  2. YufeiShao-msft 7,056 Reputation points
    2022-06-30T02:43:13.307+00:00

    Hi @Addie, Andrew

    First of all, it should be clear that this is a SQL Server forum, we are not familiar with sqlalchemy and cannot give help with it.

    Please check version of ODBC driver, not sure if the code you shown is complete, but you may need 'DRIVER={ODBC Driver 17 for SQL Server}' instead driver=SQL Server

    https://datadiaries.dev/connecting-to-microsoft-sql-server-using-sqlalchemy-and-pyodbc

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.