Hi,
Im' trying to connect with an MSSQLServer DB using a conenction string I use in another software.
This is the script I use to test connection:
import adodbapi def try_connection(): conn_string='Provider=SQLOLEDB;Data Source=V01DB2\mypath;User ID=myuser;Password=mypassword;Initial Catalog=PMT;' conn = adodbapi.connect(conn_string) return 'Connected' print(try_connection())
But when I debug it, I get this error:
Si è verificata un'eccezione: OperationalError (InterfaceError("Windows COM Error: Dispatch('ADODB.Connection') failed."), 'Error opening connection to "Provider=SQLOLEDB;Data Source=V01DB2\\TXSPA;User ID=PMTadmin;Password=123_pmtadmin;Initial Catalog=PMT;"') File "T:\Ufficio Tecnico Impiantistica Sicurezza\Div. Impianti Elettrici\Altri Impianti\Geppo\python\corsi e varie\DIGITALDOJO\Test_connessione_DB.py", line 5, in try_connection conn = adodbapi.connect(conn_string) File "T:\Ufficio Tecnico Impiantistica Sicurezza\Div. Impianti Elettrici\Altri Impianti\Geppo\python\corsi e varie\DIGITALDOJO\Test_connessione_DB.py", line 8, in <module> print(try_connection())
There are no suggestion about the specific problem. Could it be realted to the '\' char in the Data Source?
As I said, I use the same connection string from the same PC conenctiong to the DB using LabVIEW and all work fine.
Which could be the problem?
I've just tried using IDLE instead of Visual studio code and this is what I get after I run the connection command:
SOLVED
I did not have pywin32 installed (I found nowhere that I have to install it).
After installing it, all work fine.
Glad you found the problem.
Yes, pywin32 is required if you are running CPython.
I did not check for pywin32 at import time in this version of adodbapi in order to support Iron Python, which cannot call it.
I will have to drop support for Iron Python now, since Python 2 is deprecated in the pywin32 project. So this sourceforge project will become the Iron Python fork, while continued development of adodbapi will take place within the pywin32 repo.