简体   繁体   English

每个已连接用户的设置

[英]Settings per connected user

I have an windows forms application which I'm migrating from MySql to MsSql. 我有一个Windows窗体应用程序,我正在从MySql迁移到MsSql。 In MySql we are using database users for every user. 在MySql中,我们为每个用户使用数据库用户。 So every user connects to the database using their own account. 因此,每个用户都使用自己的帐户连接到数据库。 This is not what we want, because in the future we want the application set open to the world and database users is not a thing on the wishlist. 这不是我们想要的,因为在将来,我们希望向世界开放该应用程序集,而数据库用户不在愿望清单上。 So this is going away. 因此,这将消失。

The problem is that many views work with a function which uses CURRENT_USER() to give access to records (because users are part of a department and are not allowed to see all records of all departments). 问题在于,许多视图都使用使用CURRENT_USER()来访问记录的函数(因为用户是部门的一部分,并且不允许查看所有部门的所有记录)。

In MsSql we are using just one type of connectionstring, but every application connects the database directly. 在MsSql中,我们仅使用一种类型的连接字符串,但是每个应用程序都直接连接数据库。 Is it possible in MSSQL to store variables per connection so I can identify a user in the view by the variable I set after creating the connection? 在MSSQL中是否可以为每个连接存储变量,以便我可以通过创建连接后设置的变量在视图中识别用户?

So it would be like this: 所以会像这样:

  1. Start application 开始申请
  2. Users logs on 用户登录
  3. Application creates connection with mssql 应用程序与mssql创建连接
  4. Application sets a variables on sql-server 应用程序在sql-server上设置变量
  5. User opens a screen with a view 用户打开带有视图的屏幕
  6. SQL server returns the view using the variable that has ben set earlier to only return the allowed records to view. SQL Server使用早先设置的变量返回视图,以仅返回允许的记录进行查看。

So every user must have it's own variable. 因此,每个用户都必须拥有自己的变量。 Is that possible? 那可能吗?

Application is build with NET and iBatis. 应用程序是使用NET和iBatis构建的。 Not the best combination, but iBatis is to much integrated to throw it all overboard. 不是最好的组合,但iBatis集成度很高,可以将其全部抛弃。

While this may or may not be possible, it's definitely not the right way to go. 尽管这可能或不可能,但绝对不是正确的方法。 As you said, you're using a single connection string, and likely using a pool of connections to access the database. 如您所说,您使用的是单个连接字符串,并且很可能使用连接池来访问数据库。 As you want users to be able to pick any available connection in the pool to do their queries, you don't want any user state (or any state at all for that matter) to be tied to the connection. 因为您希望用户能够选择池中的任何可用连接来进行查询,所以您不希望将任何用户状态(或与此相关的任何状态)都绑定到该连接。

As you're opening up to the world, you don't want the application to directly connect to the database. 在向世界开放时,您不希望应用程序直接连接到数据库。 Instead, you should implement middleware that will handle authentication and access rights, and only return data from the database that the user may access. 相反,您应该实现中间件,该中间件将处理身份验证和访问权限,并且仅从用户可以访问的数据库中返回数据。 So instead of 所以代替

user application <- iBatis -> MSSQL

you'll have: 您将拥有:

user application <- HTTP/something else -> API <- iBatis -> MSSQL

This is the approach taken used by websites as well. 这也是网站使用的方法。 In addition, you'll be able to add functionality like caching, connection pooling etc. to the API, making it possible to support more users. 另外,您将能够向API添加诸如缓存,连接池等功能,从而有可能支持更多用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM