Solved

Problem while running C# windows application cannot find mdb file

Posted on 2008-06-22
6
600 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 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

18 Experts available now in Live!

Get 1:1 Help Now