Search code examples
pythonsql-serverpymssql

Error Executing Stored Procedure that References Linked Server with PyMSSQL


I'm trying to execute a stored procedure from a python script, via pymssql, that communicates with a linked server. The SP works when run manually, but when run from the python script errors out with:

(7391, 'The operation could not be performed because OLE DB 
provider"SQLNCLI11" for linked server "DBLOG" was unable to begin a 
distributed transaction.DB-Lib error message 20018, severity 16:
\nGeneral SQL Server error: Check messages from the SQL Server\n')

I haven't been able to find anything that references this as a limitation within pymssql itself. I'm not quite sure where to start. I do quite a bit of work with pymssql and have never had any connection issues, and I have verified that the login I am using has sufficient permissions (I even tried using SA).

Any ideas?

Thank you!


Solution

  • I was able to recreate the issue with an SP that tried to do an UPDATE on the linked server, e.g.,

    UPDATE LINKEDSERVERNAME...TableName SET ...
    

    although my error message was slightly different

    (8501, "MSDTC on server 'PANORAMA\SQLEXPRESS' is unavailable.DB-Lib error message 20018, ...

    I was able to avoid the issue by adding an autocommit=True argument to the end of my pymssql.connect call.

    If for some reason using autocommit=True is no good for you then have a look at

    MSDTC on server 'server is unavailable

    for information on configuring MSDTC.