Azure SQL 数据库和 EXECUTE AS USER - C# 连接池
Azure SQL Database and EXECUTE AS USER - C# Connection Pooling
我有一个 Azure SQL 数据库和一些使用它的 C# 业务应用程序。我一直在努力减少攻击面并更好地了解性能。
在 SQL Azure 包含的数据库中,我有:
1) 一个 SQL 身份验证用户,登录名为 'ReaderUser',具有固定的又长又疯狂的密码。
2) 在没有登录的情况下在数据库中创建的用户使用:CREATE USER [] WITHOUT LOGIN
3) 包含数据的表,由用户和行级安全保护。 ReaderUser 无法访问任何数据,它只是一个 "Proxy" 用户。
4) ReaderUser 可以模拟任何其他非管理用户(创建的种类 "without login")。数据只能被他们中的任何一个读取。
当我们开发的application/s被用户访问时,数据库连接是用ReaderUser建立的。应用程序使用 .Net 4.6.2 ADO.net 连接。连接字符串已加密并固定。 IE。它对任何用户都没有改变,他们都使用相同的连接字符串。
当应用程序用户登录时,登录的应用程序身份 (Active Directory UPN) 将传递到数据库以使用以下方法设置正确的用户上下文:
EXECUTE AS USER = 'myuser@mydomain.com' WITH NO REVERT;
用户随后访问应用程序并且只能看到他们的数据,这受到行级安全性的限制。
我的问题是,连接将如何合并?它们是按用户还是按 ReaderUser 登录名(连接字符串)合并?用户可以使用相同的连接字符串同时从多个应用程序进行连接。我浏览了几篇文章,但无法对这种特定情况做出明确的解释。任何人都可以解释一下吗?
希望使用 EXECUTE AS
连接池的应用程序必须使用 special cookie syntax:
When the WITH NO REVERT COOKIE = @varbinary_variable
clause is specified, the SQL Server Database Engine passes the cookie value to @varbinary_variable
. The execution context set by that statement can only be reverted to the previous context if the calling REVERT WITH COOKIE = @varbinary_variable
statement contains the same @varbinary_variable value.
This option is useful in an environment in which connection pooling is used. Connection pooling is the maintenance of a group of database connections for reuse by applications on an application server. Because the value passed to @varbinary_variable is known only to the caller of the EXECUTE AS statement, the caller can guarantee that the execution context they establish cannot be changed by anyone else.
所以您的应用程序负责在将连接返回到池中之前使用特殊 cookie 恢复执行上下文。
我有一个 Azure SQL 数据库和一些使用它的 C# 业务应用程序。我一直在努力减少攻击面并更好地了解性能。
在 SQL Azure 包含的数据库中,我有:
1) 一个 SQL 身份验证用户,登录名为 'ReaderUser',具有固定的又长又疯狂的密码。
2) 在没有登录的情况下在数据库中创建的用户使用:CREATE USER [] WITHOUT LOGIN
3) 包含数据的表,由用户和行级安全保护。 ReaderUser 无法访问任何数据,它只是一个 "Proxy" 用户。
4) ReaderUser 可以模拟任何其他非管理用户(创建的种类 "without login")。数据只能被他们中的任何一个读取。
当我们开发的application/s被用户访问时,数据库连接是用ReaderUser建立的。应用程序使用 .Net 4.6.2 ADO.net 连接。连接字符串已加密并固定。 IE。它对任何用户都没有改变,他们都使用相同的连接字符串。
当应用程序用户登录时,登录的应用程序身份 (Active Directory UPN) 将传递到数据库以使用以下方法设置正确的用户上下文:
EXECUTE AS USER = 'myuser@mydomain.com' WITH NO REVERT;
用户随后访问应用程序并且只能看到他们的数据,这受到行级安全性的限制。
我的问题是,连接将如何合并?它们是按用户还是按 ReaderUser 登录名(连接字符串)合并?用户可以使用相同的连接字符串同时从多个应用程序进行连接。我浏览了几篇文章,但无法对这种特定情况做出明确的解释。任何人都可以解释一下吗?
希望使用 EXECUTE AS
连接池的应用程序必须使用 special cookie syntax:
When the
WITH NO REVERT COOKIE = @varbinary_variable
clause is specified, the SQL Server Database Engine passes the cookie value to@varbinary_variable
. The execution context set by that statement can only be reverted to the previous context if the callingREVERT WITH COOKIE = @varbinary_variable
statement contains the same @varbinary_variable value.This option is useful in an environment in which connection pooling is used. Connection pooling is the maintenance of a group of database connections for reuse by applications on an application server. Because the value passed to @varbinary_variable is known only to the caller of the EXECUTE AS statement, the caller can guarantee that the execution context they establish cannot be changed by anyone else.
所以您的应用程序负责在将连接返回到池中之前使用特殊 cookie 恢复执行上下文。