Solved

Problem while running C# windows application cannot find mdb file

Posted on 2008-06-22
6
599 Views
Last Modified: 2013-12-16
i made c# windows application has form to save a data inside database, i created the connection object and command object progrmatically, it works fine and save data if run it from visual studio on my development PC, but when i deploy it to other PC when i hit Save button on form to save data into database i got the error message in attached file.
i put the mdb file on the same application root with code files.
error.jpg
0
Comment
Question by:nayel
  • 2
  • 2
  • 2
6 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21839983
so, the file exists in the folder described in the error dialog?
0
 

Author Comment

by:nayel
ID: 21839988
not exist, and also i don not know why it run from that location, how force C# when deploy to put the application files in a folder inside Program Files as normal programs?!
0
 
LVL 16

Expert Comment

by:CuteBug
ID: 21839996
you have put the mdb file on the same application root with code files.

But you might have hardcoded the path of the mdb file in your application, due to which it searches for the file in the same location... which might not be available in the other machines.

Try specifying a relative path for the mdb file in your application. Or you can use an environment variable to specify the root directory of your application.

You can also use AppDomain.CurrentDomain.BaseDirectory to get the root directory of your application.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21840007
You can post the lines near to the error, specially where you build the filepath
0
 

Author Comment

by:nayel
ID: 21840789
this the connection string i used :
string ConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + AppDomain.CurrentDomain.BaseDirectory.ToString() + "\\LeaveDB.mdb'";
            OleDbConnection connDB = new OleDbConnection(ConnString);
            connDB.Open();
            OleDbDataAdapter daUsersData = new OleDbDataAdapter("SELECT * FROM UsersData",connDB);

still not working after deploying
0
 
LVL 16

Accepted Solution

by:
CuteBug earned 500 total points
ID: 21841395
try this
string dbPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"LeaveDB.mdb");
string ConnString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath;
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now