Menu

#5 Operational Error trying to connect to an SLQ Server DB

v1.0_(example)
closed
None
5
2020-12-17
2020-12-17
No

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?

Discussion

  • Giuseppe Cattaneo

    I've just tried using IDLE instead of Visual studio code and this is what I get after I run the connection command:

    >>> conn = adodbapi.connect(conn_string)
    Traceback (most recent call last):
      File "C:\Users\cattaneo.DOMAIN1\AppData\Local\Programs\Python\Python39\lib\site-packages\adodbapi\adodbapi.py", line 97, in make_COM_connecter
        c = Dispatch('ADODB.Connection') #connect _after_ CoIninialize v2.1.1 adamvan
    NameError: name 'Dispatch' is not defined
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\Users\cattaneo.DOMAIN1\AppData\Local\Programs\Python\Python39\lib\site-packages\adodbapi\adodbapi.py", line 116, in connect
        co.connect(kwargs)
      File "C:\Users\cattaneo.DOMAIN1\AppData\Local\Programs\Python\Python39\lib\site-packages\adodbapi\adodbapi.py", line 266, in connect
        self.connector = connection_maker()
      File "C:\Users\cattaneo.DOMAIN1\AppData\Local\Programs\Python\Python39\lib\site-packages\adodbapi\adodbapi.py", line 99, in make_COM_connecter
        raise api.InterfaceError ("Windows COM Error: Dispatch('ADODB.Connection') failed.")
    adodbapi.apibase.InterfaceError: Windows COM Error: Dispatch('ADODB.Connection') failed.
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<pyshell#3>", line 1, in <module>
        conn = adodbapi.connect(conn_string)
      File "C:\Users\cattaneo.DOMAIN1\AppData\Local\Programs\Python\Python39\lib\site-packages\adodbapi\adodbapi.py", line 120, in connect
        raise api.OperationalError(e, message)
    adodbapi.apibase.OperationalError: (InterfaceError("Windows COM Error: Dispatch('ADODB.Connection') failed."), 'Error opening connection to "Provider=SQLOLEDB;Data Source=V01DB2\\XXXXX;User ID=XXXXXX;Password=XXXXXX;Initial Catalog=PMT;"')
    >>> 
    
     
  • Giuseppe Cattaneo

    SOLVED
    I did not have pywin32 installed (I found nowhere that I have to install it).
    After installing it, all work fine.

     
  • Vernon Cole

    Vernon Cole - 2020-12-17

    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.

     
  • Vernon Cole

    Vernon Cole - 2020-12-17
    • status: open --> closed
    • assigned_to: Vernon Cole
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.