Microsoft KB Archive/299865

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

Article ID: 299865

Article Last Modified on 11/5/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition

-



This article was previously published under Q299865



BUG #: 351486 (SHILOH_BUGS)



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.



Steps to Reproduce Behavior
  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)   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 &quot;.&quot;                  'Uses the default SQL Server instance server.QuotedIdentifier = True

Set db = server.Databases(&quot;northwind&quot;)

Set tblSrc = db.Tables(&quot;BulkCopyFrom&quot;) Set tblDst = db.Tables(&quot;BulkCopyTo&quot;)

'blk.UseExistingConnection = True   'Uncomment this line to reuse connection

blk.DataFilePath = &quot;C:\TEMP\exported.dat&quot; blk.ErrorFilePath = &quot;C:\TEMP\exported.err&quot; blk.LogFilePath  = &quot;C:\TEMP\exported.log&quot;

blk.DataFileType         = SQLDMODataFile_NativeFormat blk.UseBulkCopyOption    = True blk.IncludeIdentityValues = True blk.SetCodePage SQLDMOBCP_RAW

lRowsExported = tblSrc.ExportData(blk) MsgBox &quot;Exported &quot; & lRowsExported & &quot; rows&quot;

blk.ErrorFilePath = &quot;C:\TEMP\imported.err&quot; blk.LogFilePath  = &quot;C:\TEMP\imported.log&quot; lRowsImported    = tblDst.ImportData(blk) MsgBox &quot;Imported &quot; & lRowsImported & &quot; rows&quot;

server.DisConnect

Set blk = Nothing Set server = Nothing

Exit Sub

ErrHandler: MsgBox &quot;Error &quot; & 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. 

Keywords: kbbug kbfix kbsqlserv2000sp1fix KB299865

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.