none
column do not match while using SqlBulkCopy RRS feed

  • Question

  • I'm using the SqlBulkCopy and keep geting the follwing error:

     

    The locale id '1033' of the source column 'Key' and the locale id '1037' of the destination column 'Key' do not match

    The Colums Type are nvarchar or int in the target and source tables, and they do match.

    replacing [ID] to '10001010' work fine, same effect was on column [Value].

     

    this is the code Used :

     

    string connectionString = @"XXX";

    using (SqlConnection sourceConnection =

    new SqlConnection(connectionString))

    {

    string sql = "select  'mirs' as [Table],[ID] as [Key], '' as [Value],pkid as [Row],0 as [Column] from mirs where [ID] is not null";

    SqlCommand myCommand =

    new SqlCommand(sql, sourceConnection);

    sourceConnection.Open();

    SqlDataReader reader = myCommand.ExecuteReader();

    // open the destination data

    using (SqlConnection destinationConnection =

    new SqlConnection(connectionString))

    {

    // open the connection

    destinationConnection.Open();

    using (SqlBulkCopy bulkCopy =

    new SqlBulkCopy(destinationConnection.ConnectionString, SqlBulkCopyOptions.TableLock|SqlBulkCopyOptions.KeepNulls))

    {

    bulkCopy.ColumnMappings.Add("Table","Table");

    bulkCopy.ColumnMappings.Add("Key", "Key");

    bulkCopy.ColumnMappings.Add("Value", "Value");

    bulkCopy.ColumnMappings.Add("Row", "Row");

    bulkCopy.ColumnMappings.Add("Column", "Column");

    bulkCopy.DestinationTableName = "[E100]";

    bulkCopy.BatchSize = 5000;

    bulkCopy.BulkCopyTimeout = 0;

    bulkCopy.WriteToServer(reader);

    bulkCopy.Close();

    }

    }

    reader.Close();

    }

     

    Thanks

     

    Sunday, September 30, 2007 9:11 PM

Answers