Entity framework: retrieving data from different databases - sql-server

I have the following scenario
I have 4 different (sql server) databases (legacy), one for each geo (NA,AP,LA,EMEA). The schema is the same in all the db's.
I am in the process of creating a front-end which will go across 4 different db's based on the users selection.I am thinking of using Entity framework. The db's are on different servers. What is the best way to create the entities? should i create 4 different edmx? there will be scenarios when the users results need to come from one or more db's
Thanks,
Nagendra

If databases are exactly same you can create edmx file only for one of databases (the mapping will be same for all DBs) and use 4 ObjectContext instances with different connection strings. The problem here can be with your second requirement. Querying more DBs means that you have to query each DB separately and merge/union results in memory on the application server. So such scenario is not very good for advanced querying where you need to run complex queries on all databases at the same time.

Related

When to Create DB and When to Create Schema

This seems a design question but I wanted to know if there is a pattern or design consideration we need to have where we would want to create a Database and not a new schema.
why not create one big database and separate schemas. Under what circumstance should we create a new database.
They are just logical divisions, so for the most part it's a matter of preference. There is one place where it's not a matter of preference: replication.
As of September, 2022, the unit of replication is the database. It's possible to specify which databases you want to replicate, but not which schemas within a database to replicate.
If you plan to replicate, you'll want to think about keeping only the schemas/tables that are important to replicate in one or more databases that get replicated and keep other data in databases that do not get replicated.
Another thought could be, In a large DWH Enterprise Solution,
There can be variety of flavours of tables which You can map to different databases. Sales DB, Master DB, Finance DB for ex. Then Inside DBs, You may want to have schemas for tables, views ,procedures and other object .

MS SQL Server: central database and foreign keys

I'm am currently developing one project of many to come which will be using its own database and also data from a central database.
Example:
the database "accountancy" with all accountancy package specific tables.
the database "personelladministration" with its specific tables
But we also use data which is general and will be used in all projects like "countries", "cities", ...
So we have put these tables in a separate database called "general"
We come from a db2 environment where we could create foreign keys between databases.
However, we are switching to MS SQL server where it is not possible to put foreign keys between databases.
I have seen that a workaround would be to use triggers, but I'm not convinced that is a clean solution.
Are we doing something wrong in our setup? Because it seems right to me to put tables with general data in a separate database instead of having a table "countries" in every database, that seams difficult to maintain and inefficiƫnt.
What could be a good approach to overcome this?
I would say that countries is not a terrible table to reproduce in multiple databases. I would rather duplicate static data like that than use more elaborate techniques. There is one physical schema per database in sql server and the schema can not be shared. That is why people use replication or triggers for shared data.
I can across this problem a while back. We have one database for authentication, however, those users have to be shared across multiple applications some of which have their own database.
Here is my question on this topic.
We resorted to replication and using an custom Authentication/Registration service agent to keep the data up to data.
Using views, in what Sourav_Agasti suggested in his answer, would be the most straight forward approach for static data. You can create views and indexed views and join data from databases on linked servers.
Create a loopback linked server and then create a view(if required, on each database) which accesses the table in this "central database" through this linked server. There will be a minor performance impact but it more than enough compensates by being very simiplistic.

Bulk replace of content of SQL Server tables

My ASP.NET MVC application has a number of web servers accessing a SQL Server database via Entity Framework 6. The database has 2 tables, with a one to many relationship between them.
Once a day, the entire contents of both tables needs to be replaced by a new dataset that is loaded over the Internet from a remote web service. The number of records may be in the tens out thousands. The records are not very big, with about 10 nvarchar and integer fields each.
I'm planning to have one web server load the dataset from the remote web service into the 2 SQL Server tables. It would need to remove the old content and efficiently load the new content. While this is happening, the other web servers have to be prevented from accessing the tables (probably by locking the tables).
I'm looking for fast options to accomplish this, and their pros and cons. If there is a NuGet package or Entity Framework command that does this for me, that would be ideal.
Load them into temporary tables and MERGE (merge statement) Them into the daily use tables.

Usage of Database, schemas and tablespace

we are working on data migration of sql server 2000 to Oracle 11g. Sql server has 4 databases which has to be migrated. These 4 databases are used for 6 different standalone applications. Oracle is installed in Unix server. Can we create a single database and different schemas for each sql server database or do I need to create multiple databases or can I use single database, single schema and multiple tablespaces or any other procedure to maintain the performance?
You can create multiple Oracle databases. Or you can create a single database with multiple schemas. Or you can create a single database with a single schema an put everything there if all your object names are unique.
The most similar approach would generally be to create a single Oracle database with four schemas. That gives you four separate namespaces in case you have objects in two different SQL Server databases that have the same name. And a single Oracle database per server generally gives the best performance since you're not allocating multiple SGAs and PGAs in memory or running multiple sets of background processes.
Tablespaces in Oracle are a completely separate concept. They have nothing to do with namespaces or permissions. They simply allow you to determine which objects reside in which physical data files. Barring something extremely unusual, tablespaces have nothing to do with performance. You could have the objects in all four schemas use a single tablespace. Or you could create four separate tablespaces. Or you could create multiple tablespaces that each have objects from different schemas. My guess is that the simplest approach is to create one tablespace per schema so that you can manage each application's disk space allocation separately.

SELECTing across multiple DB2 databases in one query

Ive run into the issue where I need to query 2 separate databases(same instance) in one query.
I am used to doing this with mysql, but Im not sure how to do it with DB2.
In mySQL it would be something like:
SELECT user_info.*, game.*
FROM user_info, second_db.game_stats as game
WHERE user_info.uid = game.uid
So the question is how i translate a query like that into DB2 syntax?
Equivalent of this
Is there a reason why you have the tables in a separate database? MySQL doesn't support the concept of schemas, because in MySQL a "schema" is the same thing as a "database". In DB2, a schema is simply a collection of named objects that lets you group them together.
In DB2, a single database is much closer to an entire MySQL server, as each DB2 database can have multiple schemas. With multiple schemas inside the same database, your query can run more or less unchanged from how it is written.
However, if you really have 2 separate DB2 databases (and, for some reason, don't want to migrate to a single database with multiple schemas): You can do this by defining a nickname in your first database.
This requires a somewhat convoluted process of defining a wrapper (CREATE WRAPPER), a server (CREATE SERVER), user mapping(s) (CREATE USER MAPPING) and finally the nickname (CREATE NICKNAME). It is generally easiest to do these tasks using the Control Center GUI because it will walk you through the process of defining each of these.

Resources