You execute the method WriteToServer, and the following error is thrown:
Cannot access destination table '[TheInvalidTableName]'.
using(var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
{
connection.Open();
using (var sqlBulk = new SqlBulkCopy(connection))
{
// Oops! The destination name is Customer instead of Customers
sqlBulk.DestinationTableName = "Customer";
sqlBulk.WriteToServer(dt);
}
}
using(var connection = new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()))
{
connection.Open();
using (var sqlBulk = new SqlBulkCopy(connection))
{
sqlBulk.DestinationTableName = "Customers";
sqlBulk.WriteToServer(dt);
}
}
If the schema and table name was already valid: