FIX: DMO BulkCopy Fails to Copy Data When Column Names Contain the Space Character

Article translations Article translations
Article ID: 299865 - View products that this article applies to.
This article was previously published under Q299865
BUG #: 351486 (SHILOH_BUGS)
Expand all | Collapse all

On This Page

SYMPTOMS

Using the SQL Distributed Management Objects (DMO) BulkCopy object to import data into a SQL Server table that contains a column with a space embedded in the column name may fail with no rows copied.

CAUSE

By default, the BulkCopy object uses a second connection which does not inherit properties, such as QuotedIdentifiers, from the original connection.

RESOLUTION

To resolve this problem, obtain the latest service pack for SQL Server 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
290211 INF: How to Obtain the Latest SQL Server 2000 Service Pack

WORKAROUND

You can work around this problem in the following ways:
  • Make sure that the SQL-DMO BulkCopy object reuses the existing connection by setting the UseExistingConnection property to True.
  • Remove the embedded space in the column name.

STATUS

Microsoft has confirmed that this is a problem in SQL Server 2000. This problem was first corrected in SQL Server 2000 Service Pack 1.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create the source and destination SQL Server tables in the sample Northwind database:
    create table BulkCopyFrom ( c1 int)
    go
    create table BulkCopyTo ( [c1 copy] int )
    go
    insert BulkCopyFrom values (1)
    					
  2. Use the following Microsoft Visual Basic/SQL-DMO code to demonstrate the problem:
    Public Sub Main()
    
    On Error GoTo ErrHandler
    
    Dim server As New SQLDMO.SQLServer
    Dim blk As New SQLDMO.BulkCopy
    
    Dim db As SQLDMO.Database
    Dim tblSrc As SQLDMO.Table
    Dim tblDst As SQLDMO.Table
    Dim lRowsExported As Long
    Dim lRowsImported As Long
    
    server.LoginSecure = True
    server.EnableBcp   = True
    server.Connect "."                   'Uses the default SQL Server instance
    server.QuotedIdentifier = True
    
    Set db = server.Databases("northwind")
    
    Set tblSrc = db.Tables("BulkCopyFrom")
    Set tblDst = db.Tables("BulkCopyTo")
    
    'blk.UseExistingConnection = True    'Uncomment this line to reuse connection
    
    blk.DataFilePath  = "C:\TEMP\exported.dat"
    blk.ErrorFilePath = "C:\TEMP\exported.err"
    blk.LogFilePath   = "C:\TEMP\exported.log"
    
    blk.DataFileType          = SQLDMODataFile_NativeFormat
    blk.UseBulkCopyOption     = True
    blk.IncludeIdentityValues = True
    blk.SetCodePage SQLDMOBCP_RAW
    
    lRowsExported = tblSrc.ExportData(blk)
    MsgBox "Exported " & lRowsExported & " rows"
    
    blk.ErrorFilePath = "C:\TEMP\imported.err"
    blk.LogFilePath   = "C:\TEMP\imported.log"
    lRowsImported     = tblDst.ImportData(blk)
    MsgBox "Imported " & lRowsImported & " rows"
    
    server.DisConnect
    
    Set blk = Nothing
    Set server = Nothing
    
    Exit Sub
    
    ErrHandler:
    MsgBox "Error " & Err.Number & vbclr & Err.Description
    Resume Next
    
    End Sub
    					
    This code results in 0 rows imported into the destination table BulkCopyTo.

    To work around the problem, uncomment the code line to reuse the existing connection.

Properties

Article ID: 299865 - Last Review: November 5, 2003 - Revision: 3.2
APPLIES TO
  • Microsoft SQL Server 2000 Standard Edition
Keywords: 
kbbug kbfix kbsqlserv2000sp1fix KB299865

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com