How can I use several databases at the same time in a DBMS solution?

I have two unrelated databases, and I need to transfer data back and forth between them. Currently, I have created two separate entity models - one for each database, but this causes problems in my b / c code. I need to make use of nameofcontext / End Using and when I try to use some results from the first section of code per second Using nameofcontext / End I do not like using it - b / c I closed the connection to the first database!

+3
source share
1 answer

Since this is a website, you can create one instance of each context in the Global.asax BeginRequest event and get rid of this instance in EndRequest. This means that during the remaining life cycle of the event, you have contexts that will remain open and can do what you need, but you still know that they are configured correctly.

The way I ran into such problems.

Note. Do not store the context in a global shared variable, because it will share it between multiple requests, and havok will provide. HttpContext.Current.Items allows you to store something that is easy to get in your code, but has specifics for the current request, so that there is a safe place to store them.

+3
source

All Articles