francosy
francosy

Reputation: 153

pyodbc - cannot connect to DSN

I'm trying to connect to my database, but I can't establish connection. Here is my python code:

def connectToDB():
    connection = None

    while connection is None:
        try:
            connection = pyodbc.connect(r'DSN=FootNet;UID=root;PWD=password')
        except:
            print("\n[DB connector]  Error connecting to database. Trying again in 1 sec.")

        time.sleep(1)
    return connection

I set up DSN as follows:

ODBC Data Source Administrator

When I click test, the connection is successful. But I cannot connect in python. Any clues what could be a problem?

Any help would be appreciated.


edit:

I receive the following error:

pyodbc.Error: ('IM014', '[IM014] [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application (0) (SQLDriverConnect)')

Upvotes: 1

Views: 2344

Answers (1)

Ivan Vinogradov
Ivan Vinogradov

Reputation: 4473

According to the error message, the problem probably lies in the architecture mismatch between the driver and application (pyodbc) you're using.

So make sure that the driver and app are both using 32-bit / 64-bit version.

Upvotes: 3

Related Questions