简体   繁体   中英

Getting error while creating pypyodbc connection python

i am trying to connect a database in sql server using pypyodbc in ubuntu.

below is my code:

import pandas as pd
import pypyodbc
host = "servername"
username = "sa"
password = "sa@12"
database = "dbname"

try:
    conn = pypyodbc.connect("DRIVER={SQL Server};SERVER=%s;UID=%s;PWD=%s;DATABASE=%s") % (host, username, password, database)
    print ("SUCCESS")
except Exception as e:
    print ("Error: " + str(e))

but i am getting this error.

Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified')

Is there a way to solve this?

This way:

import pandas as pd
import pypyodbc
host = "servername"
username = "sa"
password = "sa@12"
database = "dbname"

try:
    conn = pypyodbc.connect(driver='{SQL Server}',server=host,UID=username,pwd=password,database=database)
    print ("SUCCESS")
except pypyodbc.Error as e:
    print (e.args[1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM