-2
I have a precedent that returns value, but when it arrives in Executescalar() of c# it returns the error "Object reference not set to an instance of an object"
The trial is perfect
            private string IdentificaPat()
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled = false;
                string retorno;
                string constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                using (SqlConnection con = new SqlConnection(constr))
                {
                    using (SqlCommand cmd = new SqlCommand("Sp_InsertContratoGestores"))
                    {
                        cmd.CommandTimeout = 300;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Connection = con;
                        con.Open();
                        retorno = cmd.ExecuteScalar().ToString();
                        con.Close();
                    }
                }
                if(retorno == "vazio")
                {
                    return "Vazio";
                }
                else
                {
                    return "Sem novos contratos";
                }
                db.Configuration.AutoDetectChangesEnabled = true;
                db.Configuration.ValidateOnSaveEnabled = true;
            }
probably his
cmd.ExecuteScalar()is returning NULL and makes that mistake on account ofToString()– jean