Can SqlBulkCopy be used with a SQL Server Compact database?

sqlbulkcopy sql-server sql-server-ce

Question

I have a live database and a local database and I want to copy a large amount of data in my live database using (SqlClient) to my local database (SqlServerCe - SQL Server CE database). How can I do that?

Accepted Answer

Yes, I have a SqlCeBulkCopy library/Nuget package that you can use:

https://github.com/ErikEJ/sqlcebulkcopy

Sample code:

using ErikEJ.SqlCe;

private static void DoBulkCopy(bool keepNulls, IDataReader reader)
{
    SqlCeBulkCopyOptions options = new SqlCeBulkCopyOptions();
    if (keepNulls)
    {
        options = options |= SqlCeBulkCopyOptions.KeepNulls;
    }
    using (SqlCeBulkCopy bc = new SqlCeBulkCopy(connectionString, options))
    {
        bc.DestinationTableName = "tblDoctor";
        bc.WriteToServer(reader);
    }
}



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why