We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

VB6 - ODBC connection problem

Cristi_E
Cristi_E asked
on
Medium Priority
2,127 Views
Last Modified: 2013-12-20
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?
Comment
Watch Question

Author

Commented:
Any ideeas?
CERTIFIED EXPERT
Commented:
Try this line

Set db = ws.OpenDatabase(DatabaseName)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.