C# 4.0 SQL Server将6000000条记录从一台服务器传输到另一台服务器-快速
使用SQL Server 2005在不同位置的两台服务器之间传输6000000条记录的最快方法是什么?考虑在下面的C.Net示例中使用bulkcopy。您可以设置每笔交易要传输的记录数。根据网络速度,将在几分钟内传输。我必须转移每个城市的IP表,我使用下面的代码C# 4.0 SQL Server将6000000条记录从一台服务器传输到另一台服务器-快速,c#-4.0,sql-server-2005,C# 4.0,Sql Server 2005,使用SQL Server 2005在不同位置的两台服务器之间传输6000000条记录的最快方法是什么?考虑在下面的C.Net示例中使用bulkcopy。您可以设置每笔交易要传输的记录数。根据网络速度,将在几分钟内传输。我必须转移每个城市的IP表,我使用下面的代码 public class BulkCopy { public string IPCIDADE() { string ret = ""; using (SqlConnection sour
public class BulkCopy
{
public string IPCIDADE()
{
string ret = "";
using (SqlConnection sourceConnection =
new SqlConnection(@"Data Source=xxxx;Initial Catalog=xxxx;Persist Security Info=True;User ID=xxx;Password=xxx"))
{
sourceConnection.Open();
// Get data from the source table as a SqlDataReader.
SqlCommand commandSourceData = new SqlCommand(
"SELECT [IP_START], [IP_END], [PAIS], [ESTADO], [CIDADE] FROM [dbo].[IPCIDADE];", sourceConnection);
SqlDataReader reader =
commandSourceData.ExecuteReader();
// Open the destination connection. In the real world you would
// not use SqlBulkCopy to move data from one table to the other
// in the same database. This is for demonstration purposes only.
using (SqlConnection destinationConnection =
new SqlConnection("Data Source=xxxx;Initial Catalog=xxxx;Persist Security Info=True;User ID=xxxxxxxxx;Password=xxxxxxxxx"))
{
destinationConnection.Open();
// Set up the bulk copy object.
// Note that the column positions in the source
// data reader match the column positions in
// the destination table so there is no need to
// map columns.
using (SqlBulkCopy bulkCopy =
new SqlBulkCopy(destinationConnection))
{
bulkCopy.DestinationTableName =
"[dbo].[IPCIDADE]";
bulkCopy.BatchSize = 1000; //Number of records by transaction
bulkCopy.BulkCopyTimeout = 0;
try
{
// Write from the source to the destination.
bulkCopy.WriteToServer(reader);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
// Close the SqlDataReader. The SqlBulkCopy
// object is automatically closed at the end
// of the using block.
reader.Close();
}
}
}
}
return ret;
}
}
不允许我在源服务器上获取备份文件。该位置处于另一个状态。我只有读取权限和仅在数据库中生成schemma脚本的权限。