Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# System.InvalidOperationException:ExecuteReader需要打开且可用的连接。连接';它的当前状态是开放的_C#_Asp.net_Sql Server_Asp.net Mvc - Fatal编程技术网

C# System.InvalidOperationException:ExecuteReader需要打开且可用的连接。连接';它的当前状态是开放的

C# System.InvalidOperationException:ExecuteReader需要打开且可用的连接。连接';它的当前状态是开放的,c#,asp.net,sql-server,asp.net-mvc,C#,Asp.net,Sql Server,Asp.net Mvc,嗨,所以我在日志中出现了一个错误,有些功能有时会被破坏,尽管是间歇性的 完整堆栈跟踪如下所示: System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时出错。有关详细信息,请参见内部异常。-->System.InvalidOperationException:ExecuteReader需要打开且可用的连接。连接的当前状态为“打开”。在System.Data.SqlClient.SqlConnection.GetOpenConn

嗨,所以我在日志中出现了一个错误,有些功能有时会被破坏,尽管是间歇性的

完整堆栈跟踪如下所示:

System.Data.Entity.Core.EntityCommandExecutionException:执行命令定义时出错。有关详细信息,请参见内部异常。-->System.InvalidOperationException:ExecuteReader需要打开且可用的连接。连接的当前状态为“打开”。在System.Data.SqlClient.SqlConnection.GetOpenConnection(字符串方法)在System.Data.SqlClient.SqlConnection.ValidateConnectionForExecute(字符串方法,SqlCommand)在System.Data.SqlClient.SqlCommand.ValidateCommand(字符串方法,布尔异步)在System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、String方法、TaskCompletionSource
1完成、Int32超时、任务和任务、Boolean和usedCache、Boolean asyncWrite、Boolean inRetry)位于System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、String方法)在System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior行为、String方法)在System.Data.Entity.Infrastructure.InternalDispatcher
1.Dispatch[TTarget、TInterceptionContext、TResult](t在System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand命令,DbCommandInterceptionContext interceptionContext)上执行目标,Func
3操作,TinterContext interceptionContext,Action
3执行,Action
3执行)在System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStorommands(EntityCommand EntityCommand,CommandBehavior)——内部异常堆栈跟踪的末尾——在System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStorommands(EntityCommand EntityCommand,CommandBehavior行为)在System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext上下文,ObjectParameterCollection参数值)的System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func
1 Func,IDbExecutionStrategy executionStrategy,Boolean startLocalTransaction,Boolean releaseConnectionOnSuccess)位于System.Data.Entity.Core.Objects.ObjectQuery
1.c_uDisplayClass7.b_u5()位于System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func
1操作)在System.Data.Entity.Core.Objects.ObjectQuery中,在System.Data.Entity.Core.Objects.DataClasses.EntityCollection中,在System.Data.Entity.Core.Objects.DataClasses中,在System.Data.Entity.Core.Objects.DataClasses中,在System.Data.Data.Entity.Core.Objects.DataClasses中,在System.Data.Data.Core.Object中,在System.Data.Data.DataClasses中,在System.DataClasses中,在System.Data.Data在System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue,String relationshipName,String targetRoleName,Boolean mustBeNull,Object wrapperObject)的System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.c_u显示类7
2.b_uuu1(TProxy代理,TItem项)在System.Data.Entity.DynamicProxies.Product_49EFA7CB993633FA6F92A211A42F2C206E79CC0974B0D20D2E9E66248C8DC082.get_ProductSpecificationAttributes()在Nop.Plugin.Widgets.Enhancements.Controllers.ProductController.ProductDetail_SizeDropDownstocklevelsOveral(Int32 productId,String productColor)在lambda_方法(闭包,ControllerBase,Object[])在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,IDictionary
2参数)在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext ControllerContext,ActionDescriptor ActionDescriptor,IDictionary
2参数)在System.Web.Mvc.Async.AsyncControllerActionInvoker.b_39(IAsyncResult asyncResult,ActionInvocation innerInvokeState)位于System.Web.Mvc.Async.AsyncResultRapper.WrappedAsyncResult
2.CallEndDelegate(IAsyncResult asyncResult asyncResult)位于System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult asyncResult)System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b_uu3D()位于System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.c_uDisplayClass46.b_u3f()位于System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.c_uDisplayClass46.b_u3f()在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvokwithFilters.c_uuDisplayClass46.b_u3f()在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvokwithFilters.c_uDisplayClass46.b_u3f()在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvokwithFilters.c_uDisplayClass46.b_u3f()上在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvokwithFilters.c_uuDisplayClass46.b_u3f()在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvokwithFilters.c_uDisplayClass46.b_u3f()在System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvokwithFilters.c_uDisplayClass46.b_u3f()上在System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)在System.Web.Mvc.Async.AsyncControllerActionInvoker.c_uuDisplayClass21.c_uuDisplayClass2B.b_u1;1c()在System.Web.Mvc.Async.Async.AsyncControllerActionInvoker.c_uDisplayClass21.b_1e(IAsyncResult asyncResult asyncResult)在System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)的System.Web.Mvc.Async.asyncResult Async.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)中在System.Web.Mvc.Controller.EndExecuteCore中调用(IAsyncResult asyncResult asyncResult asyncResult)(IAsyncResult asyncResult)位于System.Web.Mvc.Async.asyncResult Rapper.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult)位于System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)位于System
[HttpPost]
    public ActionResult ProductDetail_SizesDropDown(int productId, string productColor)
    {
        string dropdownOptions = "";
        string dropdownOptionsSizes = "";
        var allSizes = new List<Tuple<string, int>>();
        var product = _productService.GetProductById(productId);
        if (product == null)
        {
            return Json(new
            {
                success = false
            });
        }
        var parentProductId = (product.ParentGroupedProductId > 0) ? product.ParentGroupedProductId : productId;

        var childProducts = _cacheManager.Get("CHILD_PRODUCTS_" + parentProductId, () => _productService.GetAssociatedProducts(parentProductId));

        if (childProducts.Count() == 0)
        {
            return Json(new
            {
                success = false
            });
        }

        foreach (var childProduct in childProducts)
        {
            var sizeSpec =
                childProduct.ProductSpecificationAttributes.FirstOrDefault(
                    x => x.SpecificationAttributeOption != null && x.SpecificationAttributeOption.SpecificationAttribute != null && x.SpecificationAttributeOption.SpecificationAttribute.Name == "Size");
            if (sizeSpec != null)
            {
                var size = this.GetSpecValue(sizeSpec);
                allSizes.Add(new Tuple<string, int>(size, sizeSpec.SpecificationAttributeOption.DisplayOrder));
            }
        }

        allSizes = allSizes.Distinct().OrderBy(x => x.Item2).ToList();

        var countSizes = 0;
        foreach (var sizeTuple in allSizes)
        {
            var size = sizeTuple.Item1;
            var disabled = "";
            var selected = "";

            var sizeProduct = _cacheManager.Get("SIZE_PRODUCT_" + parentProductId + "_" + sizeTuple.Item1 + "_" + productColor, 60, () =>
            {
                if (!String.IsNullOrEmpty(productColor))
                {
                    return _productService.GetAssociatedProducts(parentProductId).FirstOrDefault(x =>
                        x.ProductSpecificationAttributes.Any(psa =>
                            psa.SpecificationAttributeOption != null && psa.SpecificationAttributeOption.SpecificationAttribute != null && psa.SpecificationAttributeOption.Name == sizeTuple.Item1 &&
                            psa.SpecificationAttributeOption.SpecificationAttribute.Name == "Size") &&
                        x.ProductSpecificationAttributes.Any(psa =>
                            psa.SpecificationAttributeOption != null && psa.SpecificationAttributeOption.SpecificationAttribute != null && psa.SpecificationAttributeOption.Name == productColor &&
                            psa.SpecificationAttributeOption.SpecificationAttribute.Name == "Colour"));
                }
                else
                {
                    return _productService.GetAssociatedProducts(parentProductId).FirstOrDefault(x =>
                        x.ProductSpecificationAttributes.Any(psa =>
                            psa.SpecificationAttributeOption != null && psa.SpecificationAttributeOption.SpecificationAttribute != null && psa.SpecificationAttributeOption.Name == sizeTuple.Item1 &&
                            psa.SpecificationAttributeOption.SpecificationAttribute.Name == "Size"));
                }
            });

            // No size child exists for this product so we don't add to the dropdown
            if (sizeProduct == null)
                continue;

            var sizeLabel = size;
            if (sizeProduct != null)
            {
                var stockLabel = RefreshProductStockLabel(sizeProduct.Id, false);

                if (stockLabel.ToLower().Contains("out of stock"))
                {
                    stockLabel = "Out of stock";
                }

                if (stockLabel.ToLower() == "out of stock" || stockLabel.ToLower() == "low stock")
                {
                    sizeLabel += " <strong class=\"" + stockLabel.ToLower().Replace(" ", "-") + "\">" + stockLabel + "</strong>";
                }

                if (stockLabel.ToLower() == "out of stock" && !sizeProduct.PreorderAvailableNew)
                {
                    disabled = " disabled='disabled'";
                    selected = "";
                }
            }

            dropdownOptionsSizes += String.Format("<option value='{0}'{2}{3} data-text='{1}'>{0}</option>",
                HttpUtility.HtmlEncode(size.Replace("\"", "")), HttpUtility.HtmlEncode(sizeLabel), disabled, selected);

            countSizes++;
        }
        dropdownOptions = "<option value=''>Choose from " + countSizes + " sizes</option>" + dropdownOptionsSizes;


        return Json(new
        {
            success = true,
            dropdownOptions
        });
    }
var childProducts = _cacheManager.Get("CHILD_PRODUCTS_" + parentProductId, () => _productService.GetAssociatedProducts(parentProductId));
    System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.DeferredLoad() 
at  System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem]