0

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

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • try [this](https://stackoverflow.com/questions/17115632/microsoftodbc-driver-manager-data-source-name-not-found-and-no-default-drive) answer – bn_ln Oct 09 '22 at 21:52
  • Thanks that was a useful thread to read through, however it didn't seem to fix my issue. i created a 32-bit driver that connected successfully when I tested it, however it still didn't help my python code run. I tried a 64-bit driver but it failed to connect when I tested the data source. I get this error message in my code now. ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.') task is terminated – Colby Farnham Oct 09 '22 at 22:31
  • Is there a particular reason you want to use `pypyodbc` instead of `pyodbc`? Have you tried `DRIVER = '{ODBC Driver 17 for SQL Server}'` yet? – AlwaysLearning Oct 10 '22 at 00:10
  • No specific reason. To be honest the tutorial I was looking at was using pypyodbc so that is what I went with. I'll look at pyodbc though. I have tried that entry for the Driver. I tried all the ones listed above lol. I also tried variations of this kind of package using sqlalchemy and sql.connector and they gave me connection issues as well. Thanks for commenting. – Colby Farnham Oct 10 '22 at 00:37
  • The curly brackets are important. Have you tried `DRIVER = '{ODBC Driver 17 for SQL Server}'` yet? – AlwaysLearning Oct 10 '22 at 02:23
  • Have you tried using the path to the driver file instead of the driver name? – Sanchez333 Oct 10 '22 at 10:22

0 Answers0