【问题标题】:How to fix this error "An unhandled exception of type 'System.StackOverflowException' occurred in demoWcfService.DLL"如何修复此错误“在 demoWcfService.DLL 中发生了类型为 'System.StackOverflowException' 的未处理异常”
【发布时间】:2014-08-27 07:01:02
【问题描述】:

我创建了一个 wcf 服务并从 Web 应用程序中使用它。我已经在 WCF 中定义了所有数据库连接并从 Web 应用程序调用。它在此页面的 I Service1.cs 中显示错误它显示错误在 demoWcfService 中发生了“System.StackOverflowException”类型的未处理异常.DLL”此时为“public string mobile”

IService1.cs:

public interface IService1
{
    [OperationContract]
    string insertuserdetails(userdetails userinfo);
}

[DataContract]
public class userdetails
{
    [DataMember]
    public string name
    {
       get { return name; }
       set { name = value; }
    }

    [DataMember]
    public string password
    {
       get { return password; }
       set { password = value; }
    }

    [DataMember]
    public string mobile
    {
       get { return mobile; }
       set { mobile = value; }
    }
}

Service1.svc.cs:

public class Service1 : IService1
{
    public string insertuserdetails(userdetails userinfo)
    {
        string message;
        SqlConnection con = new SqlConnection(" Data Source=72.18.355.116,1533;Initial    
        Catalog=trainingcyber;User Id=cyber13;Password=train13cyber$$;");
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into info (name,password,mobile) 
       values(@name,@password,@mobile) ");

        cmd.Parameters.AddWithValue("@name", userinfo.name);
        cmd.Parameters.AddWithValue("@password", userinfo.password);
        cmd.Parameters.AddWithValue("@mobile", userinfo.mobile);
        int result = cmd.ExecuteNonQuery();
        if (result == 1)
        {
            message = userinfo.name + " inforamation inserted ";
        }
        else
        {
            message = userinfo.name + "not inserted";
        }

        con.Close();
        return message;


    }

Web 应用程序代码:Default.aspx.cs:

public partial class _Default : System.Web.UI.Page
{
   ServiceReference1.Service1Client objServiceClientobjService = new    ServiceReference1.Service1Client();

   protected void Page_Load(object sender, EventArgs e)
   {

   }

   protected void Button1_Click(object sender, EventArgs e)
   {
      userdetails userinfo = new userdetails();
      userinfo.name = TextBoxUserName.Text;
      userinfo.password = TextBoxPassword.Text;
      userinfo.mobile = TextBoxMobile.Text;

      string result = objServiceClientobjService.insertuserdetails(userinfo);
      LabelMessage.Text = result;


   }
}

【问题讨论】:

  • 您能粘贴确切的异常消息吗?我看不出为什么这段代码应该抛出 StackOverflowException。请包括堆栈跟踪。
  • 显示以下错误,请解决此问题“demoWcfService.DLL 中发生'System.StackOverflowException' 类型的未处理异常”
  • 请任何人向我发送此异常的解决方案..

标签: asp.net sql-server wcf


【解决方案1】:

你没有在 sqlCommand 中传递你的连接字符串,我改变了你的方法。

public class Service1 : IService1
{
    public string insertuserdetails(userdetails userinfo)
    {
        string message;
        SqlConnection con = new SqlConnection(" Data Source=72.18.355.116,1533;Initial    
        Catalog=trainingcyber;User Id=cyber13;Password=train13cyber$$;");
        con.Open();
        SqlCommand cmd = new SqlCommand("insert into info (name,password,mobile) 
       values(@name,@password,@mobile) ",con);

        cmd.Parameters.AddWithValue("@name", userinfo.name);
        cmd.Parameters.AddWithValue("@password", userinfo.password);
        cmd.Parameters.AddWithValue("@mobile", userinfo.mobile);
        int result = cmd.ExecuteNonQuery();
        if (result == 1)
        {
            message = userinfo.name + " inforamation inserted ";
        }
        else
        {
            message = userinfo.name + "not inserted";
        }

        con.Close();
        return message;


    }

【讨论】:

    猜你喜欢
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多