Anyone know why this error comes up when trying to connect python to sql server with pypyodbc

114 Views Asked by At

Error message:

('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified') task is terminated

import sys
import pandas as pd
from faker import Faker
from collections import defaultdict
import pypyodbc as odbc

DRIVER = 'ODBC Driver 17 for SQL Server'
SERVER_NAME = 'LAPTOP-CMEDO1TK'
DATABASE_NAME = 'fakeData'


conn_string = """
    Driver={DRIVER};
    Server={SERVER_NAME};
    Database={DATABASE_NAME};
    Trusted_Connection=yes;"""

try:
    conn = odbc.connect(conn_string)
except Exception as e:
    print(e)
    print("task is terminated")
    sys.exit()
else:
    cursor = conn.cursor

    

Here is my code. I've ran a for loop in python that printed my drivers and I am specifying one of the ones printed.

SQL Server
SQL Server Native Client 11.0
SQL Server Native Client RDA 11.0
ODBC Driver 17 for SQL Server
Microsoft Access Driver (*.mdb, .accdb)
Microsoft Excel Driver (
.xls, *.xlsx, *.xlsm, .xlsb)
Microsoft Access Text Driver (
.txt, *.csv)
ODBC Driver 18 for SQL Server
ODBC Driver 18 for SQL Server

0

There are 0 best solutions below