Page 1 of 1
Problem while exiting from VB , using VB API's
Posted: Wed Jul 01, 2009 12:28 pm
by zameelarif
Hi All
I am connecting to a TM1 server using VB6.0 , and even performed action of creating a new user.
In my VB application , i have a login and exit buttong, I am using the login button to login to the TM1 server by providing the necessary information, and i have a second button to exit from the application.
As per the APi guide i need to do the following while exiting the application
' call TM1SystemServerDisconnect, TM1SystemClose, then TM1APIFinalize.
''
In addition, best practice dictates that all TM1 Value Pools used
' in your program be destroyed by calling TM1ValPoolDestroy().
'
vResult = TM1SystemServerDisconnect(pPoolHandle, vServerName)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Add Code to delete all TM1 Value Pools here.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TM1ValPoolDestroy (pPoolHandle)
TM1SystemClose hUser
TM1APIFinalize
Firstly , How to reference the pool and other handles created while making the connection , bcoz it is also needed for closing the connection , i tried with global variables , not sure whether it is working bcoz as soon as i press the exit button , i am getting VB debug error and the whole application(including VB) is closed.
Can anyone advise/help me how can i check any existing connection and if any exit form the application cleanly.
Re: Problem while exiting from VB , using TM1 .NET AP
Posted: Wed Jul 01, 2009 1:10 pm
by Mike Cowie
Hi,
First, if you are calling the functions you listed, that is not the .NET API (which you reference in your subject) - you're using the C/VB API. Just want to make sure you aren't using a blend of both APIs somewhere...
Have you done some debugging in VB to see where the application is failing - for example, does it actually get through all those lines of code you listed or does it fail at a certain point? You may need to step through your code to see this - otherwise you're just guessing.
To your question about referencing the pool and other handles created by your application, you need to keep track of that in your program. The only things you really need to keep track of and clean up are:
* Any private, unregistered objects you've created (using functions like TM1ObjectDuplicate)
* Value Pools you've created
Your program won't crash if you forget to clean these up, but it will often result in memory leaks on the TM1 Server if you don't clean them up.
Again, I would spend some time going through your code in the VB debugger to see specifically where your code is failing.
Regards,
Mike
Re: Problem while exiting from VB , using TM1 VB API's
Posted: Thu Jul 02, 2009 10:30 am
by zameelarif
Thanks for correcting me , Mike. I am using VB API's not .net
and here is the code which i have written to reset a pwd for existing TM1 user, but some how it is not working , can any one let me know am i doing anything wrong or missing any part of it.
Private Sub Login_cmd_Click()
Dim hUser As Long
Dim hPool As Long
Dim hServer As Long
Dim vServerName As Long
Dim vClientName As Long
Dim vClientPassword As Long
Dim ServerName As String * 75
Dim ClientName As String * 75
Dim ClientPassword As String * 75
Dim ErrorString As String * 75
Dim CompName As String
Dim vresult As Long
Dim vStringLength As Long
Dim ErrorString As String * 75
Dim msg_ErrorString As String * 75
'Check for null entries
If txt_User_id.Text <> "" Then
' initialize the API
tm1api.TM1APIInitialize
hUser = TM1SystemOpen()
'Get the computer name
CompName = Environ("COMPUTERNAME")
'CompName = Trim(cbo_server.List(cbo_server.ListIndex))
'Set the Admin Host Server Name
TM1SystemAdminHostSet hUser, Trim(CompName)
' Create a Pool Handle
hPool = TM1ValPoolCreate(hUser)
' Establish Login information
ServerName = Trim(cbo_app.List(cbo_app.ListIndex))
ClientName = "TM1_PWD_ADMIN"
ClientPassword = "Welcome2"
' Variables to connect to the TM1 server
vServerName = TM1ValString(hPool, Trim(ServerName), 0)
vClientName = TM1ValString(hPool, Trim(ClientName), 0)
vClientPassword = TM1ValString(hPool, Trim(ClientPassword), 0)
'Log in to a TM1 Server
hServer = TM1SystemServerConnect(hPool, vServerName, vClientName, vClientPassword)
' Check to see if we were successful...
If (TM1ValType(hUser, hServer) = TM1ValTypeObject()) Then
MsgBox "You Logged in Successfully"
'Reset the pwd for the user
Dim hClient As Long
Dim pwd_result As Long
Dim pwd_send As Long
Dim hPassword As Long
Dim vClient As Long
vClient = TM1ValString(hPool, Trim(txt_User_id), 0)
hClient = TM1ValString(hPool, Trim(ClientName), 0)
hPassword = TM1ValString(hPool, Trim("Welcome2TM1"), 0)
pwd_send = TM1ClientPasswordAssign(hPool, hClient, hPassword)
pwd_result = TM1ValBoolGet(hUser, pwd_send)
'Closing the TM1 Connection
Dim Server_dis As Long
Dim Dis_result As Long
Dim v_errorcode As Long
Dim v_errorstring As Long
'v_errorcode = TM1ValErrorCode(hUser, pwd_result)
'v_result = TM1ValStringGet_VB(hUser, v_errorcode, v_errorstring, 75)
Server_dis = TM1SystemServerDisconnect(hPool, vServerName)
Dis_result = TM1ValBoolGet(hUser, Server_dis)
' If Dis_result = 1 Then
' MsgBox "User Disconnected"
' Else
' MsgBox "User not Disconnected"
' End If
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Add Code to delete all TM1 Value Pools here.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
TM1ValPoolDestroy (hPool)
TM1SystemClose hUser
TM1APIFinalize
Else
MsgBox "Log in UnSuccessfull"
'If (TM1ValType(hUser, hServer) = TM1ValTypeError()) Then
MsgBox "The server handle contains an error code."
'End If
End If
Else
MsgBox "Userid to reset pwd is empty"
End If
End Sub
PS :- the return value for pwd_result i am getting is 91 , where as in the manual it says it should be 1 when sucessful.
Any help is much appreciated.
Re: Problem while exiting from VB , using VB API's
Posted: Fri Jul 03, 2009 2:51 pm
by Mike Cowie
Hi Zameel,
I see a problem with your code. You are calling TM1ClientPasswordAssign with a handle to the *name* of the client - you need to pass a handle the the client OBJECT. I haven't had a chance to look in much more detail, but that's at least one reason why you're getting a 91 (which means it returned an error handle, not a Bool variable). You have to be very careful to check the type of what was returned from any function like this that you call using TM1ValType - if you pass an error handle to a function that expects something else, you can cause your app to crash.
Have to run for now, but wanted to let you know that there is definitely something missing in your code.
Regards,
Mike
Re: Problem while exiting from VB , using VB API's
Posted: Mon Jul 06, 2009 11:59 am
by Andy Key
If you change your assignment of
Code: Select all
hClient = TM1ValString(hPool, Trim(ClientName), 0)
to
Code: Select all
hClient = TM1ObjectListHandleByNameGet(hPool, hServer, TM1ServerClients(), vClient)
this will give you the handle to the client object that you can then pass to TM1ClientPasswordAssign.
Re: Problem while exiting from VB , using VB API's
Posted: Mon Jul 06, 2009 12:39 pm
by Mike Cowie
Andy Key wrote:If you change your assignment of
Code: Select all
hClient = TM1ValString(hPool, Trim(ClientName), 0)
to
Code: Select all
hClient = TM1ObjectListHandleByNameGet(hPool, hServer, TM1ServerClients(), vClient)
this will give you the handle to the client object that you can then pass to TM1ClientPasswordAssign.
Thanks, Andy - saved me having to open up the API docs to make sure I had the function name right (TM1ObjectListHandleByNameGet doesn't exactly roll off the tongue).
-Mike