filenotfoundexception error- c#- with database

Posted on 2011-10-11
Last Modified: 2012-05-12
i have a C# windows form application w/microsoft access 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 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");  
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....

Why is it looking there for the txt file?
thank you
Question by:davetough
    LVL 40

    Expert Comment

    by:Jacques Bourgeois (James Burger)
    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.

    Author Comment

    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
    LVL 40

    Accepted Solution

    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.

    Author Closing Comment

    thank you

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
    In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

    737 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

    23 Experts available now in Live!

    Get 1:1 Help Now