1

我有以下操作方法:

[Authorize]
    public ActionResult CustomersDetails(long[] SelectRight)
    {
        if (SelectRight == null)
        {
            return RedirectToAction("customer", new { isError = true });
        }
        else
        {
            try 
            {
                var ContactsDetails2 = new ContactsDetails
                    {
                        Info = r.getcontactinfo(SelectRight)
                    };

                foreach (var x in ContactsDetails2.Info)
                {
                    ViewData[x.USER_ID.ToString()] = r.getorgname(x.USER_ID).ToString();
                }

                return View(ContactsDetails2);
            }
            catch (SqlException)
            {
                ModelState.AddModelError("", "Too many records will be returned, please try to minimize your selection and try again.");
                return RedirectToAction("customer", "Home");
             }
         }            
      }

和以下方法:

public IEnumerable<AaaUserContactInfo> getcontactinfo(long[] id)
        {
            var organizationsiteids = from accountsitemapping in entities.AccountSiteMappings
                      where id.Any(accountid => accountsitemapping.ACCOUNTID == accountid)
                                       select accountsitemapping.SITEID;
//code goes here

现在,如果 getcontactinfo 引发以下异常:-

[SqlException (0x80131904): 你的 SQL 语句的某些部分嵌套太深。重写查询或将其分解为更小的查询。]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock , Boolean asyncClose) +688
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +82
System .Data.SqlClient.SqlDataReader.get_MetaData() +135

.... **catch (SqlException)**将无法达成?

4

1 回答 1

1

更改catch (SqlException)catch (Exception ex)

在发生之前,您可能会遇到另一种异常SqlException

于 2013-01-06T00:00:25.493 回答