Skip to content

Bulkcopy requires explicit TrustServerCetificate=yes with Encrypt=No #459

Closed

Description

Describe the bug

conn = mssql_python.connect("Server=192.168.105.105,1434;Database=aw;Uid=aa;Pwd=[mypwd];Encrypt=No;")
cur = conn.cursor()
cur.execute('create table #x (i int);')
cur.bulkcopy('#x', ((r,) for r in range(100)))

The above should work on a local sql server say in Docker.
But it throws an error

RuntimeError: Failed to connect to SQL Server: TLS handshake failed while connecting to '192.168.105.105': error:0A000086:SSL routines:tls_post_process_server_certificate:certificate verify failed:../ssl/statem/statem_clnt.c:1889: (self-signed certificate). Certificate SANs: (unavailable - handshake failed before certificate could be retrieved)

Work around

Use TrustServerCertificate=yes in the connection string with Encrypt=No

Reported here #414 (reply in thread)

Activity

  1. changed the title [-]Bulkcopy requires explicit TrustServerCetificate=True with Encrypt=No[/-] [+]Bulkcopy requires explicit TrustServerCetificate=yes with Encrypt=No[/+] on Feb 28, 2026
  2. github-actions commented on Feb 28, 2026

    @github-actions

    Hi Saurabh Singh (@saurabh500), thank you for opening this issue!

    Our team will review it shortly. We aim to triage all new issues within 24-48 hours and get back to you.

    If you have additional information to share, please feel free to update the issue.

    Thank you for your patience!

  3. DanielAdeniji commented on Mar 9, 2026

    @DanielAdeniji

    Saurabh Singh (@saurabh500),

    Fam, this has nothing to do with bulk-copy.

    # Why are you running Microsoft SQL Server on port 1434
    
    # by default, Microsoft SQL Server runs on port 1433
    
    #conn = mssql_python.connect("Server=192.168.105.105,1434;Database=aw;Uid=aa;Pwd=[mypwd];Encrypt=No;")
    
    conn = mssql_python.connect("Server=192.168.105.105,1433;Database=aw;Uid=aa;Pwd=[mypwd];Encrypt=No;")
    
    cur = conn.cursor()
    
    cur.execute('create table #x (i int);')
    
    cur.execute('insert into ##x (i) values (-1); ')
    
    cur.execute('drop table #x;')

    As an aside, why are you passing along port 1434?

    By default, SQL Server runs on port 1433.

    Unfortunately, the error that I received is:-

    
    [Microsoft][ODBC Driver 18 for SQL Server]SSL Provider: The certificate chain was issued by an authority that is not trusted.
    
    

    Relief came in specifying "encrypt=no".

    No need for TrustServerCertificate=yes.

    You may want to review the following, as well:-

    1. SQL Server Version

    2. SQL Server SSL Configuration ( is SSL set to be required )

    2a) if SSL is required, specifying "encrypt=no" will not skip the requirement for SSL.

    Thanks for reporting the issue.

    I am not sure how to re-create it .

    In as much as "cur.execute('create table #x (i int);')" works, you should not fail at "cur.bulkcopy('#x', ((r,) for r in range(100)))".

    Failing at bulkcopy will mean the bulkcopy code is attempting a new database connection.

    I will suggest you try

    cursor.execute("select @ServerName")

    in place of the bulkcopy.

    Nice question.

    And, thank you kindly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area: bulk-copyIssues in cursor.bulkcopy()triage neededFor new issues, not triaged yet.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions