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 8003327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:37:20+00:00 2026-06-04T16:37:20+00:00

I’m using Entity Framework (4.3) and code first (along with SQL server 2012 localdb).

  • 0

I’m using Entity Framework (4.3) and code first (along with SQL server 2012 localdb).

I’m having an interesting situation where in one application a call returns a result (‘card’) and another using the same query on the same db (with thousands of rows available) returns nothing (null in this case since I’m using FirstOrDefault).

using (var context = new MyEntities())
        {
            //verify account exists
            var account = context.Account.SingleOrDefault(a => a.AccountNum == accountNum);

            if (account == null)
            {   
                //handle no account                 
                return false;
            }                

            var card = context.cards.FirstOrDefault(c => c.Used == false);

            //check that we actually got a card
            if (card == null)
            { 
                //handle no cards available
                return false;
            }

            card.Used = true;

           //snip...

            context.SaveChanges();
        }

In my test console app ‘card’ will have a value, while in my “service” it does not. Same code (same assembly even), same db, same rows available. The account retrieval works in both cases.

I am going to try this:
How to force EF Code First to query the database?

But even if that works the inconsistent behaviour doesn’t make sense to me.

EDIT:

Ends up I have two database instance as pointed out. The interesting part is the datasource changes depending on where the library is run from (as debug under VS11 or from a service running as the admin user). Here’s my app.config:

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True" />
  </parameters>
</defaultConnectionFactory>

When I attached to the service process running the same library (DLL) as the console application the datasource has changed from:

(localdb)\v11.0

To:

.\SQLEXPRESS

Same DLL, same app.config. I vaguely remember reading something about named vs unamed local db instances and what user they are run under, however my google skills are failing me currently.

So when I open a connection in SSMS I need to use the appropriate server name depending on which db I’m working with. Not a big deal as this is just the setup for development.

My question:

  • Does anyone know where this is documented?
  • 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-04T16:37:21+00:00Added an answer on June 4, 2026 at 4:37 pm

    The issue was using two databases. Two were being used as I didn’t have a .config in the actual running folder with the connection string for my service. The test application had a .config with

      <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
            <parameters>
                 <parameter value="Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True" />
            </parameters>
      </defaultConnectionFactory>
      </entityFramework>
    

    The service did not and therefore fell on the default behaviour (which appears is connecting to the default instance of SQL Server).

    I would have rather had the application fail to create the DB (throwing an exception) without a connection explicitly stated, however it is documented by Microsoft in the ‘remarks’ section of DbContext:

    If no connection string is found, then the name is passed to the DefaultConnectionFactory registered on the Database class. The connection factory then uses the context name as the database name in a default connection string. (This default connection string points to .\SQLEXPRESS on the local machine unless a different DefaultConnectionFactory is registered.)

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.