VB.NET accessing MS Access Database


I'm trying to figure out some basics with VB.net and interfacing with a MSAccess .accdb.

For the sake of this test, the .accdb file is located in the root directory of the project.  

I've already created a basic "Select" statement, and can pull data from my table within the .accdb.  That works fine.

It's the updates and inserts that I can't get to work.  The code below seems straightforward, and I've had this exact code work when connecting to an SQL server (with a change to connection string of course), so it's something about this access database.

The database itself is brand new, just created it, and then added a single table with a small sample of data.  There is no security setup on it that I know of.  I also set Windows File permissions to Everyone -> Full Access to rule out permissions there.

The code does not generate any errors, it simply doesn't cause a change to the DB.  

Does anyone have any thoughts?

Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=filename.accdb;Persist Security Info=False;"

     Dim ds As New Data.DataSet()
     Dim da As New Data.OleDb.OleDbDataAdapter()
     Dim conn As New Data.OleDb.OleDbConnection(connString)


     Dim cmd As New Data.OleDb.OleDbCommand("UPDATE TableName SET Manufacturer = 'abc123' WHERE MsdsID = 9")
        cmd.Connection = conn
        txtTemp.Text = cmd.ExecuteNonQuery()


Open in new window

Who is Participating?
käµfm³d 👽Commented:
Are you looking at the correct copy of the DB? If you added the DB file to your project, it should be getting copied to the bin directory when you build your application. The copy in bin is the one that will be updated, not the one in your project directory.
compsol1993Author Commented:
Thanks for the feedback, I just confirmed and it is not making any modifications to the .accdb file in bin/Debug

Good point though, I didn't think of that.
käµfm³d 👽Commented:
Did you manually include the DB into the bin directory (i.e. open up folder in Explorer and copy/paste file), or did you "add an existing item" to your project and have it copied to output on build?
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

compsol1993Author Commented:
I did the add existing.

Ok, I figured something out, but I'm not sure why.

I understand that when it is built, a new copy of the .accdb file gets copied to the Debug directory.  So I built it, ran the code, then checked the .accdb file in that directory, no change.

So then I changed from Debug to Release, re-ran, opened the db in the Release directory, and then it did work.

Any thoughts on why?
käµfm³d 👽Commented:
If you go to Solution Explorer, select the DB file, then hit F4 (open Properties pane), what does the "Copy to Output Directory" property say (for Debug and Release)?
compsol1993Author Commented:
It's set to always copy.

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.

All Courses

From novice to tech pro — start learning today.