Session not defined in a thread

rakgol_a

Member²
I think I'm doing something stupid; anyway I'm trying to create a session instance in a thread's constructor given in this code

m_oraSession = new TOracleSession(NULL);
m_oraSession->AutoCommit = true;
m_oraSession->LogonUsername = username;
m_oraSession->LogonPassword = userPassword;
m_oraSession->LogonDatabase = databaseName;
m_oraSession->LogOn();

I get "Session Undefined" error in the constructor of a thread where username, password and DB are parameters. What am I doing incorrect; to create a session instance in a thread?
 
Hi,

the following code functions without any problem within a TThread constructor:

SQLSession=new TOracleSession(NULL);
SQLSession->LogonUsername=GlobalIniFile.ReadString("DATABASE","USER","");
SQLSession->LogonPassword=GlobalIniFile.ReadString("DATABASE","PASSWORD","");
SQLSession->LogonDatabase=GlobalIniFile.ReadString("DATABASE","DBNAME","");
SQLSession->AutoCommit=false;
SQLSession->Connected=true;

Did you realy receive the error in the constructor or in the execute method ??

If it is in the constructor i would think that the string for the database is not correct.

If it is in the execute method there can be another reason. The execute method can start when the TThread constructor is finished. So its possible that your part of the constructor has not connected but the execute wants to use the invalid session. To solve this there are two solutions.
1: create the thread suspendet and active it when your constructor finishes.
2: create the session within the execute method

Hope this helps,

Lars
 
Thanx, the problem was that i've created
TOracleDataSet instanses with the session
before I connected. This is strange; but it works if u first connect before you create object that take session parameter.

thanx
 
Back
Top