Skip to main content

Accessing the Internal Database at Runtime

Certain (special) scenarios may require you to gain access and execute custom query against the Internal Database during runtime. The C# script below demonstrates how to achieve this via the Scripting Interface.

CODE
using System;
using System.Linq;
using System.Data;
using Sequentum.ContentGrabber.Internal;
using Sequentum.ContentGrabber.Api;
using Sequentum.ContentGrabber.Commands;
public class Script
{ 
public static CustomScriptReturn CustomScript(CustomScriptArguments args)
{
     // Acquire connection to the (internal) database
     IConnection connection = args.DatabaseConnection;
     try
     {
         connection.OpenDatabase();
 
         // BUILD TABLE NAME FOR THE CURRENT CONTAINER
         string tableName = string.Format("{0} {1} {2}", args.IsDebug ? "SWSID" : "SWSIR", args.Agent.Name.GetValidFileName(), args.DataRow.ParentTable.TableName);
         // BUILD THE UPDATE COMMAND/QUERY
         ICommand command = connection.GetNewCommand();
         command.SetSql(string.Format("UPDATE [{0}] SET myColumn = @myColumn WHERE filter = @filter", tableName));
         command.AddParameterWithValue("myColumn", args.DataRow["myColumn"], CaptureDataType.ShortText);
         command.AddParameterWithValue("filter", args.DataRow["filter"], CaptureDataType.ShortText);
         command.ExecuteNonQuery(); 
   }
   catch (Exception ex)
   {
         // LOG ERROR
         args.WriteDebug(string.Format("Error executing table update. ", ex.Message), DebugMessageType.Error);
         throw ex;
   }
   finally
   {
         if (connection != null) connection.CloseDatabase();
   } 
   return CustomScriptReturn.Empty();
}
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.