?
Solved

Problem while running C# windows application cannot find mdb file

Posted on 2008-06-22
6
Medium Priority
?
613 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
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 
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 2000 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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

850 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