[英]How can I get the current user from Sqlconnection
我正在尝试确定我的应用程序正在使用哪个用户来对数据库进行身份验证,有没有办法让我获得用于执行sql代码的用户?
string connection = WebConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connection))
{
using (SqlDataAdapter adapter = new SqlDataAdapter())
{
adapter.SelectCommand = new SqlCommand();
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
adapter.SelectCommand.CommandText = "MySPName";
adapter.SelectCommand.Connection = conn;
using (DataSet ds = new DataSet())
{
try
{
adapter.SelectCommand.Connection.Open();
logULS("Connection Open");
//Want to log the user that has the connection open...
adapter.Fill(ds);
adapter.SelectCommand.Connection.Close();
}
catch (Exception ex)
{
logULS(ex.ToString());
}
}
}
对数据库执行以下命令
sp_who2
它列出了所有打开的连接,包括登录名和主机名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.