Solved

ODBC, DSNLess and a dBase database

Posted on 2000-05-02
9
862 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 69

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 69

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
 

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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 69

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 69

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 69

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now