Forum Discussion

jasmeenkaur27's avatar
jasmeenkaur27
Contributor
7 years ago

Getting unspecified error

Hi,

 

I created the below function and got an error :

 

Provider

Unspecified Error

 

Error occurs at the highlighted line.

 

function fn_getDBData(strConnectionString, strQuery)

{

var objCon, objRS, strData;

strData = "";

objCon = Sys.OleObject("ADODB.Connection");

 

objCon.Open(strConnectionString);

if(objCon.State==1)

{

objRS = Sys.OleObject("ADODB.RecordSet");

Log.Message("Executing Query: "+strQuery);

 

objRS.Open(strQuery,objCon,3);

while(!objRS.EOF)

{

for(i=0;i<objRS.Fields.Count;i++)

{

strData = strData + objRS.Fields.Item(i).Name + "=" + objRS.Fields.Item(i).Value + ";;"

}

strData = strData.substr(0,strData.length-2);

strData = strData + "||"

objRS.MoveNext();

}

strData = strData.substr(0,strData.length-2);

}

objRS.Close();

objCon.Close();

return strData;

} 

 

1 Reply

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Without knowledge of what your connection string is or your actual SQL query, not sure anyone can answer that question.  The "unspecified error" usually means that an exception was thrown at the ADO object level which is not exposed directly by TestComplete.

     

    If your intention is to create a record set based upon an SQL query, rather than instantiating an ADO.RecordSet object, you can do that with an ADO.CreateADOCommand call and then run the Execute method on the command object.  The result of the execute will return a RecordSet.  My suspicion of what's causing your error is that you are saying to "Open" the record set using a command object that is already "open"... so the actual error may be something like "connection already open".  

     

    TestComplete documentation has several examples of how to use the ADO objects to generate recordsets for interation.  Here's one.

    https://support.smartbear.com/testcomplete/docs/testing-with/advanced/working-with-external-data-sources/databases/using-ado-and-bde-objects/ado-createadocommand.html