Microsoft KB Archive/285345

= PRB: &quot;Run-Time Error 3000&quot; Error Message When You Use DSN-Less Connection to Connect to Visual FoxPro Table Through DAO =

Article ID: 285345

Article Last Modified on 12/30/2001

-

APPLIES TO


 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q285345



SYMPTOMS
When you use a DSN-less connection to connect to a Visual FoxPro free table through Data Access Objects (DAO), you may receive the following error message:

Run-time error '3000':

Reserved error (-7778); there is no message for this error.



RESOLUTION
To use a DSN-less connection with a Visual FoxPro free table, you must create an Open Database Connectivity (ODBC) workspace. For sample code, refer to the &quot;More Information&quot; section.



Steps to Reproduce Behavior
 Open a new Standard EXE project in Visual Basic. Place a CommandButton control on the form.  Add the following code to the Command1_Click event: Dim dbCurrentDB As DAO.Database Dim rsTmp As Recordset Dim sConnect$, sDatabaseName$, sTable$, i% Dim wk As Workspace sTable = &quot;select * from employees&quot;  ' Modify select to use your Visual FoxPro table. ' Modify SourceDB to correctly reflect the path (and path only) of your ' Visual FoxPro .dbf file. Do not include the file name. sConnect = &quot;ODBC;SourceType=DBF;&quot; _ & &quot;SourceDB=c:\TestDir\dataDir\;&quot; _ & &quot;Driver={Microsoft Visual FoxPro Driver}&quot; ' Uncomment the following two lines of code to resolve this error. ' Set wk = DBEngine.CreateWorkspace(&quot;&quot;, &quot;admin&quot;, &quot;&quot;, dbUseODBC) ' Set dbCurrentDB = wk.OpenDatabase(&quot;&quot;, False, False, sConnect) ' Comment the following line to resolve this error. Set dbCurrentDB = DBEngine.OpenDatabase(&quot;&quot;, False, False, sConnect) ' Fails here.

Set rsTmp = dbCurrentDB.OpenRecordset(sTable, dbOpenSnapshot) For i = 0 To rsTmp.Fields.Count - 1 Debug.Print rsTmp.Fields(i).Name & &quot; | &quot;; Next Debug.Print &quot;&quot; rsTmp.Close dbCurrentDB.Close Set rsTmp = Nothing Set dbCurrentDB = Nothing  Modify SourceDB to correctly reflect the path of your Visual FoxPro .dbf file. The comments indicate where you must make the changes.

NOTE: Only type the path to the .dbf file; do not type the file name.  Click the command button to run the code. Notice that you receive the above-mentioned error message.

RESOLUTION
  To resolve this problem, create a workspace and successfully open a connection to the database. To do this, uncomment the following two lines ' Uncomment the following two lines of code to resolve this error. ' Set wk = DBEngine.CreateWorkspace(&quot;&quot;, &quot;admin&quot;, &quot;&quot;, dbUseODBC) ' Set dbCurrentDB = wk.OpenDatabase(&quot;&quot;, False, False, sConnect) and comment the following line: ' Comment the following line to resolve this error. Set dbCurrentDB = DBEngine.OpenDatabase(&quot;&quot;, False, False, sConnect) ' Fails here. </li> Click the command button to run the code. Notice that the Immediate window displays the data, and you do not receive the error message.</li></ol>

<div class="references_section">