Solved

ODBC, DSNLess and a dBase database

Posted on 2000-05-02
9
903 Views
Last Modified: 2013-12-25
I'm trying to open a DBF file via ODBC without using a DSN entry. Is this possible? Does anyone have any example code of how to achieve this? What should the connection string look like? I'm using DAO 3.51 and a dBase IV database. Thanks in advance...
0
Comment
Question by:lbowers
  • 5
  • 4
9 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 100 total points
ID: 2770286
You can create your DSN dynamically with DBEngine.RegisterDatabase.

Add this code to a class:
Option Explicit

Public glngError As Long        'Contient le code de l'erreur (s'il y en a une!)
Public gstrAttributes As String 'Contient la string d'attributs
Public gstrDriver As String     'Contient le nom du driver
Public gstrDSN As String        'Contient le nom du DSN

' *********************************************************
' *** Enregistre les données de l'ODBC dans le Registry ***
' *********************************************************
Public Function RegisterDB() As Boolean
Dim errLoop As Error

    On Error GoTo ErrorHandler
   
    RegisterDB = False
    DBEngine.RegisterDatabase gstrDSN, gstrDriver, True, gstrAttributes
    RegisterDB = True
   
    Exit Function
   
ErrorHandler:
    glngError = Err.Number
End Function

You can use it this way:
    Set objDSN = New clsRegisterDB
    With objDSN
        .gstrDriver = "Microsoft dBase Driver (*.dbf)"
       
        .gstrDSN = "FO-" & CStr(bytI)
        .gstrAttributes = "DefaultDir=" & "C:\test" & vbCrLf & _
"Description=Fichier du Front Office" & vbCrLf & _
                              "FIL=dBase 5.0;"
            .RegisterDB
    End With
0
 

Author Comment

by:lbowers
ID: 2772782
The above code works (thanks), but what is the ODBC connection string for dbf files? I notice that you don't actually specify a database within the DSN, just a directory. How do you tell VB the name of the database to use? I've tried loads of variations, but I keep gettings errors!
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2774718
Since dBase is not a model of a table containing tables, the folder becomes like a database and the files (tables) are specified in your queries.
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:lbowers
ID: 2775184
Excellent - Thanks for your help. The points are yours, but I was wondering if you had ever come across the following problem before:

I am able to READ records via the ODBC connection, but I get an error whenever I attempt to DELETE, ADD or UPDATE records. I have set all "Read Only" properties to false. Any ideas?

Thanks again.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2775771
Show me your code.
0
 

Author Comment

by:lbowers
ID: 2776553
   Set ws = dao.CreateWorkspace("Workspace", "", "", dbUseODBC)
    Set db = ws.OpenConnection("Disk5Copy", dbDriverNoPrompt, False, "ODBC;")

sSQL = "DELETE FROM house" ' For example
db.Execute sSQL

I get "ODBC--call failed" error!
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2776735
You need to add you DSN name somewhere:
Set db = ws.OpenConnection("Disk5Copy", dbDriverNoPrompt, False, "ODBC;DSN=MYDSN")
0
 

Author Comment

by:lbowers
ID: 2776909
Disk5Copy is my DSN. I find if I use "DSN=xxx" in the connections string, it doesn't work. Using the code I've show above, I can read records from the DBF file, I just can't ADD, DELETE or UPDATE! Hmmm...
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2777006
Why don't you open the dBase file directly (without going through ODBC).

http://support.microsoft.com/support/kb/articles/Q240/7/48.ASP?LN=EN-US&SD=gn&FR=0
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Viewers will learn how to maximize accessibility options in an Excel workbook for users with accessibility issues.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question