• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2109
  • Last Modified:

VB6 - ODBC connection problem

Hello,
I have a vb6 project, with a command button and a listbox on a form. I have linked the refference DAO 3.6 to the project. I want co connect to an access database and receive some records from there via ODBC.
Now i have the following code attached to Command1:

Option Explicit
Private Sub Command1_Click()
    Dim ws As Workspace
    Dim db As Database
    Dim strConnection As String
    Dim rs As Recordset
    '
    Dim DatabaseName As String
    Dim UserName As String
    Dim UserPassword As String
    '
    DatabaseName = "c:\Firewall.mdb"
    UserName = ""
    UserPassword = ""
    '
    Set ws = DBEngine.Workspaces(0)
    Let strConnection = "ODBC;DSN=" & DatabaseName & ";UID=" & UserName _
    & ";PWD=" & UserPassword
    Set db = ws.OpenDatabase("", False, False, strConnection)
    '
    '
    Set rs = db.OpenRecordset("tbl_Clienti")
    Do While Not rs.EOF
        'Put the code here for what to do with the information.
        'The field information can be access by the field name
        List1.AddItem rs!Nume_Client
        'Or by the order number it is in the list (starting at 0)
'        intString = rs.Field(1)
        rs.MoveNext
    Loop
End Sub

On the line:      Set db = ws.OpenDatabase("", False, False, strConnection)
i get the following error message:  
Run-time error '3151'
ODBC -- connection to 'c:\firewall.mdb' failed

Can you help me?
0
Cristi_E
Asked:
Cristi_E
2 Solutions
 
Cristi_EAuthor Commented:
Any ideeas?
0
 
BalajitrCommented:
Try this line

Set db = ws.OpenDatabase(DatabaseName)
0
 
gandalf97Commented:
You might also want to double check to make sure the database exists and that the variables for the username and password contain what you think they should.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now