Solved

Problem while running C# windows application cannot find mdb file

Posted on 2008-06-22
6
605 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

820 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