Connection syntax not right

  • Thread starter Thread starter Kimberley Wiggins
  • Start date Start date
K

Kimberley Wiggins

Can someone please tell me what is wrong with this syntax? I am just
really frustrated. I am trying to use the application startup path for
this but it does not like this syntax for some reason. Does something
look out of place here?

Dim strOTRConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source= Application.Startup & otr.mdb"

I know this is the problem because if I move my database to my C drive
it works fine.
Thanks
 
Hi Kim,

First of all, you don't have an opening quote before otr.mdb" (s/b
"otr.mdb"). Also, debug or messagebox.show to get the actual string
represented by application.startup - do you have to append "\" to it?

HTH,

Bernie Yaeger
 
Assumming this Application.Startuppath is where the mdb is located:
Data Source = Application.StartupPath "\otr.mdb"
 
No I don't have to append to it and I debugged it to find out the
application startup path and I do have the database in the correct path.
You said I did not have an opening quote before otr.mdb, it doesn't like
that. It tells me that a end of statement is expected when I put one
there. No, I don't have to append to the file, just display.
Thanks
 
Thanks Richard but it doesn't like that. It tells me otr is not
declared and end of statement expected at the end. I don't know how to
fix the end of statement expected. I have debugged the path and yes the
file is in the right path.
 
Hi Kimberley,

Richard forgot the & but that is such a easy to sea typo.

Data Source = Application.StartupPath & "\otr.mdb"

Cor
 
Hi Kimberly,

You have to have otr.mdb attached via "otr.mdb"; if the syntax isn't
correct, it isn't the fault of this; you can't attach a string to an
ampersand with only the outer quote.

This is undoubtedly where the error is - once you attach it with the double
quotes, print it out in a messagebox.show and let me see it.

Bernie
 
Kimberley Wiggins said:
Can someone please tell me what is wrong with this syntax? I am just
really frustrated. I am trying to use the application startup path for

Kimberley,

I have struggled with the same issue and solved it this way:

Dim dbPath as string = Application.Startup & "\otr.mdb"

Dim strOTRConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source= dbPath"

The problem is that the connection string must be enclosed in quotes,
but concatenation also requires it for the second half of the dbPath
you are defining.

Charlie
 
Thank you so much Charlie. Thanks everyone for your input. Charlie you
explained it to me why I should have it the way it is. I needed to know
exactly what was the essential pieces that needed to be there because I
had tried so many things to make the it work I didn't know what was
right from wrong. It worked and everything's good. Once again, thanks.
 
I have struggled with the same issue and solved it this way:

Dim dbPath as string = Application.Startup & "\otr.mdb"

Dim strOTRConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source= dbPath"

I think you have a typo. Shouldn't that last line be:

Dim strOTRConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" & dbPath

?
 
Cor said:
Hi Chris,

I had the same idea as you strange that it did work as Kimberley said.

This is one of the strangest postings I've ever seen.

First, how can someone be working with a database when they are having
so much trouble doing a simple string concatenation? That's one of
the first things you learn in programming, and you should certainly
know this before attempting database connections!

Second, the code that was just posted couldn't have possibly solved
the problem, as the variable name was enclosed in the string. Am I
missing something?
 
Cor said:
Hi Chris,

I had the same idea as you strange that it did work as Kimberley said.

Cor,

AFAIK this is a pecularity of Access database connection strings. I
have never dug into the thoery, but I have learned how to make it
work. You know the old saying about necessity is a mother...

Charlie
 
Back
Top