Grygonos has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

If anyone is familiar with SQL Server's Enterprise Manager, please read on. In Enterprise Manager, when viewing the current activity and process information, the application's name can be shown that corresponds to that user process. Does anyone have any experience with asking DBI to populate that field? Does DBI have the ability to populate that field?

<EDIT>GWAHAHHAA...solution... my $dbh = DBI->connect('DBI:ODBC:dsn=x;app=appname',$login,$pass); Thanks for everyone's help on this... but here is the answer for interested parties</EDIT>

Thanks,

Grygonos

Replies are listed 'Best First'.
Re: Report Application Name to Enterprise Manager via DBI
by EdwardG (Vicar) on Jun 09, 2004 at 15:37 UTC
    use DBC; # my own connector, uses DBI my $dbh= DBC->connect( { database => master } ); my $sql = qq{ select spid, program_name from sysprocesses -- not portable }; print "spid\tprogram_name\n"; print "----\t------------\n"; print "$$_[0]\t$$_[1]\n" for @{$dbh->selectall_arrayref($sql)}; __END__ spid program_name ---- ------------ 1 2 3 4 5 6 7 8 9 10 11 12 51 SQLAgent - Generic Refresher 52 SQLAgent - Alert Engine 53 SQL Profiler 54 MS SQLEM 55 SQL Query Analyzer 56 ActivePerl

     

Re: Report Application Name to Enterprise Manager via DBI
by VSarkiss (Monsignor) on Jun 09, 2004 at 15:36 UTC

    Yes. It's not a function of DBI: it's stored in the catalog, in the master database. You can retrieve it with a regular query.

    I don't recall the exact field name, but the easy way to get it is to look the text of the sp_who stored procedure. IIRC, sp_who itself is in the sybsystemprocs database.

      Actually they are logical tables.. a series of memory structures within SQL Server.. it just appears as tables. master..sysprocesses is just one such table.

      Jason L. Froebe

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: Report Application Name to Enterprise Manager via DBI
by Grygonos (Chaplain) on Jun 09, 2004 at 16:56 UTC

    I understand where it is stored.. this makes sense. How can I get my application to report its name to that table is my question. Any ideas?

      Howdy!

      IIRC, that is something you can set when you connect to the server.

      It's been a while since I did Sybase, so check your manuals... :)

      yours,
      Michael
        I found this in the ODBC API Doc,

        APP - Name of the application calling SQLDriverConnect (optional). If specified, this value is stored in the master.dbo.sysprocesses column program_name and is returned by sp_who and the Transact-SQL APP_NAME function.

        Passing app as part of \%attr does nothing and passing APP produces and error. Any ideas anyone?
Re: Report Application Name to Enterprise Manager via DBI
by dba (Monk) on Jun 10, 2004 at 14:46 UTC
    You may have to tweak the source code and add your attribute in the connect sub
    package DBD::mSQL::dr; # ====== DRIVER ====== use strict; sub connect { my($drh, $dsn, $username, $password, $attrhash) = @_; my($port); my($cWarn); # Avoid warnings for undefined values $username ||= ''; $password ||= ''; # create a 'blank' dbh my($this, $privateAttrHash); $privateAttrHash = { 'Name' => $dsn, 'user' => $username, 'password' => $password, # here ? };

      This was one of the earlier methods I attempted. I couldn't get it to work, although it seemed plausible. I don't know if it's completely impossible, but I couldn't manage it. The solution I listed in the original post does work however.