How to resolve Error#6023 Query not prepared

Studio, Ensemble

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
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()


  • 0
  • 0
  • 154
  • 4
  • 2


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


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:


or (depenting on your target DBMS):


or is it the same error?