Re: Connection Pooling!!



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


.



Relevant Pages

  • Re: ADO connections question
    ... Function CreateADOObjects(ConnectionString as string) ... you'll see this error if the connection has not been ... I have a specific login form that calls the dbLogin function as shown ... Dim strCriteria As String ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Nochmals Treeview
    ... private void button1_Click(object sender, System.EventArgs e) { ... private void TabelleAnlegen(string strDBPfad, string strDB, string strTabellenName){ ... OleDbConnection connection = new OleDbConnection; ... OleDbCommand command = new OleDbCommand; ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • RE: Error using Login control ASP.NET App_Data Folder
    ... the UserInstance type of connection string is for SQLEXPRESS only and is ... Server Management Studio and use a standard connection ... An error has occurred while establishing a connection to the server. ... SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: ExecuteReader requires an open and available Connection.
    ... you have ALL your users sharing one connection. ... Public Shared Function GetServerAs String ... Dim theServer As String ...
    (microsoft.public.dotnet.framework.aspnet)
  • Change Connection String during runtime
    ... connection is stored in the app.config file. ... connection string without exiting the application. ... Dim newConnection As String ... Private Sub RecordDatabase_Enter(ByVal sender As Object, ...
    (microsoft.public.dotnet.languages.vb)