How to resolve Error#6023 Query not prepared

Hi, please can you help me. I cant understand a thing on how to resolve this. I can run the query perfectly fine on SQL but when I run it in studio, it gives an error.

"0 "_$lb($lb(6023,,,,,,,,,$lb(,"Production",$lb("e^zSQLGWE
xecute+2^%Library.DynamicQueryGW.1^1","e^zExecute+14^%Library.ResultSet.1^1","e^
zIsRENAL+25^Production.FunctionSet.1^1","e^zS1+2^Production.ProcessMessageEMED.Thread1
.1^1","e^zSwitchState+90^Ens.BP.Thread.1^1","e^zOnRequest+8^Production.ProcessMessa
geEMED.1^1","e^zMessageHeaderHandler+19^IMP2HL7.ProcessMessageEMED.1^1","e^zMess
ageHeaderHandler+93^Ens.Actor.1^1","e^zOnTask+42^Ens.Host.1^1","e^zStart+62^Ens.
Job.1^2","d^StartEnsembleJob+6^|""%SYS""|STU^1","d^^^0"))))/* ERROR #6023: Query
 not Prepared. */

My code below:

set conn= ##class(%SQLGatewayConnection).%New()

set sc=conn.Connect("Production","username","password")

set sql = query here

set res =##class(%ResultSet).%New("%DynamicQueryGW:SQLGW")

set sc=res.Prepare(sql,,conn)

set sc=res.Execute()

while res.Next()

{

s RET= res.GetData(1)

}

set sc=res.Close()

set sc=conn.Disconnect()

q RET

  • 0
  • 0
  • 59
  • 4
  • 2

Answers

This is probably a simple syntax error.  Let's see the code you're using, from start to finish, setting up, preparing, then executing the query.  Perhaps the syntax is wrong on the preparation step.

Hi John, thank you for responding to my query. I have added a brief structure of my code in the question now. Would appreciate some help on this

sorry everyone, I was able to fix the issue. it was an issue with the password to the database. So sorry. 

thank you for the input. Would have been nice to have a clearer error message though... didnt show me anything. to indicate that the connection was an issue

Comments

Can you provide what you get from this command set sc=res.Prepare(sql,,conn)? The error should tell you why the query failed preparation.

The above error is what I get from the prepare statement. It works perfect in our test environment but on deploying to the LIVE server it gives this error. It is the same code copied over. Baffles me.

What status does this line return:

set sc=conn.Connect("Production","username","password") 

Can you execute a trivial statement such as:

SELECT 1

or (depenting on your target DBMS):

SELECT 1 FROM dual

or is it the same error?