1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[SQL] Connecting to Microsoft SQL server using Python

Discussão em 'Outras Linguagens' iniciado por Stack, Setembro 28, 2024 às 08:54.

  1. Stack

    Stack Membro Participativo

    I am trying to connect to SQL through python to run some queries on some SQL databases on Microsoft SQL server. From my research online and on this forum the most promising library seems to be pyodbc. So I have made the following code

    import pyodbc
    conn = pyodbc.connect(init_string="driver={SQLOLEDB}; server=+ServerName+;
    database=+MSQLDatabase+; trusted_connection=true")
    cursor = conn.cursor()


    and get the following error

    Traceback (most recent call last):
    File "C:\Users...\scrap.py", line 3, in <module>
    conn = pyodbc.connect(init_string="driver={SQLOLEDB}; server=+ServerName+; database=+MSQLDatabase+; trusted_connection=true")
    pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')


    I have looked at the folowing posts and tried changing my driver to {sql server} and have connected using ODBC links before in SAS, which is partially what my above code is based on, so don't think I need to install anything else.

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

    Pyodbc - "Data source name not found, and no default driver specified"

    Thanks

    Continue reading...

Compartilhe esta Página