Question

LinqToSql Context

Asked by: jherington

Hello,

I have added a second LinqToSql dbml to a project within my ASP.Net solution and when I did this I got context errors in all my pages. I discovered that I needed to assign a unque text value to both the Context Namespace and Entity Namespace for each of the dbml's. This fixed the context errors but I also ran across Linq to SQL DataContext Lifetime Management (http://www.west-wind.com/weblog/posts/246222.aspx) That discusses a context factory for LinqToSql. My question is; do I need to do somthing more then simply refering to a unique context object per dbml within a page: i.e. Private db As NCS_LINQ.NCS.Orders.NCSOrdersDataContext = New NCS_LINQ.NCS.Orders.NCSOrdersDataContext.

Thanks!

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-07-21 at 12:48:39ID24588787
Topics

.NET

,

Programming for ASP.NET

,

Language Integrated Query - LINQ

Participating Experts
1
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. weblogic 6.1
    Hi , On weblogic 6.1 I get this error : ####<Feb 24, 2003 4:39:13 PM IST> <Info> <HTTP> <YOAVGOL01> <crmServer> <main> <system> <> <101053> <[HTTP crmServer] Loading web app: webApp_crmServer> ####<Feb 24, 2003 ...
  2. Weblogic Context root
    Let me give you some background first. My organization recently upgraded from weblogic 5.1-to 8.1 web server platform, as a part of department wide ERP upgrade. In 5.1, we deployed a web application that comprised of Servlets & JSPs. Business logic was housed in app ser...
  3. Reason for having JNDI Naming context factory in Statful se…
    Why stateful session bean's constructor should maintain JNDI Naming context factory,ejb context?
  4. Problem in deploying EJB to weblogic 8.1 from eclipse
    hi, i have developed an EJB as mentioned in the tutorial of eclipse EJB Development section. I have created a TraderBean and generated the rest of the classes and interface classes and deployment descriptor through XDoclet and deployed the bean through eclipse on bea weblogic...
  5. How to construct a Dynamic Query in CMP Entity Bean in W…
    I want to know if there is anyway i can construct a dynamic query for my CMP Entity bean ? I have a session bean for my entity bean. I want to put a method in session bean and construct a dynamic query in this method and then execute it on my entity bean. How can i do it?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: FernandoSotoPosted on 2009-07-21 at 13:35:22ID: 24909054

Hi jherington;

What you did is fine as long as the two DataContext do not reference and change the same table data.

For example lets say you have two data context, DC1 and DC2,  and both of them have database A table B with Row 1 loaded from executed Linq queries. If you make a change to the values in row 1 from DC1, DC2 will not know of that change until it tries to make changes to it itself and you will receive a concurrency error on DC2. It is legal to have two data context you just need to be aware of what can go wrong.

Fernando

 

by: jheringtonPosted on 2009-07-21 at 14:58:05ID: 24909774

OK, so one thing I do is when a page loads I fill a dropdown with all our Customer Names for example. Then later within a grid on the same page the user may change the spelling of one of the Customer Names. Both the dropdown and the grid were filled by the same datacontext; is this an example of a potential problem?

 

by: FernandoSotoPosted on 2009-07-21 at 20:38:43ID: 24911402

Hi jherington;

To your question:
"I fill a dropdown with all our Customer Names for example. Then later within a grid on the same page the user may change the spelling of one of the Customer Names. Both the dropdown and the grid were filled by the same datacontext; is this an example of a potential problem?"

No, not in that case. When using the same data context, that data context does object tracking of all the tables created in that context and therefore all bound controls see all the changes made at the same time.

Fernando

 

by: jheringtonPosted on 2009-07-22 at 11:33:56ID: 24918149

Ok, thanks so much Fernando,

I actually meant to say that they come from different datacontexts. So basically the combo is filled by contextA with customer names and users will select from the dropdown to filter the grid. The grid is filled by contextB. Both contextA and contextB will pull from the customer table and both return CustomerName. The user will then edit a grid data item and change the spelling of a customer name. Will this throw an exception or will I simply need to rebind the dropdown to show the changes.

Sorry again for not asking the question correctly the first time, but your answer was helpful anyway.

 

by: FernandoSotoPosted on 2009-07-22 at 14:20:59ID: 24919772

Hi jherington;

In your last post seeming that the changes are made in the data grid control only and not as well in the combo box it will not cause a problem. It will get out of sync, names in the data grid with the ones in the combo box. To prevent that issue clear the items in the combo box and re-execute the query that fills it.

The problem comes in when, lets say you have two controls that allows you to modify the data in it which connect to the same table and lets also say that the first record in the database is modified by the first control, no problem yet, then the same record is modified in the second control which will throw a Change Conflict Exception Row Not Found or Changed. So you will need to set up code to catch and correct the error, known as conflict resolution.

Is there a reason why you are not using the same data context?

Fernando

 

by: jheringtonPosted on 2009-07-23 at 06:40:22ID: 31606115

Thank you for following through with each of these questions! I will switch to use the same data context in those scenarios.

 

by: FernandoSotoPosted on 2009-07-23 at 08:14:08ID: 24926120

Not a Problem, always glad to help.  ;=)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...