The processName field is static so it only needs to be initialized
once per application domain, during the first connection.
The GetProcessName() method is static to allow access to the static
processName field.
Inside GetProcessName() we check if the processName field is
initialized or not, if not we do the try/catch otherwise we just
return the processName field (no try/catch at every new connection,
only the first one).

I do not know enough about asp.net of compact framework to handle those parts.

private DatabaseParameterBuffer BuildDpb(IDatabase db,
FbConnectionString options)
{
    ......
    dpb.Append(IscCodes.isc_dpb_process_name, GetProcessName());
    return dpb;
}

static string processName;

#if (NET_CF)
        // for CF we can implement GetModuleFileName from coredll
        private static string GetProcessName()
        {
                if (processName == null)
                {
                  try
                  {
                    StringBuilder path = new StringBuilder(1024);
        
                    if(GetModuleFileName(IntPtr.Zero, path, path.Capacity) > 0)
                    {
                        processName = path.ToString();
                      return processName;
                    }
                  }
                  catch{}
        
                  processName = String.Empty;
                }
                
          return processName;
        }
#else
        private static string GetProcessName()
        {
                if (processName == null)
                {
                        try
                        {
                    try
                    {
                      processName = 
Process.GetCurrentProcess().MainModule.FileName;
                      return processName;
                    }
                    catch{}
                    try
                    {
                      processName = AppDomain.CurrentDomain.BaseDirectory +
"-" + AppDomain.CurrentDomain.FriendlyName;
                      return processName;
                    }
                    catch{}
                        }
                        catch{}
                        processName = String.Empty;
                }
                
          return processName;
        }
#endif



On Sat, Feb 28, 2009 at 6:43 PM, Jiri Cincura <disk...@cincura.net> wrote:
> First, I don't wanna to catch there exception, it's too slow. Let user
> to modify it in connection string isn't good idea, it's used for
> process identification, not for custom stuff - even Firebird tools are
> not allowing to modify it.
>
> On the other hand, I was thinking about, instead of showing stricly
> process name - which is for ASP.NET almost useless, we may show the
> path to current application. This may be helpful to see what site is
> having what connection.
>
> The only problem is, how to detect this in advance. I haven't looked
> to it deeply yet, but maybe there's a way to detect ASP.NET
> environment easily.
>
> What do you think?
>
> --
> Jiri {x2} Cincura (CTO x2develop.com)
> http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com
>
> ------------------------------------------------------------------------------
> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
> -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
> -Strategies to boost innovation and cut costs with open source participation
> -Receive a $600 discount off the registration fee with the source code: SFAD
> http://p.sf.net/sfu/XcvMzF8H
> _______________________________________________
> Firebird-net-provider mailing list
> Firebird-net-provider@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
>



--

Gareth

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to