简体   繁体   English

从SQL DMO迁移到SQL SMO(SQL Server 2012)

[英]Migrating from SQL DMO to SQL SMO (SQL Server 2012)

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. 我正在将SQL DMO逻辑迁移到SQL SMO逻辑,但不确定如何为某些属性实现相同的功能。 This is the DMO: 这是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: 到目前为止,这是SMO:

    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? ImportRowsPerBatch(BatchSize?),ErrorFilePath,MaxErrorsBeforeAbort和DataFileType的等效项(如果存在)是什么? Thanks. 谢谢。

Despite what the MSDN says , Transfer is not actually the equivalent of BulkCopy2 ; 尽管MSDN说了什么 ,但是Transfer实际上并不等同于BulkCopy2 it's intended for scripting/copying entire databases whereas BulkCopy2 is only for bulk copying data. 它用于脚本化/复制整个数据库,而BulkCopy2仅用于批量复制数据。 The settings don't correspond at all -- in particular, Transfer.TargetDatabaseFilePath is supposed to be the location of a database file, whereas BulkCopy2.DataFilePath is the location of the file where imported/exported data goes. 这些设置根本不对应-特别是, Transfer.TargetDatabaseFilePath应该是数据库文件的位置,而BulkCopy2.DataFilePath是导入/导出数据所在的文件的位置。 Some bulk copy scenarios are handled by Transfer , but most aren't. 某些大容量复制方案由Transfer处理,但大多数情况并非如此。

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): 如果您实际上并没有复制整个数据库,则有几种选择,其中一种都不使用SMO(没有这样的类来进行批量复制):

  • Directly invoking a BULK INSERT statement, which is probably what BulkCopy2 does in the background (but I haven't verified this); 直接调用BULK INSERT语句,这可能是BulkCopy2在后台执行的操作(但我尚未对此进行验证);
  • Using the SqlBulkCopy class, which will require some extra code (but which also offers far more flexibility as the data to be imported can come from any source); 使用SqlBulkCopy类,这将需要一些额外的代码(但由于要导入的数据可以来自任何来源,因此它还提供了更大的灵活性);
  • Building a command line and invoking bcp . 构建命令行并调用bcp

Of these, BULK INSERT is the most straightforward. 其中, BULK INSERT是最简单的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM