Getting number of DB-connections from TD

Discussion forum about all things SqlBase or SqlTalk
AlexR
Germany
Posts: 8
Joined: 14 Jun 2018, 13:03
Location: Berlin, Germany

Getting number of DB-connections from TD

Post by AlexR » 17 Oct 2023, 10:57

Hi @all,

although there are a few topics in the forum, I have unfortunately found nothing useable for us (or am unable to understand?).

Is there a way to get the number of currently active database connections (in the way SQLBase counts its licenses) directly from our TD-application (currently we're using 7.4)?

I found something about "sqlgsi()", but don't understand how to implement - if it would be the right way at all to get the desired informations.

Thanks very much in advance
Alexander

renatx
Russia
Posts: 10
Joined: 12 Dec 2018, 07:39
Location: Moscow

Re: Getting number of DB-connections from TD

Post by renatx » 18 Oct 2023, 10:10

this is an example of determining the number of active users on the server (I'm sorry that I can't arrange it as an attachment)

head 3 + Function: GetServerProcesses
.head 4 - Description:
.head 4 + Returns
.head 5 - Number:
.head 4 + Parameters
.head 5 - String: sServerName
.head 5 - String: sServerPassword
.head 4 - Static Variables
.head 4 + Local variables
.head 5 - Number: nPop
.head 5 - Number: nRet
.head 5 - Number: nErr
.head 5 - Number: hServer
.head 5 - Number: nMaxLength
.head 5 - Long String: sInfo
.head 5 - Long String: sBuffer
.head 5 - Number: nLength
.head 5 - Number: nOffset
.head 5 - String: sC
.head 5 - String: sC0
.head 5 - String: sClient
.head 5 - String: sTime
.head 5 - Number: nCursor
.head 5 - String: sCursor
.head 5 - Number: nI
.head 5 - String: sDB
.head 5 - Number: nProcess
.head 5 - Number: nP
.head 5 - Number: naP[*]
.head 4 + Actions
.head 5 - Set nPop = 0
.head 5 + While nPop < 5
.head 6 - Set nPop = nPop + 1
.head 6 - Set nErr = sqlcsv( hServer, sServerName, sServerPassword )
.head 6 + If nErr != 0
.head 7 - If nErr = 3804 AND nPop < 5
.head 7 + Else
.head 8 - Return -nErr
.head 6 + Else
.head 7 - Break
.head 5 - Set nMaxLength = 100000
.head 5 - Call SalStrSetBufferLength( sBuffer, nMaxLength )
.head 5 - Call SalStrSetBufferLength( sInfo, nMaxLength )
.head 5 - Set nRet = sqlgsi( hServer, 0x02 | 0x8000, sBuffer, nMaxLength, nLength )
.head 5 - Call sqldsv( hServer )
.head 5 - Set sInfo = sBuffer
.head 5 - Set nOffset = 0
.head 5 + If nRet != 0 ! ошибка
.head 6 - Return - nRet
.head 5 + While nOffset < nLength
.head 6 - Set sC = SalNumberToChar( CStructGetByte( sInfo, nOffset ) )
.head 6 - Set sC0 = SalNumberToChar( CStructGetByte( sInfo, nOffset + 1 ) )
.head 6 + If sC = 'S' AND sC0 = 'Q' ! похоже на SQLBase
.head 7 - Call SalStrSetBufferLength( sClient, 8 )
.head 7 - Call CStructGetString( sInfo, nOffset, 8, sClient )
.head 7 + If sClient = 'SQLBase'
.head 8 - ! Set nOffset = nOffset + 112
.head 8 - Break
.head 7 + Else
.head 8 - Set nOffset = nOffset + 1
.head 6 + Else
.head 7 - Set nOffset = nOffset + 1
.head 5 - !
.head 5 + While nOffset < nLength
.head 6 - Call SalStrSetBufferLength( sClient, 14 )
.head 6 - Call CStructGetString( sInfo, nOffset, 13, sClient )
.head 6 + If sClient = ''
.head 7 - Break
.head 6 - Else If sClient = 'SQLBase'
.head 6 + Else
.head 7 - Set nCursor = CStructGetInt( sInfo, nOffset - 2 )
.head 7 - Call SalStrSetBufferLength( sDB, 18 )
.head 7 - Call CStructGetString( sInfo, nOffset - 38, 17, sDB )
.head 7 - Call SalStrSetBufferLength( sCursor, 3 )
.head 7 - Call CStructGetString( sInfo, nOffset-60, 3, sCursor )
.head 7 - Set nProcess = CStructGetByte( sInfo, nOffset - 61 )
.head 7 + If nProcess != 0
.head 8 + If VisArrayFindNumber( naP, nProcess ) < 0
.head 9 - Set naP[ nP ] = nProcess
.head 9 - Set nP = nP + 1
.head 6 - Set sClient = sClient
.head 6 - Set nOffset = nOffset + 112
.head 5 - Return nP

AlexR
Germany
Posts: 8
Joined: 14 Jun 2018, 13:03
Location: Berlin, Germany

Re: Getting number of DB-connections from TD

Post by AlexR » 23 Oct 2023, 10:24

Hi renatx,

thank you for your exmaple. I've tried this but the result is not exactly what I wanted.
Although it looks like, it doesn't give the number of unique users, but of all database processes.
In fact, nProcess is not unique per Client in the way, SQLBase counts it's users.

Any other suggestions?

Thanks very much in advance for any idea :)
Alexander

FRBhote
India
Posts: 2206
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: Getting number of DB-connections from TD

Post by FRBhote » 23 Oct 2023, 11:54

Check out dbconnects in https://samples.tdcommunity.net/

User avatar
Steve Leighton
Site Admin
Site Admin
New Zealand
Posts: 338
Joined: 05 Mar 2017, 20:57
Location: Stroud, England <--> Tauranga, New Zealand

Re: Getting number of DB-connections from TD

Post by Steve Leighton » 23 Oct 2023, 23:43

.
As a side note - DBConnects in the sample vault is good - but doesn't work for later versions of SQLBase - as many of the offsets have changed.
It was written in 2003 so probably relates to v8 or thereabouts.
So just a hint that to get it working for later versions, you need to check your version of 'sqlsrv.h' and 'gsiext.h' to get the correct offsets.
Just saying :)
Greetings from New Zealand
Steve Leighton

Bankside Systems Ltd.
UK ♦ Australia ♦ New Zealand

www.banksidesystems.co.uk

Image

renatx
Russia
Posts: 10
Joined: 12 Dec 2018, 07:39
Location: Moscow

Re: Getting number of DB-connections from TD

Post by renatx » 24 Oct 2023, 09:11

hi all !

maybe that's what you meant (this example works on SqlBase 12) :

Code: Select all

Functional Class: clSrvClient
	Description:
	Derived From
	Class Variables
	Instance Variables
		Number: nProcess
		Number: nCursor
		String: sUser
		String: sClient
		String: sDatabase
	Functions

Code: Select all

Functional Class: clSrvClients
	Description:
	Derived From
	Class Variables
	Instance Variables
		Number: nCounts
		FunctionalVar: oClient[*]
			Class: clSrvClient
	Functions
		Function: Add
			Description:
			Returns
				Number:
			Parameters
				Number: nProcess
				Number: nCursor
				String: sUser
				String: sClient
				String: sDB
			Static Variables
			Local variables
			Actions
				Set oClient[nCounts].nProcess = nProcess
				Set oClient[nCounts].nCursor = nCursor
				Set oClient[nCounts].sUser = sUser
				Set oClient[nCounts].sClient = sClient
				Set oClient[nCounts].sDatabase = sDB
				Set nCounts = nCounts + 1
				Return nCounts
		Function: GetCount
			Description:
			Returns
				Number:
			Parameters
			Static Variables
			Local variables
			Actions
				Return nCounts
		Function: CountUniqueClients
			Description:
			Returns
				Number: nCount
			Parameters
			Static Variables
			Local variables
				Number: nI
				Number: nJ
				Number: nU
				String: saUniqueClients[*]
			Actions
				Set nI = 0
				While nI < nCounts
					Set nJ = VisArrayFindString( saUniqueClients, oClient[nI].sClient )
					If nJ < 0
						Set saUniqueClients[nU] = oClient[nI].sClient
						Set nU = nU + 1
					Set nI = nI + 1
				Return nU

Code: Select all

Function: fTest
	Description:
	Returns
	Parameters
	Static Variables
	Local variables
		FunctionalVar: oClients
			Class: clSrvClients
		Number: nCount
		Number: nUniqueClients
	Actions
		Call fGetServerInformation( 'SERVER', 'PW', oClients )
		Set nCount = oClients.GetCount()
		Set nUniqueClients = oClients.CountUniqueClients() ! maybe that's what you meant

Code: Select all

Function: fGetServerInformation
	Description:
	Returns
		Boolean:
	Parameters
		String: sServerName
		String: sServerPWD
		FunctionalVar: oClients
			Class: clSrvClients
	Static Variables
	Local variables
		Number: hBuffer
		Number: nBufferLength
		Number: nRet
		Number: hServer
		String: sBuffer
		Number: nBufferOffset
		String: sDatabase
		String: sUser
		String: sClient
		Number: nCursor
		Number: nProcess
		Number: nSize
	Actions
		Set nRet = sqlcsv( hServer , sServerName, sServerPWD )
		If nRet != 0
			Call SalMessageBox( 'Error ' || SalNumberToStrX( nRet, 0 ), 'Attention', MB_IconStop )
			Return FALSE
		Set nSize = 81920 ! for example
		Set hBuffer = CStructAllocFarMem( nSize )
		Set nRet = sqlgsi( hServer, 0x02 | 0x8000, hBuffer, nSize, nBufferLength )
		If nRet = 0
			Call SalStrSetBufferLength( sBuffer, nBufferLength )
			Call CStructCopyFromFarMem( hBuffer, sBuffer, nBufferLength )
			Set nBufferOffset = nBufferOffset + 12
			While nBufferOffset < nBufferLength
				Call SalStrSetBufferLength( sDatabase, 17 )
				Call SalStrSetBufferLength( sUser, 19 )
				Call SalStrSetBufferLength( sClient, 13 )
				Set nCursor = CStructGetByte( sBuffer, nBufferOffset + 76 )
				Set nProcess = CStructGetByte( sBuffer, nBufferOffset + 17 )
				Call CStructGetString( sBuffer, nBufferOffset + 40, 17, sDatabase )
				Call CStructGetString( sBuffer, nBufferOffset + 21, 19, sUser )
				Call CStructGetString( sBuffer, nBufferOffset + 78, 13, sClient )
				Call oClients.Add( nProcess, nCursor, sUser, sClient, sDatabase)
				Set nBufferOffset = nBufferOffset + 112
		Call sqldsv( hServer )
		Call CStructFreeFarMem( hBuffer )

AlexR
Germany
Posts: 8
Joined: 14 Jun 2018, 13:03
Location: Berlin, Germany

Re: Getting number of DB-connections from TD

Post by AlexR » 28 Oct 2023, 11:00

Dear FRBhote, Steve & renatx,

Thank you very much for your answers and suggestions.
First tries wasn't successful unfortunately, but I'll give it more time after my holidays :)

Alexander

EwaldP
Austria
Posts: 351
Joined: 07 Mar 2017, 08:00
Location: Austria

Re: Getting number of DB-connections from TD

Post by EwaldP » 13 Nov 2023, 06:56

As far as I remember opentext/Gupta provides no function to get the amount of users (in the way SQLBase counts). Especially if you have (like us) exe from different runtimes in use. We wrote a function that counts the login of the different users and programs to check the customer's license model (with all the resulting cons).

SqlBase counts:
Any exe from a given runtime per client --> 1 User

That means. If a user starts more than 1 exe compiled with the same runtime, SqlBase counts 1 user. If you start on the same client an exe compiled with a different runtime Sqlbase add 1 user. If you have a Sqlbase with 10 User, 8 users will be left.
Ewald P. Palmetshofer
EDV-Hausleitner GmbH
4020 Linz
www.edv-hausleitner.at

Return to “SqlBase General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 5 guests