Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Archiving 10 Million Records
Message
 
À
11/06/2009 15:18:23
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Maintenance bases de données
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01405057
Message ID:
01405349
Vues:
47
I don't think the joins are causing any performance problems at this point. Moving 10 mil recs in under 40 seconds is pretty impressive if you ask me. I didn't think it was possible but playing around with the query enough we found way to copy and move data around pretty quickly.

Here the C# code using SqlBulkCopy
using (SqlConnection remoteConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ArchiveDb"].ConnectionString))
{
    using (SqlCommand remoteCmd = new SqlCommand("Get_RecordsToArchive", remoteConnection))
    {
        remoteCmd.CommandType = CommandType.StoredProcedure;
        remoteCmd.Parameters.AddWithValue("@ClientId", criteria.ClientId);
        remoteCmd.Parameters.AddWithValue("@MatchSetId", criteria.MatchSetId);
        remoteCmd.Parameters.AddWithValue("@AgedDate", criteria.AgedDate);
        remoteCmd.Parameters.AddWithValue("@BatchTableName", criteria.SourceTableName);
        remoteCmd.Parameters.AddWithValue("@DisplayCol", criteria.DisplayCol);
        try
        {
            remoteConnection.Open();
            SqlDataReader remoteReader = remoteCmd.ExecuteReader(CommandBehavior.CloseConnection);
            using (SqlConnection localConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ArchiveDb"].ConnectionString))
            {
                try
                {
                    localConnection.Open();
                    SqlBulkCopy localBulkCopy = new SqlBulkCopy(localConnection);
                    localBulkCopy.DestinationTableName = criteria.TargetTableName;
                    localBulkCopy.BatchSize = criteria.BatchSize;
                    localBulkCopy.NotifyAfter = criteria.NotifyAfter;
                    localBulkCopy.SqlRowsCopied += new SqlRowsCopiedEventHandler(ArchiveBatchTable_SqlRowsCopied);

                    localBulkCopy.WriteToServer(remoteReader);
                }
                finally
                {
                    localConnection.Close();
                }
            }
        }
        finally
        {
            remoteConnection.Close();
        }
    }
}
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform