[英]Creating user for SQL Server database and accessing through C#.net application
I have created the users for SQL Server database. 我已经为SQL Server数据库创建了用户。 It got created just fine.
它创建得很好。
My problem is when I am accessing through application by executing the following code it does not switch to that user which I am specify as 我的问题是,当我通过执行以下代码访问应用程序时,它不会切换到我指定为的用户
exec as user='myuser'
ALTER USER myuser WITH DEFAULT_SCHEMA=maindb
EXEC sp_addrolemember N'db_owner', N'myuser'
and I have run the query as 我已经运行查询为
DbCommand command = ds.CreateCommand();
command.CommandText = "exec as user='myuser'";
command.CommandType = CommandType.Text;
command.ExecuteNonQuery();
from C# code 从C#代码
Waiting for your valuable responses and comments 等待您的宝贵回应和评论
yes, this is expected. 是的,这是预期的。 the connection string contains the credentials required to connect to the server.
连接字符串包含连接到服务器所需的凭据。 and typically there is a single connection string between the application and database to optimize resources and take advantage of connection pooling etc.
通常在应用程序和数据库之间只有一个连接字符串,以优化资源并利用连接池等。
different users may have different rights in the system, but that can be handled by authorization, not connection strings. 不同的用户在系统中可能具有不同的权限,但是可以通过授权而不是连接字符串来处理。
The user or login name specified in EXECUTE AS clause must exist as a principal in sys.database_principals or sys.server_principals, respectively, or else the create or alter module operation fails.
EXECUTE AS子句中指定的用户名或登录名必须分别作为主体存在于sys.database_principals或sys.server_principals中,否则创建或更改模块操作将失败。 Additionally, the user that creates or alters the module must have IMPERSONATE permissions on the principal.
此外,创建或更改模块的用户必须对主体具有IMPERSONATE权限。
Do you satisfy those conditions? 您满足这些条件吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.