I am migrating the SQL DMO logic to a SQL SMO logic and I am not sure how to achieve the same functionality for a few of the attributes. This is the DMO:
oBCP = New SQLDMO.BulkCopy2
With oBCP
.ImportRowsPerBatch = ImportRowsPerBatch
.DataFilePath = Path.Combine(gtSysTempDir, "file.dat")
.LogFilePath = Path.Combine(gtSysTempDir, "file.log")
.ErrorFilePath = Path.Combine(gtSysTempDir, "file.err")
.MaximumErrorsBeforeAbort = 1
.DataFileType = SQLDMO.SQLDMO_DATAFILE_TYPE.SQLDMODataFile_TabDelimitedChar
End With
This is the SMO so far:
trans = New Transfer
With trans
.ImportRowsPerBatch = ImportRowsPerBatch
.TargetDatabaseFilePath = Path.Combine(gtSysTempDir, "file.dat")
.TargetLogFilePath = Path.Combine(gtSysTempDir, "file.log")
'.ErrorFilePath = Path.Combine(gtSysTempDir, "file.err")
.MaximumErrorsBeforeAbort = 1
.DataFileType = SQLDMO.SQLDMO_DATAFILE_TYPE.SQLDMODataFile_TabDelimitedChar
End With
What are the equivalents, if they exist, of ImportRowsPerBatch (BatchSize?), ErrorFilePath, MaxErrorsBeforeAbort, and DataFileType? Thanks.
Despite what the MSDN says,
Transferis not actually the equivalent ofBulkCopy2; it's intended for scripting/copying entire databases whereasBulkCopy2is only for bulk copying data. The settings don't correspond at all -- in particular,Transfer.TargetDatabaseFilePathis supposed to be the location of a database file, whereasBulkCopy2.DataFilePathis the location of the file where imported/exported data goes. Some bulk copy scenarios are handled byTransfer, but most aren't.If you're not actually copying an entire database, you have several alternatives, none of which use SMO (which has no class for bulk copying as such):
BulkCopy2does in the background (but I haven't verified this);Of these,
BULK INSERTis the most straightforward.