Recupera o número da conexão ativa com o DBAccess.
Sintaxe
Retorno
Nome | Tipo | Descrição |
---|
nHnd | numérico | Retorna o número da conexão ativa. |
Observações
- Caso náo haja conexão ativa, a funçáo retornará -1.
- Caso haja conexão ativa, nHnd será maior ou igual a 0, igual ao retorno da função TCLink.
- Essa funçáo é util em integrações de aplicações, identificando qual é a conexão ativa no momento.
Exemplos
#DEFINE CRLF Chr(13)+Chr(10)
user function getconn1()
Local cDB1 := "MSSQL/DATABASE1"
Local cSrv1 := "172.16.0.1"
Local nHnd1 := 0
Local cDB2 := "MSSQL/DATABASE2"
Local cSrv2 := "172.16.0.1"
Local nHnd2 := 0
Local cMsg := ""
// Show active connection handle
nHnd1 := TCGetConn()
if nHnd1 < 0
cMsg += "No active connection!" + CRLF
endif
// Connect to the first database
nHnd1 := TCLink( cDB1, cSrv1, 7890 )
If nHnd1 < 0
UserException( "Error connecting to " + cDB1 + " on " + cSrv1 )
Endif
cMsg += "Return from TCLink 1 = " + cValToChar( nHnd1 ) + CRLF
cMsg += "Return from TCGetConn = " + cValToChar( TCGetConn() ) + CRLF
// Connect to the second database
nHnd2 := TCLink( cDB2, cSrv2, 7890 )
If nHnd1 < 0
UserException( "Error connecting to " + cDB2 + " on " + cSrv2 )
Endif
cMsg += "Return from TCLink 2 = " + cValToChar( nHnd2 ) + CRLF
cMsg += "Return from TCGetConn = " + cValToChar( TCGetConn() ) + CRLF
// Change the connection to the first one
if TCSetConn( nHnd1 ) == .F.
UserException( "Could not change connection to " + cDB1 + " on " + cSrv1 )
endif
cMsg += "Active connection changed!" + CRLF
// Show active connection handle
cMsg += "Active connection = " + cValToChar( TCGetConn() ) + CRLF
TcUnlink( nHnd1 )
TcUnlink( nHnd2 )
if TCGetConn() < 0
cMsg += "No active connection!" + CRLF
endif
return MsgInfo( cMsg, "TCGetConn Example" )
Resultado do Exemplo

Abrangência
Disponível a partir da build 7.00.131227A com data de geração superior a 13/11/2015.
Veja também