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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:59:21+00:00 2026-05-21T18:59:21+00:00

I’m gonna try to explain this without actually mucking through the whole design of

  • 0

I’m gonna try to explain this without actually mucking through the whole design of the application I’m working on. Cause who cares about that. If it’s pertinent, I can give more detail but I think I cover everything below.

main problem:

I’ve got a few stored procedures that I need to execute periodically. I get the proc names from a database table, so my application has no hard coded knowledge of them. This is by design. I’m currently using the entity framework to do all my data access.

My application is multi threaded — I grab all the procs that I need to run, then iterate through each one, grab its properties from my configuration tables and queue it up to run on a separate thread in the app’s thread pool.

I’m using the Database.Connection.CreateCommand method and executing the procs — pulling the data into a data table. This works out well when I’m only executing one proc, but when

Problem is that I run into concurrency issues. The specific exception I’m getting is

System.Data.SqlClient.SqlException:
New transaction is not allowed because
there are other threads running in the
session.

I’m assuming this is because I’m trying to execute my procedure while also accessing the properties of another procedure via the entity framework.


Potential solutions / trains of thought that occur to me:

  • I can get this to work just fine using the DbContext.Database.SqlQuery method if I write a model class that has the fields I need. But what if I don’t want to write a model class at all? Is there a way I can do this and let the entity framework actually handle the query?

  • I could grab all of the properties before i start executing any procs. That would probably work fine. If I define my properties as ICollections on the model that tells me what procedure to run, is there a way to force them to load when I select said model from the DB instead of when I iterate through them later to read them?

  • 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-21T18:59:22+00:00Added an answer on May 21, 2026 at 6:59 pm

    The main problem here is that you are using single database connection (Database.Connection returns the same instance for all your CreateCommand calls) by multiple threads and you are trying to define multiple transactions concurrently. The solution for this scenario is only one – use a new connection per stored procedure / thread. You should be able to get connection string by calling Database.Connection.ConnectionString.

    • Your first solution will not solve the problem unless you run a new context in each thread.
    • Database.SqlQuery always require type for loading data. Entity framework make easier data access by mapping result sets to types. If you don’t have a type you can’t take any advantage of EF.
    • The way to load relation immediately is called eager loading and is performed by Include method used in the query. You will just say which navigation properties on the mapped entity must be loaded immediately.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.

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.