Python - using pyodbc to connect to a remote server using information from an Excel data connection

I have excel (although the one on our company server) that has a data connection for our SQL database, so we can create nice pivot tables.

I would like to get this data in python (on my local computer) so that I can perform a faster analysis.

I installed pyodbc.

Here is the connection string from excel:

Provider=SQLOLEDB.1;Password=**mypassword**;Persist Security Info=True;User
ID=**myusername**;Initial Catalog=**catalogename**;Data 
Source=**datasourcename**;Use Procedure for Prepare=1;Auto 
Translate=True;Packet Size=4096;Workstation ID=**workstationid**;Use 
Encryption for Data=False;Tag with column collation when possible=False

and now I have a python script:

import pyodbc
cnxn = pyodbc.connect(DRIVER='{SQL Server}',SERVER='***server ip address**',DATABASE='**cataloguename**',UID='**myusername**',PWD='**mypassword**')
cursor = cnxn.cursor()

and I get errors saying that SQL Server does not exist or access is denied.

Any help is appreciated.

+4
source share
2 answers

, ... - :

cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=192.168.123.456;PORT=1433;DATABASE=yourdb;UID=your_user;PWD=your_pw;')

!

+3

, SQL-, - - ODBC

-1

Source: https://habr.com/ru/post/1616097/


All Articles