?
Solved

filenotfoundexception error- c#- with database

Posted on 2011-10-11
4
Medium Priority
?
268 Views
Last Modified: 2012-05-12
hello,
i have a C# windows form application w/microsoft access database.in the visual studio 2008 enviroment- it runs with no problems. I can also go to debug folder and copy the exe file and database- and it works ( although- this is not correct way to deploy a c# app).
 database is on local network-  txt file in debug folder - the program.cs file loads form1 and checks for the txt file. (i read that txt file has to be in same folder where application .exe resides).
Then it checks for database and loads application.

Code in the program.sc file:
System.IO.StreamReader file = new System.IO.StreamReader(Application.StartupPath + "\\dbpath.txt");
Code in form1:
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Program.dbPath + "\\data13.mdb");  
Problem:
am getting a filenotfoundException when try to deploy it.
In the app.publish folder- there is setup.exe, publish htm, project ### application, and applicatoin files folder - if that is what is supposed to be created there?
It says " could not find "C:\Documents and settings\name\local settings\apps\2.0\ etc....
\dbpath.txt"

Why is it looking there for the txt file?
thank you
     
0
Comment
Question by:davetough
  • 2
  • 2
4 Comments
 
LVL 40
ID: 36951600
It is looking there because when you install a program with ClickOnce (this is what you seem to be using for deployment), by clicking the Setup.exe or activating the install from publish.htm, the application is installed in "C:\Documents and settings\name\local settings\apps\2.0\". So Application.StartupPath leads you there.

You probably did not include the dbpath.txt file in your deployment, so the FileNotFoundException.
0
 

Author Comment

by:davetough
ID: 36951701
do i need to use a different deployment method - to include the dbPath.txt file ?
I do not see how to add i with click once
thank you
0
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 36952265
The file must first be part of your project. If it is not, you can add it by right-clicking on the project in the Solution Explorer, and point to the file through the Add...Existing Item menu entry.

Once the file is in the Project, click on it in the Solution Explorer, and set its Build Action to Content in the Properties window. A file flagged as Content is usually added in the list of Application Files distributed through ClickOnce, and installs in the same directory as the application.
0
 

Author Closing Comment

by:davetough
ID: 36953369
thank you
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
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