¿Cómo puedo obtener el usuario actual de Sqlconnection?
Frecuentes
Visto 1,064 equipos
0
I am trying to determine what user my application is using to authenticate to my database, is there a way that I can get the user that is being used to execute the sql code?
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());
}
}
}
2 Respuestas
0
Execute following command against database
sp_who2
it lists all open connections including logins and host names.
contestado el 28 de mayo de 14 a las 15:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas asp.net sqldatasource sqlconnection sqldataadapter or haz tu propia pregunta.