1. Phyllip Hall
  2. PowerServer 2020 or older (Obsolete)
  3. Friday, 12 July 2019 23:53 PM UTC

Does anyone know why I might be receiving the following error when commit; is executed in embedded SQL in WebServer?

 

 

The code connects to the database and retrieves data properly.

 

Primary Code

transaction l_trans

if -1 = this.trigger event ue_connect(l_trans) then return -1

dw_1.SetTransObject(l_trans)

dw_1.retrieve()

commit;

destroy l_trans

 

 

Event: ue_connect 

string ls_error
string ls_datasource = 'test_postgres'

a_trans = create transaction

a_trans.AutoCommit = false

a_trans.DBMS = 'odb-pgs'
a_trans.DBParm = "CacheName='" + ls_datasource + "'"

// connect to db
CONNECT USING a_trans;

// --- Check for errors in database connection
if a_trans.SQLCode = 0 then
return 0
else
ls_error = 'Unable to connect to database:' + &
'~r~n' + '~r~n' + 'DBMS: ' + a_trans.dbms + &
'~r~n' + 'DBParm(DataSource): ' + a_trans.DBParm + &
'~r~n' + '~r~n' + 'Error Code: ' + string (a_trans.SQLDBCode) + &
'~r~n' + 'Error Message: ' + a_trans.SQLErrText

MessageBox('ue_connect', ls_error)
return -1
end if

 

Full Error Message:

Error 20010
Transaction is not connected.
For more help, please consult the Appeon user document.

Accepted Answer
Michael Kramer Accepted Answer Pending Moderation
  1. Saturday, 13 July 2019 00:39 AM UTC
  2. PowerServer 2020 or older (Obsolete)
  3. # Permalink

Hi Phyllip,

Statement = COMMIT;

is shorthand for statement = COMMIT USING SQLCA;

Since your application object auto-instantiates SQLCA that code is valid but no code has connected SQLCA to your database.

Your code creates a reference to DB connection in l_trans. Hence, what I expect you want is

Statement = COMMIT USING l_trans;

HTH /Michael

Comment
  1. Phyllip Hall
  2. Saturday, 13 July 2019 13:12 PM UTC
Hi Michael, thank you for the thorough explanation!
  1. Helpful
  1. Michael Kramer
  2. Saturday, 13 July 2019 14:04 PM UTC
You're welcome, Phyllip!

My personal coding style is to ALWAYS be explicit on "USING …;" even when it is "USING SQLCA;"

I don't want to shoot myself in the foot once more by A) modify data, B) check SQLCode, and C) COMMIT/ROLLBACK on different DB connections.
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.