Linq DBML multiple sql servers

2019-08-03 15:52发布

问题:

I have an archive system that had to be on two sql databases for simplicity

one is
Archive2009
and the other Archive2010

they are both on the same sql server and instance and have identical structures however I have a page that needs to view the old one and the new one (I can make two seperate pages)

How best would I go about doing this? Dynamically changing the connection string etc?

回答1:

If you are accessing these databases via L2S, then you'll probably want a DBML that points to Archive2009, and a DBML that points to Archive2010. Then your queries can use whichever DBML is appropriate. If you run into namespace issues, use different generated namespaces for each DBML.



回答2:

You probably best use two Linq-to-SQL data contexts, e.g. one for Archive2009 and the other for Archive2010. That way, each of the data contexts is dealing with just a single database and you can select stuff from both data contexts at the same time.



标签: linq-to-sql