SQL Server 2005/2008: defining the current user

I have a web application that uses a SQL Server 2005 database.

My problem is that the application does not have role management. Thus, the application always accesses the database with a single user by default. But now I need to save and access the value only for the current user.

Is there any way to do this? Maybe something like a session on a web server? A better way would be if it is possible to access the current web server session id from T-SQL.

Does anyone understand my problem? :)

+3
source share
2

DECLARE @sys_usr char(30);
SET @sys_usr = SYSTEM_USER;
SELECT 'The current user is: '+ @sys_usr;
GO

from MSDN

-, . : -:

command.CommandText = "EXEC mySP @user";
command.Parameters.Add("@user").Value = ((YourOwnUserClass)Session["user"]).Name;

// or System.Web.HttpContext.Current.User.Identity.Name; to use built-in
// from web page it becomes this.User.Identity.Name;
+5

Windows SQL:

  • Windows, . .
  • SUSER_NAME() Windows ( loginDomain\userName.
-1

Source: https://habr.com/ru/post/1740416/


All Articles