Using a script to check database server availability

This example uses a script action to check if the database server is online before running the database operation. In the first step the script creates a field called is_database_server_online. If it is online the value of this field is set to “yes”, otherwise it is set as “no”. It then uses a conditional run action that depending on the value of the field is_database_server it calls the action Insert on primary database server or calls Insert on backup database server.  

example_33_leftpanel Download this example

using System;
using System.Text;
using System.IO;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Collections.Specialized;
using EmailParserBackend.ScriptingInterface;

public class MyAction : ScriptBasedProcess
	public override bool Run(MailMessage email, NameValueCollection fields)
        // Check if the database server is online
        string database_server_ip_address = "";
        Ping pingSender = new Ping();
        PingReply reply = pingSender.Send(database_server_ip_address);
        if (reply.Status == IPStatus.Success)
            fields.Add("is_online_db_server", "yes");
            fields.Add("is_online_db_server", "no");
        return (true);
The example shown on the right produces the following output: example_33_output