从 sql management studio 修改表设计时出现 SQL 错误
我在 SQL Server 2008 上有一个相当大的表(20 多列)。我使用 Microsoft 的 SQL Server Management Studio 打开表设计视图并添加一列。添加列后,我将其在列排序中向上移动。
下图显示了我添加的列,以及我试图通过将其向上拖动几个位置来将其移动到的位置。
完成此操作后,当我尝试执行以下操作时出现异常打开网站。当我添加列而不将其在列排序中向上移动时,一切正常。
有人可以帮我解决这个问题吗?这是 MSSQL 服务器、管理工作室中的错误还是其他问题?
异常
Operand type clash: bit is incompatible with uniqueidentifier
堆栈跟踪:
[SqlException (0x80131904): Operand type clash: bit is incompatible with uniqueidentifier]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363
System.Data.SqlClient.SqlDataReader.HasMoreRows() +301
System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout) +422
NHibernate.Driver.NHybridDataReader.Read() +28
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +1383
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +114
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +195
[ADOException: could not execute query
[ SELECT * from SomeFunction(@p0,@p1) ]
Name:Id - Value:3429fb7e-dba3-4c74-b41b-6f2e0bbb33f8 Name:Moment - Value:7-1-2011 12:16:45
[SQL: SELECT * from SomeFunction(@p0,@p1)]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +637
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +23
NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) +438
NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results) +373
NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters) +340
NHibernate.Impl.SqlQueryImpl.List() +258
CMS.ResourceAccess.DataAccessLogic.Repositories.NodeRepository.GetAncestors(Guid nodeId) in C:\Projects\Website\DataAccessLogic\Repositories\Repository.cs:228
CMS.Business.Components.Services.NodeService.GetAncestors(Guid nodeId) in C:\Projects\Website\DataAccessLogic\Repositories\Service.cs:921
CMS.Business.Components.Services.NodeService.GetSiteByNodeId(Guid nodeId) in C:\Projects\Website\DataAccessLogic\Repositories\Service.cs:1280
Plugin.Wysiwyg.Business.Components.Services.WysiwygSearchService.RebuildIndex() +1232
CMS.Business.Components.Services.SearchService.RebuildIndexForSites(IEnumerable 1 sites, ConfigurationManager configurationManager) in C:\Projects\Website\Services\Service.cs:303
CMS.Business.Components.Services.SearchService.RebuildIndex() in C:\Projects\Website\DataAccessLogic\Repositories\Service.cs:252
CMS.Backend.MvcApplication.Application_Start() in C:\Projects\Website\Global.asax.cs:49
[HttpException (0x80004005): could not execute query
[ SELECT * from SomeFunction(@p0,@p1) ]
Name:Id - Value:3429fb7e-dba3-4c74-b41b-6f2e0bbb33f8 Name:Moment - Value:7-1-2011 12:16:45
[SQL: SELECT * from SomeFunction(@p0,@p1)]]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +3988565
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +325
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
[HttpException (0x80004005): could not execute query
[ SELECT * from SomeFunction(@p0,@p1) ]
Name:Id - Value:3429fb7e-dba3-4c74-b41b-6f2e0bbb33f8 Name:Moment - Value:7-1-2011 12:16:45
[SQL: SELECT * from SomeFunction(@p0,@p1)]]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11529072
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4784373
编辑: 我使用 NHibernate 作为 ORM
I've got a rather large table (20+ columns) on an SQL server 2008. I'm using Microsofts SQL Server Management Studio to open the tables design view and add a column. After adding the column i move it up in the column sorting.
The image below shows the column i added and where i'm trying to move it to by just dragging it a few places up.
After i've done this i'm getting an exception when i'm trying to open up the website. Everything works fine when i add the column without moving it up in the column sorting.
Can someone help me figuring out this problem. Is this an bug in MSSQL server, the management studio or is something else going wrong?
The exception
Operand type clash: bit is incompatible with uniqueidentifier
The stacktrace:
[SqlException (0x80131904): Operand type clash: bit is incompatible with uniqueidentifier]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363
System.Data.SqlClient.SqlDataReader.HasMoreRows() +301
System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout) +422
NHibernate.Driver.NHybridDataReader.Read() +28
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +1383
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +114
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +195
[ADOException: could not execute query
[ SELECT * from SomeFunction(@p0,@p1) ]
Name:Id - Value:3429fb7e-dba3-4c74-b41b-6f2e0bbb33f8 Name:Moment - Value:7-1-2011 12:16:45
[SQL: SELECT * from SomeFunction(@p0,@p1)]]
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +637
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +23
NHibernate.Impl.SessionImpl.ListCustomQuery(ICustomQuery customQuery, QueryParameters queryParameters, IList results) +438
NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters, IList results) +373
NHibernate.Impl.SessionImpl.List(NativeSQLQuerySpecification spec, QueryParameters queryParameters) +340
NHibernate.Impl.SqlQueryImpl.List() +258
CMS.ResourceAccess.DataAccessLogic.Repositories.NodeRepository.GetAncestors(Guid nodeId) in C:\Projects\Website\DataAccessLogic\Repositories\Repository.cs:228
CMS.Business.Components.Services.NodeService.GetAncestors(Guid nodeId) in C:\Projects\Website\DataAccessLogic\Repositories\Service.cs:921
CMS.Business.Components.Services.NodeService.GetSiteByNodeId(Guid nodeId) in C:\Projects\Website\DataAccessLogic\Repositories\Service.cs:1280
Plugin.Wysiwyg.Business.Components.Services.WysiwygSearchService.RebuildIndex() +1232
CMS.Business.Components.Services.SearchService.RebuildIndexForSites(IEnumerable 1 sites, ConfigurationManager configurationManager) in C:\Projects\Website\Services\Service.cs:303
CMS.Business.Components.Services.SearchService.RebuildIndex() in C:\Projects\Website\DataAccessLogic\Repositories\Service.cs:252
CMS.Backend.MvcApplication.Application_Start() in C:\Projects\Website\Global.asax.cs:49
[HttpException (0x80004005): could not execute query
[ SELECT * from SomeFunction(@p0,@p1) ]
Name:Id - Value:3429fb7e-dba3-4c74-b41b-6f2e0bbb33f8 Name:Moment - Value:7-1-2011 12:16:45
[SQL: SELECT * from SomeFunction(@p0,@p1)]]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +3988565
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +191
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +325
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +407
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
[HttpException (0x80004005): could not execute query
[ SELECT * from SomeFunction(@p0,@p1) ]
Name:Id - Value:3429fb7e-dba3-4c74-b41b-6f2e0bbb33f8 Name:Moment - Value:7-1-2011 12:16:45
[SQL: SELECT * from SomeFunction(@p0,@p1)]]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11529072
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4784373
EDIT:
I'm using NHibernate as ORM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
据我估计,在您的 SQL 代码中(可能在函数中,或者它所依赖的视图中)有一个 SELECT * 潜伏着。这只是 SELECT * 危险的众多原因之一。下面是一个类似的示例,用于演示一种此类故障模式:
上面返回单个结果行,如预期的那样。现在我们以与 SSMS 相同的方式在幕后执行更改:
现在我们再次查询 F 函数:
我们得到:
事实上,如果我将F函数修改为:
我可以得到:
There's a SELECT * lurking somewhere in your SQL code (possibly in the function, or a view it relies on), by my reckoning. This is just one of many reasons SELECT * is dangerous. Here's an example of something similar, to demonstrate one such failure mode:
The above returns a single result row, as expected. Now we perform the change the same way SSMS will be doing, behind the scenes:
And now we query our F function again:
And we get:
In fact, if I modify the F function to be:
I can get:
你如何从代码访问你的表?该错误表明您在代码中的某个位置访问了表,并且您的代码取决于列的顺序。
由于您将列移到了另一个地方,现在您的代码突然尝试访问第 1 列。 17(或其他)并假设这是一个
uniqueidentifier
列 - 但情况不再是这样,因为您重新组织了表的列顺序......How are you accessing your table from code?? The error would indicate that somewhere in your code, you access the table and your code depends on the sequence of the columns.
Since you moved away your column to another place, now suddenly your code is trying to access column no. 17 (or whatever) and assumes that this is a
uniqueidentifier
column - but that's no longer the case, since you reorganized your table's column order....只需重新编译引用该表的所有视图、存储过程、UDF 和 TVF 即可。
SQL Server 在内部将列名转换为数字。当您移动列时,这会在运行缓存的查询计划时导致意外情况。
我相信您也可以重新启动 SQL Server 以使其刷新所有计划。不过我还没有尝试过这个。
Simply recompile all views, stored procedures, UDFs, and TVF's that reference this table.
SQL Server converts the column names to numbers internally. When you shift columns around, this causes unexpected conditions when cached query plans are run.
I believe you can also just restart SQL Server to cause it to flush all plans. I haven't tried this, though.