添加未使用的try catch时WCF服务崩溃

时间:2014-10-11 10:54:46

标签: c# wcf

我有一个非常奇怪的情况。 (C#4.0),windows 12服务器。

我有一个WCF服务运行一个方法,然后我决定添加一个新的操作合同(新方法调用)。 一切都很好。

然后我决定在我的新方法调用中添加一些try catch。 现在整个网络服务崩溃,甚至无法返回wsdl信息等。

只有在调用我的新方法时,才会调用此函数 不是我的老,但整个服务只是崩溃。 (更奇怪的是,它只在服务器上运行,而不是从VS调用时)

private bool ValidateLogin(string login, string pwd)
    {
        SqlConnection con;

        con = new SqlConnection("Data Source=Wsource;Initial Catalog=FTPServerSync;Integrated Security=True");

          con.Open();



        try //if I remove this try catch it works perfect.
        {   //if I remove this try catch it works perfect.
            SqlDataReader myReader = null;
            SqlCommand cmd = new SqlCommand("select ID from dbtabel where login=@login and password=@password ", con);
            SqlParameter paramLogin = new SqlParameter("login", SqlDbType.VarChar, 50) { Value = login };
            SqlParameter parampwd = new SqlParameter("password", SqlDbType.VarChar, 50) { Value = pwd };
            cmd.Parameters.Add(paramLogin);
            cmd.Parameters.Add(parampwd);

            myReader = cmd.ExecuteReader();
            bool b = myReader.HasRows;
            myReader.Close();

            return (b);
        }                   //if I remove this try catch it works perfect.
        catch               //if I remove this try catch it works perfect.
        {                   //if I remove this try catch it works perfect.
            return (false); //if I remove this try catch it works perfect.
        }                   //if I remove this try catch it works perfect.

    }

编辑: 抱歉花了你的时间,似乎我们有一个糟糕的网络/路由器,我是如此da ..不幸的是,每当我更改代码,它看起来像一个模式尝试Catch是问题。 现在一切正常。

0 个答案:

没有答案