Microsoft KB Archive/817848

= FIX: &quot;Run-Time Error&quot; Occurs with ExportData Method of BulkCopy Object When DataBase Name Contains Space =

Article ID: 817848

Article Last Modified on 5/17/2007

-

APPLIES TO


 * Microsoft Data Access Components 2.7 Service Pack 1
 * Microsoft SQL Server 2000 Service Pack 3

-



SYMPTOMS
When you use the ExportData method of the BulkCopy object from SQL Distributed Management Objects (SQL-DMO), and the name of the database that you use in the method contains a space (for example, My Database), you receive the following error message at run time:

Run-time error '-2147221348(8004009c)':

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'Database'.

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'Database'.



RESOLUTION
To resolve this problem download MDAC 2.7 Service Pack 1 (SP1) Refresh. To download MDAC 2.7 SP1 Refresh, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/data/aa937695.aspx



WORKAROUND
To work around this problem, remove the space in the name of the database. To do this, you can name the database as follows:   Execute the following SQL command in SQL Query Analyzer. sp_renamedb 'My Database', 'MyDatabase'  Modify the name of the database in the Visual Basic project. On the Run menu, click Start.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in MDAC 2.7 Service Pack 1 Refresh.



Steps to Reproduce the Behavior
 Start SQL Server Enterprise Manager. Expand your SQL Server node. Right-click Databases, and then click New Database.</li> In the Name text box, type My Database, and then click OK.</li> Create a table in My Database, and then name it MyTable .</li> Insert records in MyTable.</li> Start Microsoft Visual Basic 6.0, and create a new Standard EXE project. By default, Form1 is created.</li> Drag a Button control from the Toolbox to Form1. By default, Command1 is created.</li> On the Project menu, click References, and then click to select Microsoft SQL DMO Object Library.</li>  Double-click Command1, and then paste the following code in Command1_Click. 'create the object Dim mySQLserver As SQLDMO.SQLServer Dim myDatabase As SQLDMO.Database

Set mySQLserver = New SQLDMO.SQLServer Set BulkCopy = New SQLDMO.BulkCopy mySQLserver.EnableBcp = True

'connect to the SQL Server mySQLserver.Connect &quot;yourSQLServer&quot;, &quot;YourLogin&quot;, &quot;YourPassword&quot;

With BulkCopy .DataFileType = SQLDMODataFile_NativeFormat .MaximumErrorsBeforeAbort = 1 .UseBulkCopyOption = True .UseExistingConnection = True 'specify the path where the table is to be copied .DataFilePath = &quot;C:\mytable.bcp&quot; 'export the data from the table in My Database mySQLserver.Databases(&quot;My Database&quot;).Tables(&quot;MyTable&quot;).ExportData BulkCopy

End With Note Replace,  , and  , with your local SQL Server, and the logon name and logon password of your local SQL Server. </li> On the Run menu, click Start.</li> Click Command1. You receive the error message that is described in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">