Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Revisiting the global connection object
Message
De
30/04/2007 06:08:11
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
29/04/2007 12:38:25
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01220816
Message ID:
01221030
Vues:
18
>>Can't you use a static array to keep them.
>
>Could you elaborte more on the static array approach?
>
>I have an array presently to hold all different connection strings but I would say it is not a static array. But, the prime goal here would be to have an identifier so I would know that if the current connection used is 47, than the next hit should use connection 48 and so on. So, I need some kind of mechanism that would apply a lock at the hit level just to make sure that two simultaneous connection do not use the same connection.

You could keep a static array of a type. The type itself could have 2 properties (connection and inUse flag). Instead of strictly checking for item 48 when 47 used you could then check any with inUse flag false. Or if you want to work orderly you could use Queue/Stack classes. ie:(pseudo code)
public static myCons
{
  Queue _connQueue;
  public myCons()
  {
    this._connQueue = new Queue(100);
    for (int i = 0; i < 100; i++)
    {
     this._connQueue.Enqueue( MyNewCon() );
    }
  }
  public static OleDbConnection GetConnectionFromQueue()
  {
    return this._connQueue.Dequeue();
  }
  public static ReturnConnectionToQueue(OleDbConnection con)
  {
    this._connQueue.Enqueue(con);
  }
}

// some connection requiring code
OleDbConnection myCon = MyCons.GetConnectionFromQueue();
myCon.Open(); 
// do something with connection
myCon.Close();
MyCons.ReturnConnectionToQueue(myCon);
The idea is to create a queue of your 100 connections initially. When needed get next from the queue, do whatever and return to the last position in queue line.

PS: With queue approach, you might as well create no connections intially. If connections in queue is 0 create one and return it. That would be more flexible IMHO.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform