Know a good article or link that we're missing? Submit it!

VB.NET

Moderators: seancampbell
Number of threads: 3618
Number of posts: 9200

This Forum Only
Post New Thread

Report
Access 2007 & VB 2008 Posted by Psyborg on 5 Nov 2009 at 12:52 PM
I have a real problem here. I am connecting to an access 2007 database (accdb) via an OLEDB connection, and I have no idea why this code isn't working!
Imports System.Data.OleDb
Public Class Form1

    Private Sub Form1_Load(...)
        Dim dbCon As OleDbConnection
        Dim dbCmd As OleDbCommand
        Dim dbRead As OleDbDataReader

        dbCon = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\My.accdb;Persist Security Info=False;")
        dbCon.Open()  

        dbCmd = New OleDbCommand("SELECT * FROM CITY", dbCon)
        dbRead = dbCmd.ExecuteReader
        Do While dbRead.Read
            MsgBox(dbRead(1))
        Loop
    End Sub
End Class

The result is the program crashes with no errors. I tried it in a different form/project and it launches the forum without any messages. So, in short, I'm getting no error messages and I don't know why. It will not go past dbCon.Open(). Please help!
Report
Re: Access 2007 & VB 2008 Posted by seancampbell on 11 Nov 2009 at 7:31 AM
If the program is crashing, it has to be throwing an exception...

to get the error message try this:

    Private Sub Form1_Load(...)
        Dim dbCon As OleDbConnection
        Dim dbCmd As OleDbCommand
        Dim dbRead As OleDbDataReader
try
        dbCon = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\My.accdb;Persist Security Info=False;")
        dbCon.Open()  
catch ex as exception
msgBox(ex.Message, vbOkOnly, "Error During dbCon.Open()")
return
End Try

        dbCmd = New OleDbCommand("SELECT * FROM CITY", dbCon)
        dbRead = dbCmd.ExecuteReader
        Do While dbRead.Read
            MsgBox(dbRead(1))
        Loop
    End Sub



My gut feeling is that this is a connection string issue
try this:
Dim DBName as String = "c:\path_of_db\dbname.dbext"
Dim ConString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DBName & ";User ID=Admin;Password="

dbCon = New OleDbConnection(ConString)
Report
Re: Access 2007 & VB 2008 Posted by Psyborg on 11 Nov 2009 at 8:49 AM
Thanks! I tested everything out, and it still didn't work. I was looking around, and I realized that it's because first, I'm using the compiler in x64 so it can't find the provider, and second that I was using the code in the form load event, so it wouldn't throw errors.
Report
Re: Access 2007 & VB 2008 Posted by seancampbell on 11 Nov 2009 at 1:30 PM
Did you find a solution?

If not, you might find a more proper connection string (that has a provider that you can see on your x64 box) here: http://www.connectionstrings.com/

I go there a lot when I am writing con-strings for DB's I don't normally work with.

Good Luck!
Sean Campbell - firesickle.com
Report
Re: Access 2007 & VB 2008 Posted by Psyborg on 11 Nov 2009 at 1:42 PM
Yeah, thanks. I changed the compiler to target x86 machines, and moved the code to a button event. Thanks for the help!



 
Popular resources and forums for programmers on Programmersheaven.com
Assembly, Basic, C, C#, C++, Delphi, Java, JavaScript, Pascal, Perl, PHP, Python, Ruby, Visual Basic
© Copyright 2009 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Publisher: Lars Hagelin. Read the latest words from the publisher here.
Be the first to sign up for Lars Hagelin’s In-depth Outsourcing Newsletter here.
bootstrapLabs Logo A bootstrapLabs project.