Задача: Нужно два раза в год у определенных 1200 объктов из 2500 объктов менять  HI.limit и HIHI.limit. Первый раз выставлено вручную. Нужно сохранить уставки  текущего периода и залить уставки предыдущего периода.
Пример: Скрипты для сохранения скопированы из руководства стр.21 (Example Scripts) - асинхронный скрипт и асинхронный запрос. Для простоты SQL таблица для сохранения - пустая и у нее 3 поля(tag,hi,hihi). Вставка в SQL таблицу осуществляется одной командой Command.SaveChangesAsync() . 
Алгоритм: читаю таблицу и если в ней 0 строк, перебирая нужные объекты добавляю строку. Закончив перебор сбрасываю в SQL таблицу.   
- Код: Выделить всё
 [color=#FF0000]Query Script Code[/color]
DIM Connection as aaDBClient.aaDBConnection;
DIM Command as aaDBClient.aaDBCommand;
'Create a connection object with the connection string.
LogMessage("Creating connection");
Connection = aaDBAccess.CreateConnection("Data Source=xxxxx;Initial Catalog=wond;User Id=yyyy;Password=yyyxxx");
'Create a command object, with a SQL statement.
LogMessage("Creating a command object");
Command = Connection.CreateCommand("Select * from wondSqlTest", aaDBCommandType.SqlStatement, true);
'Everything is ready, let's execute the command async.
LogMessage("Executing command async");
DIM ResultCode as integer;
ResultCode = Command.ExecuteAsync();
if ResultCode <> 0 then
'Failed to start async execution, report the reason.
LogMessage("Got error " + ResultCode + " executing command async");
else
'Execution started, identify the command by ID, for use later.
LogMessage("Command async execution started successfully");
me.CommandID = Command.GetID();
LogMessage("me.CommandID?"+me.CommandID+" successfully");
'Allow the Process script to run.
me.InsertProcessCommand = true;
endif;
'Reset for next time
me.InsertCommand = false;
[color=#BF0000]Process Script Code[/color]
dim xHiLimit as indirect;
dim xHiHiLimit as indirect;
dim s as string;
dim tagnames as string;
dim i as integer;
dim worktag as indirect;
dim strElement as string;
dim strname as string;
DIM Command as aaDBClient.aaDBCommand;
'Retrieve the command object using its ID.
Command = aaDBAccess.GetCommand(me.CommandID);
if Command <> null then
   'Poll for command complete
   if Command.ExecutionState <> aaDBCommandState.Queued then
       LogMessage("Command execution state is " + Command.ExecutionState);
      if Command.ExecutionState == aaDBCommandState.Completed then
         DIM Rows as integer;
         Rows = Command.RowCount;
         LogMessage("Row count returned from command is " + Rows);
         if Rows == 0 then
                     LogMessage("Start object selection" );
                     ‘ Перебор всех объектов 
                     for each strElement in MyEngine.Engine.Objects[]
                         ‘ Нужные объекты содержат в имени pk 
                         if StringInString( strElement, "pk",1, 0 ) > 0 then
                           strname=strElement+".__Attr_Name_List_1";
                           worktag.BindTo(strname);
                         ‘ Нужные объекты порождены от $pkv или $pkt
                           if StringInString( worktag, "$pkv",1, 0 ) > 0 
                              or StringInString( worktag, "$pkt",1, 0 ) > 0  then
                             ' LogMessage("Object is OK!!! - " + strElement);
                               s = strElement+".Temp.Hi.Limit"; xHiLimit.BindTo(s);
                            s = strElement+".Temp.HiHi.Limit"; xHiHiLimit.BindTo(s);
                               ‘ добавляю строку 
                               Command.Addrow();
                               ‘ заношу имя tag и лимиты 
                               Command.SetCurrentRowColumnByIndex(0,strElement);
                               Command.SetCurrentRowColumnByIndex(1,xHiLimit);
                               Command.SetCurrentRowColumnByIndex(2,xHiHiLimit);
                           endif;
                         endif;
                    next;
                    LogMessage("End object select" );
                    ‘ одной асинхронной командой записываю всю таблицу
                    ‘ следует помнить что, если больше 1000 – нужно изменить параметр в SQLData
                     ‘     
                   DIM ResultCode as integer;
                    ResultCode = Command.SaveChangesAsync();
                   if ResultCode <> 0 then
                      'Failed to start async execution, report the reason.
                       LogMessage("Got error " + ResultCode + " executing command async");
                  endif;   
               endif;
   'When done, dispose the command.
   Command.Dispose();
   'Reset for next time
   me.InsertProcessCommand = false;
   endif;
else
   LogMessage("Cannot find command " + me.CommandID);
   me.InsertProcessCommand = false;
endif;