CFF KB - Carrz-Fox-Fire Promotions Knowledge Base

CFF KB is all about 1 thing: The Sharing of Knowledge and the Power we gain from it.
  • Breadrumbs:
  • Microsoft OLE DB Provider for SQL Server error '80040e0c' - Command text was not set for the command object

  • CFF Knowledge Base - Share With Facebook CFF Knowledge Base - Share on Twitter CFF Knowledge Base - Share on Reddit CFF Knowledge Base - Share on Digg It CFF Knowledge Base - Share on Stumble Upon It CFF Knowledge Base - Share on Delicious
    Share With Friends (Updated 6-8-2010)
  • Article ID:
    6265
  • Date Created
    Tuesday, February 14, 2023
  • Last Updated
    Tuesday, February 14, 2023
  • This Article Has been Viewed
    872 times
  • Short Desc
    The error "Command text was not set for the command object" means that the Commandtext is not applied to the statement.
  • Details
    If we look at this Statement, we have a good source for our Commandtext.
    <%
    searchsql.commandtext="Select ColOne from TableOne where ColTwo=?"
    %>

    However, if we use another method in place of our Statement, like this.
    <%
    searchsql.commandtext=strSQL
    %>

    And if the Variable is not found or able to be read, then we will receive the error.
    "Command text was not set for the command object."
  • Recreate Issue
    In the below code, we are making different calls using QueryStrings to determine the Database call we need for each Query.
    Example

    <%

    If request.querystring="One" then
    strSQL = "Select ColOne from TableOne where ColTwo=?"
    elseif request.querystring="Two" then
    getSQL = "Select ColOne from TableTwo where ColTwo=?"
    end if

    %>


    The above IF THEN Statement is accurate in the way it works.
    If the QueryString equals ONE
    We give the user the database from that Query.
    However, in the ELSEIF Statement, the Variable is incorrectly spelled, so when the user request Two in the QueryString, they will receive the error.

     
    Microsoft OLE DB Provider for SQL Server error '80040e0c.'
    Command text was not set for the command object
    /Results.asp, line 133
  • Resolve Issue
    As demonstrated above, we have to ensure our Variables in all Queries are spelled correctly for our Database Queries to work.

    <%

    If request.querystring="One" then
    strSQL = "Select ColOne from TableOne where ColTwo=?"
    elseif request.querystring="Two" then
    strSQL = "Select ColOne from TableTwo where ColTwo=?"
    end if

    %>

    Now, with both Variables being the same name, strSQL.
    We can now run our database query to get the results requested.

    <%

    Set searchsql = Server.CreateObject("ADODB.Command")
    searchsql.ActiveConnection=siteconn
    searchsql.Prepared = true
    searchsql.commandtext=strSQL
    set rssearchsql = searchsql.execute

    %>