我正在使用 SqlBulkCopy 类执行 SQL 大容量复制。我创建了与源表完全相同的目标表。它们都具有相同的表名、列名、数据类型甚至相同的排序规则。我还做了sql映射以确保准确性。
我的代码如下:
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();
}
}
但是,每次执行代码时,都会出现以下错误:
源列“CreatedBy”的区域设置 ID“1025”与目标列“CreatedBy”的区域设置 ID“1033”不匹配。
我在互联网上搜索了很多,但没有找到任何解决方案。如果有人帮助我,我将非常感激。