C# bulkCopy.WriteToServer不复制

C# bulkCopy.WriteToServer不复制,c#,sql-server-express,C#,Sql Server Express,我正在尝试使用bulkCopy.WriteToServer()将数据从远程SQL Server Express复制到本地SQL Server Express,但从未将任何数据写入本地SQL Server Express数据库 代码立即跳过WriteToServer()方法。。。我不知道它是否在内部出现故障,并且没有显示错误消息 我已经读过,我正在使用非常相似的代码。虽然我在SQL Server 2014 Express的远程和本地上使用SQL Server 2008 Express: using

我正在尝试使用
bulkCopy.WriteToServer()
将数据从远程SQL Server Express复制到本地SQL Server Express,但从未将任何数据写入本地SQL Server Express数据库

代码立即跳过
WriteToServer()
方法。。。我不知道它是否在内部出现故障,并且没有显示错误消息

我已经读过,我正在使用非常相似的代码。虽然我在SQL Server 2014 Express的远程和本地上使用SQL Server 2008 Express:

using (SqlConnection remoteConnection = new SqlConnection(remoteConnectionString))
{
    var query = "SELECT * FROM information_schema.tables WHERE table_type = 'base table'";
    SqlCommand commandGetTables = new SqlCommand(query, remoteConnection);

    try
    {
        remoteConnection.Open();
        SqlDataReader results = commandGetTables.ExecuteReader();

        while (results.Read())
        {
            tables.Add(results.GetString(2));
        }

        results.Close();
    }
    catch (Exception ex)
    {
        //stuff
    }
    finally
    {
        remoteConnection.Close();
    }

    remoteConnection.Open();

    foreach (var table in tables)
    {                    
        // Get data from the source table as a SqlDataReader.
        var commandSourceData = new SqlCommand("SELECT * FROM " + table + ";", remoteConnection);
        var reader = commandSourceData.ExecuteReader();

        using (SqlConnection destinationConnection = new SqlConnection(destinationConnectionString))
        {
            destinationConnection.Open();

            using (var bulkCopy = new SqlBulkCopy(destinationConnection))
            {
                bulkCopy.DestinationTableName = table;

                try
                {
                    // Write from the source to the destination.
                    bulkCopy.WriteToServer(reader);
                }
                catch (Exception ex)
                {
                    //stuff
                }
                finally
                {
                    //stuff removed for this post
                }
            }
        }
    }

    remoteConnection.Close();
}
return true;
我知道这可能会受到SQL注入等,但这个应用程序只由我使用,而不是这里的问题

我做错了什么

编辑

我检查了reader的值(
var reader=commandSourceData.ExecuteReader();
),它有我所期望的条目,这意味着他可以从远程读取

bulkCopy.DestinationTableName = table;
bulkCopy.WriteToServer(reader);
这些线是错的应该是这样的

bulkCopy.DestinationTableName = "dbo." + DataTable.TableName; 
bulkCopy.WriteToServer(DataTable);

您收到了什么错误消息?如果这是测试中的真实代码,则该代码会抛出错误消息,而不会抛出错误消息。我在所有编写日志的catch语句中都有断点@马修斯:你没有提供mapping@GiorgiNakeuri源数据读取器中的列位置与目标表中的列位置匹配,因此无需映射列。这不对吗?@CodeSlinger,我想我不能运行SSIS包,因为我在Express上。我在C#中做这件事,所以将来我可以在GUI中添加新的数据库,比如IP、用户ID、密码、初始目录等,然后也备份这些数据库。。。但我可以尝试将其移动到SP