David,

The connections are number from 1 and up. So what you need to do is to check 
each number from one until a connection isn't available or you can set a 
minimum number of connections you want to check before assuming that there is 
no more.

The "problem" is that MapInfo doesn't change the connection number. I call it a 
problem here, but in general I'm glad that they keep the number.
The problem here is that you can have 3 connections open, but the first 
connection number can be 5, if you have closed the 4 first connections. 


'****************************************************************************************************
Include "MapBasic.def"

Type T_CONNECTION_INFO
        szDriverName    As String
        szDatabaseName  As String
        szSQLUserName   As String
        szDataSourceName        As String
        szQuoteChar             As String
End Type

Declare Sub Main
Declare Function GetConnectionInfo(ByVal nConn As Integer, tcInfo As 
T_CONNECTION_INFO) AS Logical

Sub Main

Dim     nConn As Integer,
        tcInfo As T_CONNECTION_INFO

        For nConn = 1 To 2000
                If GetConnectionInfo(nConn, tcInfo) Then
                        Print "Driver: " & tcInfo.szDriverName
                                & " Database: " & tcInfo.szDatabaseName
                                & " Username: " & tcInfo.szSQLUserName
                                & " Data Source: " & tcInfo.szDataSourceName
                                & " Quote Char: " & tcInfo.szQuoteChar
                Else
                        '**No more conections ?
                        If nConn > 10 Then
                                '**If ConnectionNumber is larger than 10, I 
guess there is no more connections ??
                                '**10 can be changed to any number
                                Exit For
                        End If
                End if
                tcInfo.szDriverName     = ""
                tcInfo.szDatabaseName   = ""
                tcInfo.szSQLUserName    = ""
                tcInfo.szDataSourceName = ""
                tcInfo.szQuoteChar      = ""
        Next
End Sub

Function GetConnectionInfo(ByVal nConn As Integer, tcInfo As T_CONNECTION_INFO) 
AS Logical

OnError GoTo NoConnection

GetConnectionInfo = FALSE

        tcInfo.szDriverName     = Server_ConnectInfo (nConn, 
SRV_CONNECT_INFO_DRIVER_NAME)
        tcInfo.szDatabaseName   = Server_ConnectInfo (nConn, 
SRV_CONNECT_INFO_DB_NAME)
        tcInfo.szSQLUserName    = Server_ConnectInfo (nConn, 
SRV_CONNECT_INFO_SQL_USER_ID)
        tcInfo.szDataSourceName = Server_ConnectInfo (nConn, 
SRV_CONNECT_INFO_DS_NAME)
        tcInfo.szQuoteChar      = Server_ConnectInfo (nConn, 
SRV_CONNECT_INFO_QUOTE_CHAR)

        GetConnectionInfo = TRUE

        Exit Function
'--------------------
NoConnection:
        Print "Connection doesn't exist: " & nConn
                        & " Error: " & Error$()

End Function
'****************************************************************************************************

HTH,

Peter Horsbøll Møller
GIS Developer, MTM
Geographical Information & IT
 
COWI A/S
Odensevej 95
DK-5260 Odense S.
Denmark
 
Tel     +45 6311 4900
Direct  +45 6311 4908
Mob     +45 5156 1045
Fax     +45 6311 4949
E-mail  [EMAIL PROTECTED]
http://www.cowi.dk/gis

COWI har fået ny hjemmeside. Ydelserne GIS og IT, kort, kortlægning, 3D 
visualisering og arealforvaltning ligger under SAMFUND. Se mere her : 
www.cowi.dk

COWI has changed its homepage. Our services within cadastre and 
landadministration, geodataproducts, mapping and GIS can be seen under SOCIETY. 
See our services here: www.cowi.com


-----Original Message-----
From: David Jerrard [mailto:[EMAIL PROTECTED] 
Sent: Friday, October 07, 2005 4:08 AM
To: [email protected]
Subject: MI-L Server_ConnectInfo - What are my current connections?


Hi all,

I am writing MapBasic code to run in an environment where more than one Oracle 
Spatial database connection may be current at any time.  I would like to 
"interrogate" those connections to see if a suitable connection already exists 
before prompting the user to login (... again, and again, and again...).

The Server_ConnectInfo() function looks *ALMOST* like what I'm after.  Once I 
have a connection handle, I can find out what database it connects to, what 
username was used to login, etc.

What I can't find is anything to tell me:
 (a) How many existing connections exist, and
 (b) What connection handles (integers) they use

Come to think of it, another nice-to-have would be a "test connection" option, 
as some of these connections go "stale" if left overnight when a database 
backup takes place.  But that's another story...

Any assistance finding either the existing MapBasic functionality to do this, 
or a cute workaround in its absence, would be greatly appreciated.

Cheers,
David Jerrard



---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com | To 
unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 18166



Reply via email to