Forum Discussion

mugheessiddiqui's avatar
mugheessiddiqui
Contributor
8 years ago
Solved

Read Blob object from DB and convert to System.Collection.Generic.List type of object.

I have scenario where database field stores a System.Collection.Generic.List of Double object. Now I want to read a BLOB object from database field and convert it to list of Array or any type collection in Test Complete. I have written following routine and getting null value when reading a field from record set. Can any body help how to read blob object?

 

function TestBlob()
{
  var serverName = "ServerName";
  var dbName = "databaseName";
  
  Conn = new ActiveXObject("ADODB.Connection");  
  Conn.ConnectionString = "Driver={SQL Server};Server=" + serverName + 
                          ";Database=" + dbName + ";Trusted_Connection=True;";
  Conn.Open();
  
  var adoCmd = new ActiveXObject("ADODB.Command");
    adoCmd.ActiveConnection = Conn;    
    adoCmd.CommandType = adCmdText;
    adoCmd.CommandText = "Select * from scan";
    var rs = adoCmd.Execute();
    
//Table Field "slices" is type of varbinary 
// and holds the Blob object of System.Collections.Generic.List of Doubles.
   
  rs.MoveFirst();
  var blob = rs.Fields("slices").Value; // Always returns null.
  
  //How can I get coverted Blob object to List of Array, I have tried to test following statement.
  //I have doubt that it will not work. 
  var objList = Aliases.appName.AppDomain("appUI.exe").dotNET.System_Collections_Generic.List_1.zctor_3(blob);

}
  • Rather than "Value", you might want to use the GetChunk method.  What you'll need to do is get the ActualSize of the field and then use GetChunk to retrieve it.  I've not tested this but it might look something like this:

     rs.MoveFirst();
    var blobSize = rs.Fields("slices").ActualSize;
      var blob = rs.Fields("slices").GetChunk(blobSize);

9 Replies