Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7996989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:51:09+00:00 2026-06-04T14:51:09+00:00

I am currently in the middle of creating an app that uses a sql

  • 0

I am currently in the middle of creating an app that uses a sql CE database, I have made this database deploy-able with the application, however the problem I’m having at the moment is I need to run TestMethods but this is erroring out when it doesn’t find the database as its looking in the “testingProject” folder under debug or release as that is it’s Data Directory

using (SqlCeConnection sqlCon = new SqlCeConnection(@"Data Source=|DataDirectory|\database.sdf;Persist Security Info=False;"))

The code above is my connection string, so I’m guessing that means that the test is running and searching for a database in its own data directory

Any help on what I could do without changing the database connection string, database location and still leaving my application deployable? or am I asking something impossible?

EDIT

[TestMethod]
        public void TestForReadingFromDB()
        {
            List<string> list = class.readDB();
            Assert.IsNotNull(list);
            Assert.AreNotEqual(0, list.Count);
        }

just added in the test method that’s currently failing

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:51:10+00:00Added an answer on June 4, 2026 at 2:51 pm

    In the test project you can override the DataDirectory location using

    AppDomain.CurrentDomain.SetData("DataDirectory", <PATH_TO_DATA_DIRECTORY>);
    

    For instance in my app.config file the testing projects I have

      <appSettings>
        <add key="DataDirectory" value="..\..\Database"/>
      </appSettings>
    

    In my test fixture base I have:

    var dataDirectory = ConfigurationManager.AppSettings["DataDirectory"];
    var absoluteDataDirectory = Path.GetFullPath(dataDirectory);
    AppDomain.CurrentDomain.SetData("DataDirectory", absoluteDataDirectory);
    

    This sets the DataDirectory to the folder /Database under the test project folder structure.

    Once I drop or create a copy of the database in there I can easily run Integration Tests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have a class that looks like this: public class MyClass : IMyClass
Currently I have: $(#location).autocomplete({source: cities, minLength: 0, autoFocus: true}); The problem is that this
I am in the middle of rewriting an MS Access database that currently is
I'm currently in the middle of developing an iPhone app with a big reference
Currently developing an application using the newest version of symfony, obtained through PEAR. This
How would one go about creating an ipad app that has a similar view
I'm currently creating a WPF application, using C# and XAML in Visual Studios 2010.
I have the concept of a Rule that I want to be able to
I have a jQuery UI Dialog box, that I'm creating. It starts out as
I'm currently in the middle of a project that involves YouTube API. I'm using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.