It looks much cleaner with the TransactionScope.
using (TransactionScope scope = new TransactionScope())
using (var connection = new SqlConnection(GetConnectionString()))
{
connection.Open();
try
{
foreach (var fileData in Helpers.StreamFile(filePath, tableName, fieldSeparator, numberOfSourceColumns))
{
// BulkInsert uses SqlBulkCopy to insert data.
Helpers.BulkInsert(fileData.Data, tableName, connection, transaction);
}
scope.Complete();
return true;
}
catch (Exception)
{
return false;
}
}
You should also read this: Is it possible to use System.Transactions.TransactionScope with SqlBulkCopy? Is it possible to use System.Transactions.TransactionScope with SqlBulkCopy?
The last parameter is unnecessary.
Exception handling
Are you sure you want to ignore the exception? I guess you log it somehow, do you?
It looks much cleaner with the TransactionScope.
using (TransactionScope scope = new TransactionScope())
using (var connection = new SqlConnection(GetConnectionString()))
{
connection.Open();
try
{
foreach (var fileData in Helpers.StreamFile(filePath, tableName, fieldSeparator, numberOfSourceColumns))
{
// BulkInsert uses SqlBulkCopy to insert data.
Helpers.BulkInsert(fileData.Data, tableName, connection, transaction);
}
scope.Complete();
return true;
}
catch (Exception)
{
return false;
}
}
You should also read this: Is it possible to use System.Transactions.TransactionScope with SqlBulkCopy?
The last parameter is unnecessary.
Exception handling
Are you sure you want to ignore the exception? I guess you log it somehow, do you?
It looks much cleaner with the TransactionScope.
using (TransactionScope scope = new TransactionScope())
using (var connection = new SqlConnection(GetConnectionString()))
{
connection.Open();
try
{
foreach (var fileData in Helpers.StreamFile(filePath, tableName, fieldSeparator, numberOfSourceColumns))
{
// BulkInsert uses SqlBulkCopy to insert data.
Helpers.BulkInsert(fileData.Data, tableName, connection, transaction);
}
scope.Complete();
return true;
}
catch (Exception)
{
return false;
}
}
You should also read this: Is it possible to use System.Transactions.TransactionScope with SqlBulkCopy?
The last parameter is unnecessary.
Exception handling
Are you sure you want to ignore the exception? I guess you log it somehow, do you?
It looks much cleaner with the TransactionScope.
using (TransactionScope scope = new TransactionScope())
using (var connection = new SqlConnection(GetConnectionString()))
{
connection.Open();
try
{
foreach (var fileData in Helpers.StreamFile(filePath, tableName, fieldSeparator, numberOfSourceColumns))
{
// BulkInsert uses SqlBulkCopy to insert data.
Helpers.BulkInsert(fileData.Data, tableName, connection, transaction);
}
scope.Complete();
return true;
}
catch (Exception)
{
return false;
}
}
You should also read this: Is it possible to use System.Transactions.TransactionScope with SqlBulkCopy?
The last parameter is unnecessary.
Exception handling
Are you sure you want to ignore the exception? I guess you log it somehow, do you?