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.
a source to share
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.
a source to share
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
a source to share
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.
a source to share
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
a source to share