[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Problem while running C# windows application cannot find mdb file

Posted on 2008-06-22
6
Medium Priority
?
610 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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 …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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