Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlBulkCopy Login Failed

Tags:

sql-server

I have an issue with SqlBulkCopy command when using SQL Server authentication. The issue does not arise with Windows authentication.

SqlBulkCopy sbc = new SqlBulkCopy(sqConn.ConnectionString, SqlBulkCopyOptions.KeepIdentity);

this throws an error:

Login failed for user 'xx'

Code:

SqlBulkCopy sbc = new SqlBulkCopy(sqConn);

This works fine but does not preserve identity column original values.

like image 300
davehay Avatar asked Feb 05 '23 15:02

davehay


1 Answers

"persist security info=true" is required in the connection string. Otherwise password is stripped from sqlConn.ConnectionString if the connection is already open.

like image 81
Nullkiller Avatar answered Feb 16 '23 11:02

Nullkiller