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

  • Home
  • SEARCH
  • 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 7598619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:27:12+00:00 2026-05-30T22:27:12+00:00

Visual studio created a unit test project for me based on a method (right-click

  • 0

Visual studio created a unit test project for me based on a method (right-click add test). When I try to access the database, I get an exception. Ran this code to see what my connection was:

ConnectionStringSettings connStringSettings = ConfigurationManager.
    ConnectionStrings["myConnectionString"];

but, connStringSettings is null. Upon inspection, ConnectionStrings collection has a count of only one. It seems to not be reading from my web.config.

My DAL is isolated and cannot have its connection string set through code. Its connection string is set in code like this:

set
{
    value = System.Configuration.ConfigurationManager.
        ConnectionStrings["myConnectionString"].ConnectionString;
}

How can I resolve this?

  • 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-05-30T22:27:14+00:00Added an answer on May 30, 2026 at 10:27 pm

    Add an App.config file to your unit testing project and copy over the connection string from the Web.config.

    Update: Better Solution

    While adding a config will solve the immediate problem, it still results in unit tests depending on an actual database connection, which is not great. The better way to solve this problem is to mock the DAL entirely and pass that into the services which are using it.

    Microsoft provides some guidance on that here. It takes a little more time to setup, but it allows tests to be much more contained and complete.

    I have had success using MockQueryable for mocking individual tables within a test data context.

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

Sidebar

Related Questions

In Visual Studio, I just created a simple Unit Test to test a method
using visual studio (database pro) 2008, i have created a unit test (using the
I created a new Visual Studio 2010 Test Project. <solution> <test-project> Resources test-data.csv tests.cs
Visual Studio 2008 has the ability to automatically create unit test stubs. I have
I have created a Visual Studio 2008 sp1 test suite web test that uploads
I created a new Visual Studio Setup project with VS 2008. I use it
I have created a custom dialog for Visual Studio Setup Project using the steps
I created an Ordered Test in Visual Studio 2008, which includes a subset of
I am trying to use the Database unit tests in Visual Studio 2010. I
I have installed the new Visual Studio 2012 Ultimate. I have created a Test

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.