Showing posts with label C# Programming. Show all posts
Showing posts with label C# Programming. Show all posts

Change ConnectionString when database server is not working


Thursday, September 22, 2011

Hello Friends,

Sometime, you might have notice that, your hosting server is working fine but your database is not working due to which you
might be getting error on website and you might be loosing visitor and ranking in website..

This post is regarding that only, you can manage this issue by two database.

You can have two database at different server and you can call this in global.asax

first you can make ping to first database everytime and if its working you can call first server database and
if you find any issue or server is not working then you can switch to second server using below code..



    Dim connStatus As String
        Dim png As New Ping()
        Dim pr As PingReply = png.Send("221.256.357.36")
        connStatus = pr.Status.ToString()
        '--------------------

        If connStatus = "Success" Then
            If ConnString = "OldConnection" Then
                If ConfigurationManager.ConnectionStrings("oldconnection1").ConnectionString <> "" Then
                    ConnObj = New SqlConnection(ConfigurationManager.ConnectionStrings("oldconnection1").ConnectionString)
                Else
                    Throw New Exception("Connection String is Empty")
                End If
            Else
                If ConfigurationManager.ConnectionStrings("oldconnection2").ConnectionString <> "" Then
                    ConnObj = New SqlConnection(ConfigurationManager.ConnectionStrings("oldconnection2").ConnectionString)
                Else
                    Throw New Exception("Connection String is Empty")
                End If
            End If
        Else
            If ConnString = "newconnection" Then
                If ConfigurationManager.ConnectionStrings("newconnection1").ConnectionString <> "" Then
                    ConnObj = New SqlConnection(ConfigurationManager.ConnectionStrings("newconnection1").ConnectionString)
                Else
                    Throw New Exception("Connection String is Empty")
                End If
            Else
                If ConfigurationManager.ConnectionStrings("newconnection2").ConnectionString <> "" Then
                    ConnObj = New SqlConnection(ConfigurationManager.ConnectionStrings("newconnection2").ConnectionString)
                Else
                    Throw New Exception("Connection String is Empty")
                End If
            End If
        End If


Let me know, if you have any query..




Thanks Hope this post will help you, if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer
e-Procurement Technologies Ltd (India)
www.abcprocure.com 

How to create class file in Asp.Net ?


Sunday, July 25, 2010

Hi,

You can just add App_Code file and add class file to this folder and copy this code to that class file and modify according to your need.

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using commonlib.Common;

/// <summary>
/// Summary description for Program
/// </summary>
public class Program
{
    #region "Fields"

    string sOperation;
    int iProgramID;
    string sProgramName;
    string sSlogan;
    string sStartTime;
    string sEndTime;
    string sDetail;
    int iCityID;
    string sStatus;

    #endregion

    #region "Construtor"
    public Program()
    {
    }

    public Program(string SOperation, int IProgramID, string SProgramName, string SSlogan, string SStartTime, string SEndTime, string SDetail, int ICityID, string SStatus)
    {
        this.sOperation = SOperation;
        this.iProgramID = IProgramID;
        this.sProgramName = SProgramName;
        this.sSlogan = SSlogan;
        this.sStartTime = SStartTime;
        this.sEndTime = SEndTime;
        this.sDetail = SDetail;
        this.iCityID = ICityID;
        this.sStatus = SStatus;
    }
    #endregion

    #region "Properties"

    public string SOperation
    {
        get { return sOperation; }
        set { sOperation = value; }
    }

    public int IProgramID
    {
        get { return iProgramID; }
        set { iProgramID = value; }
    }

    public string SProgramName
    {
        get { return sProgramName; }
        set { sProgramName = value; }
    }

    public string SSlogan
    {
        get { return sSlogan; }
        set { sSlogan = value; }
    }

    public string SStartTime
    {
        get { return sStartTime; }
        set { sStartTime = value; }
    }

    public string SEndTime
    {
        get { return sEndTime; }
        set { sEndTime = value; }
    }

    public string SDetail
    {
        get { return sDetail; }
        set { sDetail = value; }
    }

    public int ICityID
    {
        get { return iCityID; }
        set { iCityID = value; }
    }

    public string SStatus
    {
        get { return sStatus; }
        set { sStatus = value; }
    }

    #endregion

    #region "Functions"

    public int ProgramOperation(string user, string pass)
    {

        SqlConnection conn = new SqlConnection("Data Source=localhost;Database=MyDB;Integrated Security=SSPI");
        SqlCommand command = new SqlCommand("XYZ_SP_CheckProgramAvailability", conn);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.Add("@User", SqlDbType.VarChar).Value = user;
        command.Parameters.Add("@Pass", SqlDbType.VarChar).Value = pass;
        conn.Open();
        int rows = command.ExecuteNonQuery();
        conn.Close();

    }

    #endregion
}


Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Senior Asp.Net Developer

e-Procurement Technologies Ltd (India)
www.abcprocure.com



How to define Global Variable in Windows Forms with C#


Thursday, March 25, 2010

Create one Static class and declare static member/property into that class.

Now you can access that variable from any form in your windows application. Also you can able to set and get variable values.

GlobalModule Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class GlobalModule
{

private static string _GlobalVar = "";
public static string GlobalVar
{
get { return _GlobalVar; }
set { _GlobalVar = value; }
}

public static string FirstName = "Rajesh";
}



How to use global variables in application:


//Set the value to static variable
GlobalModule.GlobalVar = "VB.Net C#";

//Get the value from static variable
string CheckVal = GlobalModule.GlobalVar;
string FirstName = GlobalModule.FirstName;



Hope this post will help you,
if yes please put comment below of this page,
Rajesh Singh,
Asp.Net Developer
Indianic Infotech Ltd (India)
rajesh@indianic.com


.

Explaination of flow of Authorize.net Payment Gateway


Wednesday, October 14, 2009

In this post, I have explained you step by step implementation of authorize.net payment gateway integration in your website and explained you what happen behind the screen in payment gateway processing.


Explanation of Step 1


Step 1: The merchant submits a credit card transaction to the Authorize.Net Payment
Gateway on behalf of a customer via secure Web site connection, retail store, MOTO
center or wireless device.


Explanation of Step 2


Step 2: Authorize.Net receives the secure transaction information and passes it via a secure connection to the Merchant Bank's Processor.


Explanation of Step 3


Step 3: The Merchant Bank's Processor submits the transaction to the Credit Card Network (a system of financial entities that communicate to manage the processing, clearing, and settlement of credit card transactions).


Explanation of Step 4


Step 4: The Credit Card Network routes the transaction to the Customer's Credit Card Issuing Bank

Explanation of Step 5

Step 5: The Customer's Credit Card Issuing Bank approves or declines the transaction based on the customer's available funds and passes the transaction results back to the Credit Card Network.


Explanation of Step 6


Step 6: The Credit Card Network relays the transaction results to the Merchant Bank's Processor.

Explanation of Step 7


Step 7: The Merchant Bank's Processor relays the transaction results to Authorize.Net.


Explanation of Step 8


Step 8: Authorize.Net stores the transaction results and sends them to the customer and/or the merchant. This step completes the authorization process – all in about three seconds or less!


Explanation of Step 9


Step 9: The Customer's Credit Card Issuing Bank sends the appropriate funds for the transaction to the Credit Card Network, which passes the funds to the Merchant's Bank. The bank then deposits the funds into the merchant's bank account. This step is known as the settlement process and typically the transaction funds are deposited into your primary bank account within two to four business days.




Hope this post has helped you,
If yes, Please put a comment below to encourage us.
Thank you

Rajesh Singh,
Indianic Infotech Ltd
rajesh@indianic.com