Re: Connection Pooling!!
- From: "Sahil Malik [MVP]" <contactmethrumyblog@xxxxxxxxxx>
- Date: Fri, 9 Sep 2005 22:55:47 -0400
Pools are per appdomain, per connection string. In case of NT Auth the pool
is further partitioned <-- That is the whole truth.
- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------
"Mark Ashton" <markash@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:O00wKEYtFHA.3188@xxxxxxxxxxxxxxxxxxxxxxx
> Here is a bit of V2.0 C# code using PerformanceCounters that shows each
> appdomain has its own connection pool for SqlClient. Pooling happens in
> native code for Odbc & OleDb, so their pooling is per process.
>
> using System;
> using System.Data.SqlClient;
> using System.Diagnostics;
> using System.Reflection;
> using System.Runtime.InteropServices;
>
> class CrossDomain : System.MarshalByRefObject {
>
> [DllImport("kernel32.dll")]
> private static extern int GetCurrentProcessId();
>
> private static string GetAssemblyName() {
> Assembly assembly = Assembly.GetEntryAssembly();
> if (null != assembly) {
> AssemblyName name = assembly.GetName();
> return name.Name;
> }
> return null;
> }
>
> private static string GetInstanceName() {
> string instanceName = GetAssemblyName();
> if (String.IsNullOrEmpty(instanceName)) {
> AppDomain appDomain = AppDomain.CurrentDomain;
> if (null != appDomain) {
> instanceName = appDomain.FriendlyName;
> }
> }
> int pid = GetCurrentProcessId();
> return String.Format("{0}[{1}]", instanceName, pid);
> }
>
> public string Start(string constr) {
> using(SqlConnection c = new SqlConnection(constr)) {
> c.Open();
> }
> return GetInstanceName();
> }
> }
>
> class Program {
>
> private static void NumberOfActiveConnectionPools(string name) {
> PerformanceCounter instance = new PerformanceCounter();
> instance.CategoryName = ".NET Data Provider for SqlServer";
> instance.CounterName = "NumberOfActiveConnectionPools";
> instance.InstanceName = name;
> instance.ReadOnly = true;
> Console.WriteLine("{0}: NumberOfActiveConnectionPools={1}",
> instance.InstanceName, instance.RawValue);
> }
>
> public static void Main(string[] args) {
> try {
> CrossDomain c0 = new CrossDomain();
>
> AppDomain ad =AppDomain.CreateDomain("Test");
> CrossDomain c1 =
> (CrossDomain)ad.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location,
> typeof(CrossDomain).FullName);
>
> string name1 = c0.Start("Data Source=.;integrated
> security=sspi");
> string name2 = c1.Start("Data Source=.;integrated
> security=sspi");
> string name3 = c1.Start("server=.;trusted_connection=sspi");
>
> NumberOfActiveConnectionPools(name1);
> NumberOfActiveConnectionPools(name2);
> if (name2 != name3) {
> NumberOfActiveConnectionPools(name3);
> }
> }
> catch (Exception e) {
> Console.WriteLine(e);
> }
> }
> }
>
>
> --
> This posting is provided "AS IS", with no warranties, and confers no
> rights. Please do not send email directly to this alias. This alias is for
> newsgroup purposes only.
>
> "David Browne" <davidbaxterbrowne no potted meat@xxxxxxxxxxx> wrote in
> message news:ebNfoOUtFHA.2912@xxxxxxxxxxxxxxxxxxxxxxx
>>
>> "Paul Clement" <UseAdddressAtEndofMessage@xxxxxxxxxxxxxx> wrote in
>> message news:4703i1512n8rk1ukph8dkjrk3itjfg808h@xxxxxxxxxx
>>> On Fri, 9 Sep 2005 00:46:55 -0400, "Sahil Malik [MVP]"
>>> <contactmethrumyblog@xxxxxxxxxx> wrote:
>>>
>>> ¤ I want to add a bit more. If your code uses impersonation, I believe
>>> that
>>> ¤ creates a new connection pool within the same appdomain .. (or am I
>>> wrong?)
>>> ¤
>>> ¤ - SM
>>>
>>> I'm assuming by appdomain you mean process?
>>>
>>> Connection pools are created per unique connection string and are
>>> process specific. You can have
>>> multiple connection pools per process, but these pools do not cross
>>> process boundaries.
>>>
>>
>> A Process is divided into one or more App Domain. Connection Pools are
>> scoped to the App Domain, just like any global/static variable.
>>
>> David
>>
>
>
.
- Follow-Ups:
- Re: Connection Pooling!!
- From: Paul Clement
- Re: Connection Pooling!!
- References:
- Connection Pooling!!
- From: parez
- Re: Connection Pooling!!
- From: David Browne
- Re: Connection Pooling!!
- From: Sahil Malik [MVP]
- Re: Connection Pooling!!
- From: Paul Clement
- Re: Connection Pooling!!
- From: David Browne
- Re: Connection Pooling!!
- From: Mark Ashton
- Connection Pooling!!
- Prev by Date: Re: Watcher for Datasets?
- Next by Date: Re: Inserting to Dbase 3 database via ADO .Net Problem
- Previous by thread: Re: Connection Pooling!!
- Next by thread: Re: Connection Pooling!!
- Index(es):
Relevant Pages
|