BulkCopy error: The locale id '1025' of the source column 'CreatedBy' and the locale id '1033' of the destination column 'CreatedBy' do not match

asp.net c# sqlbulkcopy sql-server

Question

Using the SqlBulkCopy class, I'm executing SQL bulk copy. I made my destination table precisely the same as my source table when I established it. They are identical in terms of table name, column names, data types, and even collation. I also completed the SQL mapping to guarantee correctness.

Here is my code:

SqlConnection SourceConnection =  new SqlConnection(SourceConnectionString);
SqlConnection DestinationConnection =  new SqlConnection(DestinationConnectionString);

DestinationConnection.Open();
SourceConnection.Open();

SqlCommand commandSourceData = new SqlCommand("SELECT * FROM Requisitions;", SourceConnection);

SqlDataReader reader = commandSourceData.ExecuteReader();    

    using (SqlBulkCopy bulkCopy = new SqlBulkCopy(DestinationConnection))

    {
           bulkCopy.DestinationTableName = "Requisitions";


           bulkCopy.ColumnMappings.Add("RequisitionId", "RequisitionId");
           bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
           bulkCopy.ColumnMappings.Add("DateCreated", "DateCreated");
           bulkCopy.ColumnMappings.Add("AircraftTailNum", "AircraftTailNum");
           bulkCopy.ColumnMappings.Add("JobNumber", "JobNumber");
           bulkCopy.ColumnMappings.Add("ShopCode", "ShopCode");
           bulkCopy.ColumnMappings.Add("RequestedByName", "RequestedByName");
           bulkCopy.ColumnMappings.Add("RequestedById", "RequestedById");
           bulkCopy.ColumnMappings.Add("Status", "Status");
           bulkCopy.ColumnMappings.Add("IsCancelled", "IsCancelled");
           bulkCopy.ColumnMappings.Add("IsProcessed", "IsProcessed");


           try
               {
                  // Write from the source to the destination.
                  bulkCopy.WriteToServer(reader);
                }
          catch (Exception ex)
                {
                     Console.WriteLine(ex.Message);
                 }
          finally
                 {

                    reader.Close();
                  }
          }

But each time I ran my code, I encountered the following error:

The locale id '1025' of the source column 'CreatedBy' and the locale id '1033' of the destination column 'CreatedBy' do not match.

I've looked all over the internet for a solution, but to no avail. If someone could assist me, I would be eternally grateful.

1
5
12/21/2012 2:48:57 PM

Accepted Answer

Attempt this

  public DataTable fetchValue()
    {
        SqlDataAdapter dap=new SqlDataAdapter("SELECT RequisitionId,CreatedBy,DateCreated,AircraftTailNum,JobNumber,ShopCode,RequestedByName,RequestedById,Status,IsCancelled,IsProcessed FROM Requisitions;", cn);
        DataSet ds=new();
        dap.Fill(ds);
        return ds.Tables[0];
    }

        DataTable dtgenerate=new DataTable();
        dtgenerate=fetchValue();

       cn.open();
       using (SqlBulkCopy bulkCopy = new SqlBulkCopy(n))
       {
           bulkCopy.DestinationTableName = "Requisitions";//DestionTableName
           // bulkCopy.ColumnMappings.Add("SourceColumnIndex", "DestinationColumnIndex");  
           bulkCopy.ColumnMappings.Add("RequisitionId", "RequisitionId");
           bulkCopy.ColumnMappings.Add("CreatedBy", "CreatedBy");
           bulkCopy.ColumnMappings.Add("DateCreated", "DateCreated");
           bulkCopy.ColumnMappings.Add("AircraftTailNum", "AircraftTailNum");
           bulkCopy.ColumnMappings.Add("JobNumber", "JobNumber");
           bulkCopy.ColumnMappings.Add("ShopCode", "ShopCode");
           bulkCopy.ColumnMappings.Add("RequestedByName", "RequestedByName");
           bulkCopy.ColumnMappings.Add("RequestedById", "RequestedById");
           bulkCopy.ColumnMappings.Add("Status", "Status");
           bulkCopy.ColumnMappings.Add("IsCancelled", "IsCancelled");
           bulkCopy.ColumnMappings.Add("IsProcessed", "IsProcessed");

           bulkCopy.WriteToServer(dtgenerate);
       }
       cn.close();
2
12/10/2012 11:26:27 AM

Popular Answer

The source varchar columns' collation is different from the destination varchar columns' collation.

This may be avoided by loading first into a datatable, but if you are loading a lot of data, you will probably run into a System. OutOfMemoryException.



Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow