bcpy
bcpy copied to clipboard
Can't use trustservercertificate=yes bcp
Was not possible to set the parameter -u that permit Trust server certificate. (available since bcp version 18).
https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/connecting-with-bcp?view=sql-server-ver16
I did the modification below and works:
def bcp(sql_table, flat_file, batch_size):
"""Runs the bcp command to transfer the input flat file to the input
SQL Server table.
:param sql_table: The destination Sql Server table
:type sql_table: SqlTable
:param flat_file: Source flat file
:type flat_file: FlatFile
:param batch_size: Batch size (chunk size) to send to SQL Server
:type batch_size: int
"""
if sql_table.with_krb_auth:
auth = ['-T']
else:
auth = ['-U', sql_table.username , '-P', sql_table.password ]
full_table_string =
f'{sql_table.database}.{sql_table.schema}.{sql_table.table}'
try:
bcp_command = ['bcp', full_table_string, 'IN', flat_file.path, '-f',
flat_file.get_format_file_path(), '-S',
sql_table.server, '-b', str(batch_size), '-u'] + auth