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 said:
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