Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Code 7009: Data is unavailable when using DTO

Status
Not open for further replies.

ianbtheog

Technical User
Nov 2, 2023
4
0
1
GB
Hello,

I am trying to programmatically close an SQL session.

For more context: I am using Pervasive 13.31.014.

I have also tried to run on the server and my workstation, same outcome.

I am using Python and pywin32 and I have been able to get to a point where I think it should be working as I intend.

As documented here:
Once I have a DtoSqlClient object, disconnecting the session should be as simple as calling the Disconnect method, right? The problem I am having is that I get a 7009 code returned back whenever I call Disconnect. Wherever I look code 7009 doesn't seem to have much more information on it other than 'Data is unavailable'

Has anyone ever encountered this error before, got any more ideas as to what causes the error to occur.

Code:
import win32com.client


session = win32com.client.Dispatch("DTO.DtoSession.2")
session.Connect(my_server_name, username, password)

monitor = session.Monitor

#get sql clients
sql_clients = monitor.SqlClients

list_of_sql_clients = list(sql_clients)

#attempt to disconnect a sqlclient just for example - normally within a loop
return_code = list_of_sql_clients[0].Disconnect()

if return_code != 0:
[indent]print(f"Error code: {return_code}, {session.Error(return_code)}")[/indent]

The return code would be
Code:
Error code: 7009, Data is unavailable

This is not the exact code (it may not even be correct python code) but is intended to give a general overview of the approach taken.




In the meantime, if I figure this out I'll update this post later.

Many Thanks
Ian
 
Because you aren't posting your code, I have a couple of questions:
1. Are you checking the result of the Connect?
2. Are you checking the count of SqlClients?
3. Before you Disconnect the SqlClient, are you checking that it's a valid session?
4. Have you tried the VBScript example in the docs ( Does it work? That would help identify if it's something in Python or the engine?
5. Have you tried using Zen v15.20? V13 ended support in Dec 2022.

Mirtheil
 
Hello Mirtheil,

Thank you for responding, in response to your questions.

1) Here is some actual code, I do check the result of connect, if it is non-zero I exit the program and print the return code and error message.

Code:
my_connection = PervasiveSession()
result = my_connection.connect(os.environ["server"], os.environ["username"].strip(), os.environ["password"].strip())

if result != 0:
    print(f"Error disconnecting to Pervasive Database, the return code was {result}, the error description was \"{my_connection.error(result)}\"")
    sys.exit()


Code:
class PervasiveSession:
    '''
        A convenience wrapper for DTOSession object, for Python.
    
    '''

    def __init__(self) -> None:
        self.com_object = win32com.client.Dispatch("DTO.DtoSession.2")


    def connect(self, servername:str, username:str, password:str)->int:
        '''
            Connects to the DTO Pervasive Session object.

            Non-zero return codes indicate an error condition that should be handled by the programmer.
        
        '''
        
        return_code:int = self.com_object.connect(servername, username, password)

        return return_code

2.) I don't explicitly check the count as I have to iterate over the clients anyway which is done using a for in loop.

3.) I am not, please could you suggest how one might go about doing this.

4.) It's something to do with the Python!, I have just taken your advice and run the example VB script with some modifications to call Disconnect conditionally and the sessions are disconnected without issue.

5.) I will contact our ERP vendor about the database version as it's included as it's provided as part of their software product.

At least I have something to work with now. It's strange because everything else does work such as getting all of the information about each session, just not Disconnect.

Thank you for your help.

I will post an update if I figure out what I've done wrong to maybe help the admittedly small population of users that want to do something like this using Python.

Thanks
Ian
 
3.) I am not, please could you suggest how one might go about doing this.
This suggestion is more for debugging but I would suggest checking one of the properties of the SqlClient. Maybe the UserName or Status or IP.

You're right, not too many are using Python. I've used VB, C#, Delphi, and C / C++ with the DTO or DTI interfaces. I'm not as familiar with Python but it seems that you've got a good start. Good luck

Mirtheil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top