none
how to create Two different database connection with in Stored Procedure RRS feed

  • General discussion

  •  how to create Two different database connection with in Stored Procedure
    I am Create Stored Procedure for read DB1 (database)  and insert to data in DB2(database) and delete to data in DB1 
    string OdbcConn = ConfigurationManager.AppSettings["ConnStr1"].ToString();
                OdbcConnection conn1 = new OdbcConnection(OdbcConn);
                string OdbcConn_Backup = ConfigurationManager.AppSettings["ConnStr1_Backup"].ToString();
                OdbcConnection conn1_Backup = new OdbcConnection(OdbcConn_Backup);
                string i = "0";
                try
                {
                    OdbcCommand cmd = new OdbcCommand("TransUpdateProc_KMS1_Backup", conn1);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@postcash", OdbcType.VarChar, 255);
                    cmd.Parameters["@postcash"].Value = "POSTPAID";
                    cmd.Parameters.Add("@eservices", OdbcType.VarChar, 255);
                    cmd.Parameters["@eservices"].Value = Service;
                    if (conn1.State == ConnectionState.Closed)
                    {
                        conn1.Open();
                    }
                    else
                    {
                        conn1.Close();
                        conn1.Open();
                    }
                    conn1_Backup.Open();
                    int rows = cmd.ExecuteNonQuery();
                    cmd.Dispose();
                    conn1.Close();
                    conn1_Backup.Close();
                    return rows.ToString();
                }
                catch(Exception ex)
                {
                    MclObj.WriteErrorFile("Error In DeleteTransactionDataKMS1 StoredProcedure  -->" + ex.ToString());
                    return "-1";
                }
    Tuesday, May 24, 2011 11:22 AM

All replies