没有聚集索引的表在此版本的SQL Server不支持 [英] Tables without a clustered index are not supported in this version of SQL Server

查看:160
本文介绍了没有聚集索引的表在此版本的SQL Server不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的 VS 2010和EF 4.1 SQL Server数据库
下面提到code正常工作与本地SQL Server数据库(SQL 2008)。

但是,当我发表了 Windows Azure云的MVC应用程序 SQL Azure的它给的下面提到的错误


  1. 为什么这个错误的仅返回SQL Azure的(与桌面SQL Server 2008中工作)?

  2. 如何摆脱呢?

我的资料库 code样品作为below.Below提到的错误时调用来
  Catalog.SaveChanges()方式。

 使用(VAR目录=新DataCatalog())
{
    VAR retailSaleReturn =新RetailSaleReturn
    {
        ReturnQuantity = returnQuantity,
        产品= saleDetailObj.Product,
        所有者=所有者,
        供应商=供应商,
    };    //添加到环境
    Catalog.RetailSaleReturns.Add(retailSaleReturn);    //保存分贝
    Catalog.SaveChanges();
}

DbUpdateException 是象下面这样:

  {,同时节省不为他们的关系公开外键属性的实体时出现错误。该EntityEntries属性将返回null,因为一个单一的实体不能被认定为异常的根源。例外的处理,同时节省可制成通过在实体类型揭露外键的属性更容易。详情请参阅的InnerException。}

的InnerException 是象下面这样:

  {没有聚集索引的表未在此版本的SQL Server支持,请创建聚簇索引,然后再试一次。}

堆栈跟踪是像下面

 在System.Data.Entity.Internal.InternalContext.SaveChanges()
   在PawLoyalty.Data.Repositories.CustomersRepository.ReturnRetailOnlySales(GUID saleDetailId,的Int32 returnQuantity,字符串providerKey,字符串ownerKey)在D:\\ PawLoyalty模块\\ PawLoyalty \\ PawLoyalty \\ PawLoyalty.Data \\库\\ CustomersRepository.cs:550线
   在PawLoyalty.Web.Areas.Providers.Controllers.CustomersController.ReturnRetailOnlySales(字符串providerKey,字符串ownerKey,字符串petKey中GUID saleDetailId,的Int32 returnQuantity)在D:\\ PawLoyalty模块\\ PawLoyalty \\ PawLoyalty \\ PawLoyalty.Web \\区\\供应商\\控制器\\ CustomersController.cs:942线
   在lambda_method(封闭,ControllerBase,对象[])
   在System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary`2参数)
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2参数)
   在System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
   在System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter过滤器,ActionExecutingContext preContext,Func`1续)


解决方案

您需要创建所有表上的聚集索引的 SQL Azure的的,你要添加行;否则,INSERT语句总是失败。

创建唯一聚集索引Idx_TableName在tablename上(yourGUIDColumn);

下面是关于明确这些指标的一般准则和限制的参考: MSDN链接

下面是另一篇文章,说明此项背后的原因:链接

I am working on vs 2010 and EF 4.1 with SQL server database. Below mentioned code works fine with local SQL server DB.(SQL 2008).

But when I published the MVC application for windows AZURE cloud and SQL Azure it's giving below mentioned error.

  1. Why this error is only return SQL Azure (working with desktop SQL server 2008)?
  2. How to get rid of this ?

My repository code sample as below.Below mentioned error comes when calling Catalog.SaveChanges() method.

using (var catalog = new DataCatalog())
{
    var retailSaleReturn = new RetailSaleReturn
    {
        ReturnQuantity = returnQuantity,
        Product = saleDetailObj.Product,
        Owner = owner,
        Provider = provider,
    };

    //add to context
    Catalog.RetailSaleReturns.Add(retailSaleReturn);

    //save for db
    Catalog.SaveChanges();
}

DbUpdateException is Like below :

{"An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details."}

InnerException is Like below :

{"Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again."}

StackTrace is Like below

at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at PawLoyalty.Data.Repositories.CustomersRepository.ReturnRetailOnlySales(Guid saleDetailId, Int32 returnQuantity, String providerKey, String ownerKey) in D:\PawLoyalty Module\PawLoyalty\PawLoyalty\PawLoyalty.Data\Repositories\CustomersRepository.cs:line 550
   at PawLoyalty.Web.Areas.Providers.Controllers.CustomersController.ReturnRetailOnlySales(String providerKey, String ownerKey, String petKey, Guid saleDetailId, Int32 returnQuantity) in D:\PawLoyalty Module\PawLoyalty\PawLoyalty\PawLoyalty.Web\Areas\Providers\Controllers\CustomersController.cs:line 942
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)

解决方案

You need to create a clustered index on all tables in SQL Azure that you wish to add rows to; otherwise the insert statement always fails.

CREATE UNIQUE CLUSTERED INDEX Idx_TableName ON TableName(yourGUIDColumn);

Here is a reference to the general guidelines and limitations specifically regarding these indexes: MSDN Link

Here is another article which explains the reasoning behind this: link

这篇关于没有聚集索引的表在此版本的SQL Server不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆