0

I am working on an experimental project and have run into a problem trying to connect a microsoft access database to my program in visual basic 2008 express and keep getting the following message when I try to make the connection.

"The 'Microsoft.Jet.OLEDB.4.0C:\Users\lewis\Documents\programming\programs\cadet stores program\squadron stores system V1.1\squadron stores system V1.1\stores database\213 squadron stores.mdb' provider is not registered on the local machine."

After some research I have seen that there may be an issue because I am using a 64 bit operating system with 32 bit software. Any help or suggestions I would be grateful

This is the method I am currently trying to use:

Dim con As New OleDb.OleDbConnection
    Dim dbProvider As String
    Dim dbSource As String

    dbProvider = "Provider=Microsoft.Jet.OLEDB.4.0"
    dbSource = "C:\Users\lewis\Documents\programming\programs\cadet stores program\squadron stores system V1.1\squadron stores system V1.1\stores database\213 squadron stores.mdb"

    con.ConnectionString = dbProvider And dbSource
    con.Open()

I have now re written the syntax as shown bellow:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim con As New OleDb.OleDbConnection
    Dim connString As String

    connString = "Provider = Microsoft.Jet.OLEDB.4.0;"
    connString &= "C:\Users\lewis\Documents\programming\programs\cadet stores program\squadron stores system V1.1\squadron stores system V1.1\stores database\213 squadron stores.mdb;"
    con.ConnectionString = connString

    con.Open()

    MessageBox.Show("Conection open")

End Sub

However I now get the following error message:

"Format of the initialization string does not conform to specification starting at index 35."

The connection now works many thanks for your help

many thanks

Lewis

Lewis Carter
  • 3
  • 1
  • 5
  • Your connection string is seriously messed up, the Provider and DataSource parts are just run together. Use the [proper syntax](http://www.connectionstrings.com/access/). – Hans Passant Oct 29 '13 at 12:25
  • Hi hans I cannot seem to get the syntax in this format to work is there any chance you could please show me an example to get a better idea. – Lewis Carter Oct 29 '13 at 12:56
  • If you can't get it right from the link I provided then I seriously doubt I could do a better job. Nobody can see what you're doing wrong if you don't document your connection string. – Hans Passant Oct 29 '13 at 13:06
  • I have added the syntax I am trying to use I have also swithced the target cpu of the program to 86x – Lewis Carter Oct 29 '13 at 14:13
  • You really need to go slower. When you write code like this you're not quite ready yet to tackle a database project, it will just be a constant struggle to get somewhere. Find an introductory book on vb.net programming in your local library or book store, do the exercises. – Hans Passant Oct 29 '13 at 14:23
  • I realised What I had done wrong almost as soon as I reposted I have previously worked though a book on basic programing with Vb however it didnt cover setting up connections, However the connection now works many thanks for all you help – Lewis Carter Oct 29 '13 at 14:49

1 Answers1

0

This is just wrong:

' And does not concatenate strings
con.ConnectionString = dbProvider And dbSource

what you probably meant was:

con.ConnectionString = dbProvider & ";" & dbSource

or

connString = "Provider=Microsoft.Jet.OLEDB.4.0; "   ' end with a ;
connString &= "Data Source = C:\Users\lewis..."

con.ConnectionString = connString   

I am using a 64 bit operating system with 32 bit software If this means your project is 32 bit, you shouldn't have a problem, but for info on using OLEDb 4.0 in 64bit mode look here

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178