0

From a stored procedure in SQL Server, is it possible to get the name of the executable (ie MyApp.exe) that owns the connection? I know there is APP_NAME(), but that appears to just return whatever string was passed into the 'Application Name' parameter in the connection string.

If this is possible, how can it be done? Thanks.

1
  • I'm fairly sure that's not possible... Commented May 22, 2009 at 19:07

6 Answers 6

4

Unless you modify your stored procedure to pass the app name, you're stuck with the results of APP_NAME(). Hopefully, developers are placing meaningful values in there rather than just accepting the default value which is generally an indication of the development tool used to build the app.

Hope this helps,

Bill

Sign up to request clarification or add additional context in comments.

Comments

2

Unfortunately I'm not aware of any such thing -- remember that the connection is coming from an entirely different machine most likely.

Perhaps you can design you security so that different apps are using different user names to access the database. Finding the current user is easy.

1 Comment

Thanks, that is what we'll have to do.
1

You can get the computer and the information from the connection string, but that's basically it.

Through monitoring and other measures you can ensure that developers always use Application Name in their connection strings. For instance, you can log cases where it's not an approved applciation name, or use the profiler to watch for things.

Comments

0

Oracle can give you the name of the exe, but SQL Server can't - different architecture.

Comments

0

I realize this isn't exactly what you are looking for. But you can determine a bit of the call stack by using DBCC INPUTBUFFER. If you put logic like this in inside the storeprodedure and log it somewhere you might get some info about the caller.

            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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.