Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Revisiting the global connection object
Message
From
08/05/2007 13:23:23
 
 
To
30/04/2007 06:08:11
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
Databases
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01220816
Message ID:
01223493
Views:
21
>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?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform