如何使用LINQ登录的用户连接到不同的数据库 [英] Howto connect to diffirent database based on logged in user with LINQ

查看:122
本文介绍了如何使用LINQ登录的用户连接到不同的数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我会尽力澄清这一点:)

情况
我有一个可以俯瞰数据库的数据库,其中包含一个与用户相关的表. 根据登录的用户,应用程序应连接到包含有关该用户的组织的更多信息的数据库.
因此,用户属于多个(动态)数据库.
所有组织数据库都具有相同的表结构,但位于单独的数据库中.

问题
如果我想与Linq合作,是否可以即时连接到不同的数据库?
我可以将组织数据库的connetionStrings保存到俯瞰数据库中吗?还是最好的方法是在这里?

谢谢!

Hi, i will try to be as clear as possible on this :)

Situation
I have one overlooking database, that hold a table with users.
Depending on which user logs in, the application should connect to a database that holds more information about that user''s organization.
So there are multiple (dynamic) databases where users belong to.
All the organizational databases have the same structure of tables but are in seperate databases.

Questions
If i would like to work with Linq, is it possible to connect to different databases on-the-fly?
Can i save the connetionStrings of the organizational databases in my overlooking database then or what is best here?

Thank you!

推荐答案

是的,您可以与每个用户一起保存对正确连接字符串的引用,因此您将拥有一个连接字符串表和一个外键引用.您的用户表中的内容.

当您对用户的验证感到满意后,请重新调整连接字符串,然后使用它来访问下一个数据库.

这是一篇文章的链接,其中提供了一种在Linq/Sql中使用动态连接字符串的解决方案:

LINQ to SQL动态连接字符串 [
Yes, you could save a reference to the correct connection string with each user so you would haver a table of connection strings and a foreign key reference to that from your user table.

Once you are satisfied that the user is validated retunr the connection string and use that to get to the next database.

Here is a link to an article with one solution to using dynamic connection strings with Linq/Sql:

LINQ to SQL Dynamic Connection String[^].

I''m curious as to why you are having to do it this way rather than, for instance, having a single database.


这篇关于如何使用LINQ登录的用户连接到不同的数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆