• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3304
  • Last Modified:

Command text was not set for the command object

Error "Command text was not set for the command object" occurs in Set oRS = conn.Execute(strSQL) .  Please help.  thanks.            



<%
function conn(strSQL)
      'Create and open the database connection object
      Set conn = Server.CreateObject("ADODB.Connection")
      conn.Open application("connstr"),"user","password"
      
      startStmt = Mid(trim(strSQL),1,6)
      page_id = Request.QueryString("page")
      if page_id = "" then
            page_id = Request.QueryString("page_id")
      end if
      
            auditSQL = "INSERT INTO ......"
            auditSQL = replace(auditSQL,"''''","''")
            session("strSQL") = auditSQL
            Set oRS = conn.Execute(auditSQL)

      'Executing query
      session("strSQL") = strSQL
      Set oRS = conn.Execute(strSQL)
      Set conn = oRS

      Set oRS = Nothing
end function

%>
0
ewang1205
Asked:
ewang1205
  • 2
1 Solution
 
VAScottCommented:
where is session("strSQL") getting set?  sounds like strSQL is not getting set correctly.
try adding a write just before that line and see what (if any) SQL statement gets output, like this:

response.write(strSQL)
Set oRS = conn.Execute(strSQL)
0
 
kevp75Commented:
just for testing, you may want to do this as well.

response.write Application("connstr")

at the top of your code, just to make sure the connection string is being set in your global.asa file
0
 
Anthony PerkinsCommented:
An INSERT statement never returns a resultset.  You need to lose the Set oRS, as in:

<%
function conn(strSQL)
     'Create and open the database connection object
     Set conn = Server.CreateObject("ADODB.Connection")
     conn.Open application("connstr"),"user","password"
     
     startStmt = Mid(trim(strSQL),1,6)
     page_id = Request.QueryString("page")
     if page_id = "" then
          page_id = Request.QueryString("page_id")
     end if
     
     auditSQL = "INSERT INTO ......"
     auditSQL = replace(auditSQL,"''''","''")
     session("strSQL") = auditSQL
     conn.Execute auditSQL

     'Executing query
     session("strSQL") = strSQL
     conn.Execute strSQL
     conn.Close
     Set conn = Nothing

end function

%>
0
 
Anthony PerkinsCommented:
And of course, I am making the assumption that strSQL is not a SELECT statement.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now