pyodbc.Interfaceerror: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Name of data source not found

Asked

Viewed 1,304 times

0

I am creating a code to perform an adjustment in a sql server database, but when trying to run it is returning error:

pyodbc.Interfaceerror: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Name of data source not found and no default driver specified (0) (Sqldriverconnect)')

I tried in version 2016 and 2019 of sql server, python version 3.9, windows 10.

The code is as follows:

import pyodbc

def retorna_conexao_sql():
    server = "ALEXANDRE-PC\ARC"
    database = "DB_ARC"
    username = "sa"
    password = "#abc123#"
    string_conexao = 'Driver = {ODBC Driver 17 for SQL Server}; Server = '+server+'; Database = '+database+'; UID = '+username+'; PWD='+ password
    conexao = pyodbc.connect(string_conexao)
    return conexao.cursor()
cursor = retorna_conexao_sql()
cursor.execute("""update wfiscal.sped_ajuste set codigo = 'ES70009702', descricao_complementar = 'DEBITO ESPECIAL: Diferencial de Alíquota pela entrada' 
from wfiscal.m00001 inner join wfiscal.sped_ajuste
on M00001.CdNota = sped_ajuste.nota_id and M00001.IdCodFiscal = 2407 and codigo is null""")

Could you help me?

1 answer

0

import pyodbc
    
def retorna_conexao_sql():
        

        server = "ALEXANDRE-PC\ARC"
        database = "DB_ARC"
        username = "sa"
        password = "#abc123#"
    
        cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
    
       
        return cnxn.cursor()

The error was in the connection string where there were some spaces between the elements, I refactored the same so it is possible to connect.

GIST

Browser other questions tagged

You are not signed in. Login or sign up in order to post.