-1

I made a web proyect, and in all the preview codes compiling (F5) i was abble to test and continue using my programs and codes, after I finished it... i need to publish my web app, y have 4 Main classes, Bussines,Data,Entity and Visual, after this i compile my entire proyect, and try to publish it, i already conect my app to the DB and APP server because my Connection String it's already defined to acces that server in test mode and it works with no problem, the problem it's after i publish my proyect y got a StackOverflowException at SqlConnection.Open() but only by publishing it, can someone help me to figure out why it's happening this?

Here it's my code with the exception: Error Capture Debug

 //Funcion Conectar

public SqlConnection conectar()
        {
            SqlConnecti

on cn = new SqlConnection();
            //cn.ConnectionString = @"Data Source=LAP\YRG_LOCAL; Initial Catalog= SAP3Test; Integrated Security=true";
            //cn.ConnectionString = @"Data Source=SERVER\SQLSERVER2008; Initial Catalog= SAP3Test; Integrated Security=true";
            //Cn.ConnectionString = @"Data Source=MEXMAC176AP12\SQLSERVER2008; Initial Catalog= SAP3Test; user=sa password=E1nste1n01 Integrated Security=true";
            cn.ConnectionString = @"Data Source=SERVER\YRGSQL2008R2; Initial Catalog= SAP3; Integrated Security=true; ";
            return cn;
        }

//Función para crear registro en Bitácora con sobrecarga
        public static int CrearBitacora(String Sys, String pagWeb, int RESULTADO, String display) //sobrecarga cuando no se puede enviar objeto tipo entUsuario
        {
            //Declaración de objetos que se usaran, Res como , SQLCMD y un DATAREADER
            //entUsuario obj = null;
            SqlCommand cmd = null;
            SqlDataReader dr = null;
            int RES = 0;
            try
            {
                Conexion cn = new Conexion(); // Variable de conexión para BD
                SqlConnection cnx = cn.conectar();
                cmd = new SqlCommand("CrearBitacora", cnx);
                cmd.Parameters.AddWithValue("@idUsuario", "System");
                cmd.Parameters.AddWithValue("@paginaWeb", pagWeb);
                cmd.Parameters.AddWithValue("@tipoAccion", RESULTADO);//Se obtendrá de BD como parte del resultado
                cmd.Parameters.AddWithValue("@Mensaje", display);//Mensaje que se mostró al Usuario
                cmd.CommandType = CommandType.StoredProcedure;
                //se ejecuta el SP
                if (cnx != null && cnx.State == ConnectionState.Closed)
                {
                    cnx.Open();
                    dr = cmd.ExecuteReader();
                    dr.Read();
                    //se obtiene respuesta si se creo o no el registro en Bitácora
                    RES = Convert.ToInt32(dr["RES"]);
                }
                cmd.Connection.Close();
            }
            catch (Exception ex)
            {
                String mesg;
                int Reg = 0;
                mesg = ex.ToString();
                RES = 4; //Asigna 4 a Res en caso de algún error durante la operación
                //Insertar Registro en Bitácora
                String MsgFinal = "Error de Sistema Mensaje de Error: " + mesg;
                Reg = CrearBitacora("System", pagWeb, RES, MsgFinal);
                //FIN Insertar Registro en Bitácora
            }
            finally
            {
                if (cmd != null && cmd.Connection.State != ConnectionState.Closed)
                {
                    cmd.Connection.Close(); //Cerrar conexión de datos
                }
                else
                {
                    cmd.Connection.Close(); //Cerrar conexión de datos
                }
            }
            return RES;
        } 
    }

Thanks to all.

3 Answers3

2

You're catching an exception and calling the same method.

 catch (Exception ex)
        {
            String mesg;
            int Reg = 0;
            mesg = ex.ToString();
            RES = 4; //Asigna 4 a Res en caso de algún error durante la operación
            //Insertar Registro en Bitácora
            String MsgFinal = "Error de Sistema Mensaje de Error: " + mesg;
            Reg = CrearBitacora("System", pagWeb, RES, MsgFinal); // <---- This line!!!
            //FIN Insertar Registro en Bitácora
        }
Artavazd Balayan
  • 2,353
  • 1
  • 16
  • 25
0

Your code is trying to go into interactive mode. That works in test but it will not in a production web server. use a function to display your messages (Jquery or Java)

Alexis
  • 11
  • 2
0
public static class MessageBox
{
public static void ShowMessage(string MessageText, Page MyPage)
    {     
            MyPage.ClientScript.RegisterStartupScript(MyPage.GetType(),
            "MessageBox", "alert('" + MessageText.Replace("'", "\'") + "');", true);
    }
}
Ali Vojdanian
  • 2,067
  • 2
  • 31
  • 47
Alexis
  • 11
  • 2
  • Try this code. You can added in App_Code to be used in the whole app – Alexis Jan 26 '16 at 20:40
  • Try to only use one answer for the same question. Don't post two or more than one answer. You can simply update the other answer instead of posting different answers. – Ali Vojdanian Jan 26 '16 at 20:44