1

I have the following action method:

[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");
             }
         }            
      }

and the following method:

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

Now if the getcontactinfo raise the folloiwng exception:-

[SqlException (0x80131904): Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries.]
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

.... the **catch (SqlException)** willnot be reached ?

Tohid
  • 6,175
  • 7
  • 51
  • 80
John John
  • 1
  • 72
  • 238
  • 501

1 Answers1

1

Change catch (SqlException) to catch (Exception ex).

You probably get another kind of exception, before SqlException happens.

Tohid
  • 6,175
  • 7
  • 51
  • 80