Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Revisiting the global connection object
Message
De
08/05/2007 17:37:10
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
08/05/2007 13:23:23
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:
01223628
Vues:
11
>>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);
>>
>
>I tried to convert that to VB.NET. This is what I came up with:
>
>
>Imports System.Data
>Imports System.Data.Common
>Imports System.Data.OleDb
>Imports System.Data.SqlClient
>Imports System.Data.Odbc
>
>Namespace Framework
>
>    Public Class QueueConnection
>
>        Dim oQueue As Queue = New Queue
>
>        Public Function Initialize() As Boolean
>            Dim lnCounter As Integer = 0
>
>            oQueue = New Queue(100)
>
>            For lnCounter = 1 To 100
>                oQueue.Enqueue(MyNewCon())
>            Next
>
>            Return True
>        End Function
>
>        Public Function GetConnectionFromQueue() As OleDbConnection
>            Return oQueue.Dequeue()
>        End Function
>
>        Public Function ReturnConnectionToQueue(ByVal toConnection As OleDbConnection) As Boolean
>            oQueue.Enqueue(toConnection)
>            Return True
>        End Function
>
>    End Class
>
>End Namespace
>
>
>Is that how you saw it?

Probably. I think static is shared in VB. I'd create that as static.
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
Répondre
Fil
Voir

Click here to load this message in the networking platform