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

Unexpected error with Database connection in VB.Net

Cookie_Crum
Cookie_Crum asked
on
Medium Priority
255 Views
Last Modified: 2010-04-23
I have a VB.Net program that is the front end for a Access databse. I am now trying to deploy the program
and so have moved the database into the same folder as the project so that it can find the database. However when I
changed the connection settings to simply "Database.mdb" and ran the program I got the following error message:

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

What am I doing wrong?

Thanks!
Comment
Watch Question

Hi

Firstly, your connection string shoud still say "Provider=...." and you have simply removed the path within the Data Source setting.

Next, maybe just terminology, but you have made sure the .EXE (or .DLL) is in the same folder as the database rather than the project (.proj)

You are running this on a client operating system with the .Net framework / MDAC installed ?

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

Ask the Experts

Author

Commented:
Not 100% sure I've read you correctly but I checked the connection in the server explorer and it still reads "Provider =..." the only thing I changed
was the settings within OleDbDataAdapter. By ran the project I don't mean when the project was installed but when I ran the project within Visual Studio
(by pressing F5).

The machine I was running the program on had the .Net framwork installed, not sure what MDAC is!
Carl TawnSenior Systems and Integration Developer
CERTIFIED EXPERT

Commented:
If you don't specify the full path to the DB then it is assumed to be in the build folder. If running under the debugger, as you are, the DB will need to be in the "YourProject\Bin\Debug" folder rather than the project folder.
carl is right and that's what I was trying to get to... i.e. the current running directory is probably not what you think it is
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
If you need a more explicit exception message, wrap the code in a Try...Catch and read the exception stack:

Try

Catch ex As Exception

  MessageBox.Show(ex.ToString)

End Try

Bob

Author

Commented:
Thanks!! fixed that problem nicely, just one more thing quickly, when the program is compiled during the creation of the setup file will
it recognise the database will in the Bin folder and compile that aswell? Or does it have to be in the main folder?
It won't automatically include the database within the setup project. You need to add this as a file and will therefore give it a path to pull in from when the setup project is compiled.

Author

Commented:
So it will be enough to just include the file within the application folder?
Yes, you can add the file from the application folder to the setup project, then make sure that the EXE and MDB files will both be installed in the same destination library then you should be okay
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.