Retrieving the Application Executable Name from a T-SQL Stored Procedure

From a stored procedure in SQL Server, can I get the name of the executable file (that is, MyApp.exe) that owns the connection? I know there is APP_NAME (), but it looks like it just returns whatever string passed to the Application Name parameter in the connection string.

If possible, how can this be done? Thanks.

0


a source to share


6 answers


Unfortunately, I don't know anything like that - remember that the connection comes from a completely different machine, most likely.



Perhaps you can create your own security so that different applications use different usernames to access the database. Finding the current user is easy.

+2


a source


Unless you change your stored procedure to pass the application name, you are stuck in the results of APP_NAME (). Hopefully the developers are posting meaningful values ​​here and not just accepting the default, which is usually a metric for the development tool used to build the application.

Hope it helps,



Bill

+4


a source


You can get the computer and information from the connection string, but basically this.

Through monitoring and other measures, you can ensure that developers always use the application name in their connection strings. For example, you can log cases where this is an unapproved app name, or use a profiler to keep an eye on things.

+1


a source


Oracle can provide you with the exe name, but SQL Server cannot - different architectures.

0


a source


I understand that this is not exactly what you are looking for. But you can define the bit of the call stack using DBCC INPUTBUFFER. If you put logic in this window inside the store and write it somewhere you can get the caller information.

            CREATE TABLE #dbc
                (
                  EventType VARCHAR(15),
                  Parameters INT,
                  EventInfo VARCHAR(255)
                )
              DECLARE @execStr VARCHAR(500)
              SET @ExecStr = 'DBCC INPUTBUFFER(' + STR(@@SPID) + ')'



              INSERT    INTO #dbc
                        EXEC ( @execStr
                            )

              SELECT    *
              FROM      #dbc

      

0


a source


You can also get the process ID on the client machine, so if you had a magical way to match the process name you could do that.

0


a source







All Articles