I need to work on this poorly designed db where a new group of data are established by adding a new db to the server. So I have to fetch data from multi dbs, I wonder is there a way to get all thoes group data through one connection? I am using c#.
Share
(aside: is it possible to influence the design? This sounds in part like what database schema names are designed for…)
It is sometimes possible (for example in SQL Server by using
database.schema.objectnotation, or evenserver.database.schema.object), but I don’t recommend it as the same approach won’t fit all use-cases, and it breaks a lot of best-practice guidelines. I would strongly recommend simply generating the connection string per database, perhaps usingDbConnectionStringBuilder, or more specific variants likeSqlConnectionStringBuilder.You could disable pooling on the dynamic connections if you are worried about having too many open (pooled) connections (but you would then need to handle connection management yourself; personally I’d be tempted to leave pooling enabled until I can prove there is a problem).