working on it ...

Filters

Explore Public Snippets

Sort by

Found 2,261 snippets matching: procedure

    public by cghersi @ MailUp API DEV  206838  8  6  1

    MailUp REST API - How to subscribe to a particular list several contacts with the "Confirmed Optin" Procedure

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 two leg authentication. You can start digging into the MailUP API world by reading this content: http://help.mailup.com/display/mailupapi/REST+API An instance of MailUpClient class is able to manage one user at a time. A MailU
    public static void SubcribeRecipientsWithDoubleOptin(string clientID, string clientSecret, string username, string password)
    {
        // 1) Setup the MailUp Client:
        MailUpClient client = new MailUpClient(clientID, clientSecret);
        try
        {
            client.RetrieveAccessToken(username, password);
        }
        catch (MailUpException ex)
        {
            Console.WriteLine("Unable to access the service due to " + ex.Message);
            return;
        }
    
        // 2) Subscribe recipients:
        int idList = 1;
        List<ConsoleRecipientItem> recipients = new List<ConsoleRecipientItem>();
        ConsoleRecipientItem recipient1 = new ConsoleRecipientItem()
        {
            Email = "test1@mailup.com",
            Name = "First New Recipient" + DateTime.Now.ToFileTimeUtc(),
            MobileNumber = "3331234567",
            MobilePrefix = "39",
            Fields = new List<ConsoleRecipientDynamicFieldItem>()
            {
                new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name1_" + DateTime.Now.ToFileTimeUtc() },
                new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName1_" + DateTime.Now.ToFileTimeUtc() }
                //here you can add all the fields you want to add...
            }
        };
        ConsoleRecipientItem recipient2 = new ConsoleRecipientItem()
        {
            Email = "test2@mailup.com",
            Name = "Second New Recipient" + DateTime.Now.ToFileTimeUtc(),
            MobileNumber = "3337654321",
            MobilePrefix = "39",
            Fields = new List<ConsoleRecipientDynamicFieldItem>()
            {
                new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name2_" + DateTime.Now.ToFileTimeUtc() },
                new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName2_" + DateTime.Now.ToFileTimeUtc() }
                //here you can add all the fields you want to add...
            }
        };
        recipients.Add(recipient1);
        recipients.Add(recipient2);
        int subscriptionResult = 0;
        try
        {
            subscriptionResult = client.AddRecipientsToList(idList, recipients, true);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
        // 2.1) wait for the end of import task:
        if (subscriptionResult > 0)
        {
            Console.WriteLine("Recipients Import started; import ID:" + subscriptionResult);
    
            //optionally we can check the import status:
            bool completed = false;
            do
            {
                ConsoleImportStatus importStatus = client.CheckImportStatus(subscriptionResult);
                if (importStatus == null)
                {
                    Console.WriteLine("Cannot check the import status for import task #" + subscriptionResult);
                    return;
                }
                completed = importStatus.Completed;
            } while (!completed);
            Console.WriteLine("Recipients Added!");
        }
        else
        {
            Console.WriteLine("An error occurred while adding the recipients.");
            return;
        }
    
        // 3) Retrieve the sendingID of the confirmation email related to the previous task:
        int sendingID = -1;
        try
        {
            sendingID = client.GetSendingIDForImport(subscriptionResult);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot retrieve sending ID due to " + ex.Message);
            return;
        }
        if (sendingID <= 0)
        {
            Console.WriteLine("Cannot retrieve sending ID.");
            return;
        }
    
        // 4) Send the confirmation email:
        EmailSendingItem sendingResult = null;
        try
        {
            sendingResult = client.SendEmailMessage(sendingID);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot send email due to " + ex.Message);
            return;
        }
        if (sendingResult == null)
            Console.WriteLine("Cannot send confirmation email.");
        else
            Console.WriteLine("Confirmation email sent!");
    }
                

    public by cghersi @ MailUp API DEV  112999  11  5  0

    How to Retrieve your personal information with MailUp .NET SDK

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 two leg authentication. You can start digging into the MailUP API world by reading this content: http://help.mailup.com/display/mailupapi/REST+API An instance of MailUpClient class is able to manage one user at a time. A MailU
    public static void GetPersonalDataFields(string clientID, string clientSecret, string username, string password)
    {
        // 1) Setup the MailUp Client:
        MailUpClient client = new MailUpClient(clientID, clientSecret);
        try
        {
            client.RetrieveAccessToken(username, password);
        }
        catch (MailUpException ex)
        {
            Console.WriteLine("Unable to access the service due to " + ex.Message);
            return;
        }
    
        // 2) Prepare the input:
        //nothing to do here...
    
        // 3) Invoke the web method:
        CollectionOf<ConsoleDynamicFieldItem> result = null;
        try
        {
            result = client.GetPersonalDataFields();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Cannot perform the operation due to " + ex.Message);
            return;
        }
    
    
        if (result != null)
            Console.WriteLine("Personal Data Fields Retrieved: " + result.Count);
        else
            Console.WriteLine("Cannot retrieve Personal Data Fields.");
    }
    

    public by cghersi  2868  1  7  0

    Call Stored Procedure with OUT or INOUT parameters in MySQL

    This is how to call a stored procedure "MySP" with a parameter defined as INOUT directyl from SQL environment
    DELIMITER $$
    CREATE PROCEDURE MySP(
    	IN _Ip VARCHAR(20),
    	INOUT _Id INT
    )
    BEGIN
    	SELECT  Id INTO _Id 
    	FROM    `MyTable`
    	WHERE   Ip = _Ip ;
    END $$
    DELIMITER ;
    
    SET @a = 1;
    CALL MySP('192.168.2.3', @a);

    public by cghersi  2401  1  6  2

    C#: Read the output parameter of a stored procedure

    fetch the output parameter of the given SP and try to read it
    static public string ReadOutputParam(this SqlCommand sqlCmd, string outputParamName, string defaultValue = "")
    {
      object outputValue = defaultValue;
      if (!string.IsNullOrEmpty(outputParamName))
        outputValue = sqlCmd.Parameters[outputParamName].Value;
    
      if ((outputValue == null) || (outputValue.Equals(DBNull.Value)))
        return defaultValue;
      else
        return outputValue.ToString();
    }
    

    public by lbottaro  2923  0  7  1

    Stored Procedure to solve error about Agent XPs in SQL Server on Maintenance Plan

    This is how to solve the error in Microsoft SQL Server Management Studio, when trying to create a Maintenance Plan. The error you get is the following. Error Message: ‘Agent XPs’ component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘Agent XPs’ by using sp_configure. For mo
    sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'Agent XPs', 1;
    GO
    RECONFIGURE
    GO            

    public by cghersi  3097  1  6  0

    Safe creation of Stored Procedure for MS SQL Server 2012

    The following example of Stored Procedure can be use as a template for the creation of every procedure that needs a transaction
    CREATE PROCEDURE [dbo].[TblName_ProcName]
    	@Param1 nvarchar(50)
    AS
    BEGIN
    	SET NOCOUNT ON;
    	SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
    	SET XACT_ABORT ON;
    
    	DECLARE @error int = 0;
    
    	BEGIN TRAN
    
    		-- do stuff; for each SQL instruction add the following statement to 
    		-- check the occurrence of an error: 
    		SET @error = @error + @@ERROR
    	
    	IF @error = 0
    		BEGIN
    			COMMIT;
    			RETURN 0;
    		END
    	ROLLBACK
    	RETURN -1;
    	
    END
    GO

    public by cghersi @ MailUp API DEV  1580  16  6  0

    MailUp REST API - How to subscribe a single contact with the "Confirmed Optin" Procedure

    This snippet takes advantage of the MailUp .NET SDK to setup the secure communication towards the server through OAuth2 two leg authentication. You can start digging into the MailUP API world by reading this content: http://help.mailup.com/display/mailupapi/REST+API An instance of MailUpClient class is able to manage one user at a time. A MailU
    public static void SubscribeContactWithCOI(string clientID, string clientSecret, string username, string password)
    {
      // 1) Setup the MailUp Client:
      MailUpClient client = new MailUpClient(clientID, clientSecret);
      try
      {
        client.RetrieveAccessToken(username, password);
      }
      catch (MailUpException ex)
      {
        Console.WriteLine("Unable to access the service due to " + ex.Message);
        return;
      }
    
      // 2) Prepare the input:
      int idList = 1;
      ConsoleRecipientItem recipient = new ConsoleRecipientItem()
      {
        Email = "test1COI@mailup.com",
        Name = "First COI New Recipient" + DateTime.Now.ToFileTimeUtc(),
        Fields = new List<ConsoleRecipientDynamicFieldItem>()
        {
            new ConsoleRecipientDynamicFieldItem() { Id = 1, Value = "Name1COI_" + DateTime.Now.ToFileTimeUtc() },
            new ConsoleRecipientDynamicFieldItem() { Id = 2, Value = "LastName1COI_" + DateTime.Now.ToFileTimeUtc() }
            //here you can add all the fields you want to add...
        }
      };
    
      // 3) Invoke the web method:
      int result = 0;
      try
      {
        result = client.AddRecipientToList(idList, recipient, true);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Cannot perform the operation due to " + ex.Message);
        return;
      }
    
      // 4) Print results:
      if (result > 0)
        Console.WriteLine("Recipients Added with confirmed Opt-in! The ID of the recipient is " + result);
      else
        Console.WriteLine("An error occurred while adding the recipients with confirmed Opt-in.");
    }
                

    public by Geometry  894  7  4  0

    ToExactString: Converts the given double to a string representation of its exact decimal value. This procedure (and ArbitraryDecimal) from Jon Skeet! here: http://www.yoda.arachsys.com/csharp/DoubleConverter.cs

    Converts the given double to a string representation of its exact decimal value. This procedure (and ArbitraryDecimal) from Jon Skeet! here: http://www.yoda.arachsys.com/csharp/DoubleConverter.cs The double to convert. A string representation of the double's exact decimal value.
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Text.RegularExpressions;
    
    /// <summary>
    /// Converts the given double to a string representation of its
    /// exact decimal value.
    /// This procedure (and ArbitraryDecimal) from Jon Skeet! 
    /// here: http://www.yoda.arachsys.com/csharp/DoubleConverter.cs
    /// </summary>
    /// <param name="d">The double to convert.</param>
    /// <returns>A string representation of the double's exact decimal value.</returns>
    public static string ToExactString(this double d)
    {
        if (double.IsPositiveInfinity(d))
            return "+Infinity";
        if (double.IsNegativeInfinity(d))
            return "-Infinity";
        if (double.IsNaN(d))
            return "NaN";
    
        // Translate the double into sign, exponent and mantissa.
        long bits = BitConverter.DoubleToInt64Bits(d);
        // Note that the shift is sign-extended, hence the test against -1 not 1
        bool negative = (bits < 0);
        int exponent = (int)((bits >> 52) & 0x7ffL);
        long mantissa = bits & 0xfffffffffffffL;
    
        // Subnormal numbers; exponent is effectively one higher,
        // but there's no extra normalisation bit in the mantissa
        if (exponent == 0)
        {
            exponent++;
        }
        else
        {     
            // Normal numbers; leave exponent as it is but add extra
            // bit to the front of the mantissa
            mantissa = mantissa | (1L << 52);
        }
    
        // Bias the exponent. It's actually biased by 1023, but we're
        // treating the mantissa as m.0 rather than 0.m, so we need
        // to subtract another 52 from it.
        exponent -= 1075;
    
        if (mantissa == 0)
        {
            return "0";
        }
    
        // Normalize
        while ((mantissa & 1) == 0)
        {    //  i.e., Mantissa is even
            mantissa >>= 1;
            exponent++;
        }
    
        // Construct a new decimal expansion with the mantissa
        ArbitraryDecimal ad = new ArbitraryDecimal(mantissa);
    
        // If the exponent is less than 0, we need to repeatedly
        // divide by 2 - which is the equivalent of multiplying
        // by 5 and dividing by 10.
        if (exponent < 0)
        {
            for (int i = 0; i < -exponent; i++)
                ad.MultiplyBy(5);
            ad.Shift(-exponent);
        }
        // Otherwise, we need to repeatedly multiply by 2
        else
        {
            for (int i = 0; i < exponent; i++)
                ad.MultiplyBy(2);
        }
    
        // Finally, return the string with an appropriate sign
        if (negative)
            return "-" + ad.ToString();
        else
            return ad.ToString();
    }

    public by cghersi  2552  0  7  0

    How to create a new SqlCommand to invoke a Stored Procedure

    This method creates a new SqlCommand for a stored procedure invocation. It sets all the relevant information for a stored procedure that can be then executed in ADO.NET environment
    static public SqlCommand CreateStoredProc(SqlConnection connection, string name)
    {
         SqlCommand newSPCmd = new SqlCommand();
         newSPCmd.CommandType = CommandType.StoredProcedure;
         newSPCmd.Connection = connection;
         newSPCmd.CommandText = name;
         newSPCmd.CommandTimeout = WebConfig.Current.DBConnectionTimeout;   //default timeout for snip2code
         return newSPCmd;
    }

    public by cghersi  2517  0  5  0

    Stored Procedure with Transactions

    This is an effective way to write a stored procedure which needs to use transactions
    CREATE PROCEDURE [dbo].[Snippets_AddPropToSnippets] 
    	@PropName nvarchar(50),
    AS
    BEGIN
    	SET NOCOUNT ON;
    	SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
    	SET XACT_ABORT ON;
    
    	DECLARE @error int = 0;
    
    	BEGIN TRAN
    		-- do a query
    		SELECT	ID
    		FROM	Properties
    		WHERE	Name = @PropName
    		
    		-- save the eventual error condition (@@ERROR <> 0)
    		SET @error = @error + @@ERROR
    
    	--at the end of the transaction, check on cumulative error:
    	IF @error = 0
    		BEGIN
    			COMMIT;
    			RETURN 0;
    		END
    	ROLLBACK
    	RETURN -1;
    
    END
    • Public Snippets
    • Channels Snippets