Visual Studio 认为正确的 SQL 语法不正确 [英] Visual Studio thinks correct SQL syntax is incorrect

查看:69
本文介绍了Visual Studio 认为正确的 SQL 语法不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 2013 中,我创建了一个数据库项目并导入了一个现有数据库.起初一切都很好,项目构建并生成了创建脚本.

In Visual Studio 2013, I have created a database project and imported an existing database. At first all was fine, and the project built and produced create scripts.

但是,现在Visual Studio似乎认为存在SQL语法错误,返回几个SQL46010: Incorrect syntax near:错误.这些都来自 VS 生成的代码 - 我没有写过任何.

However, now Visual Studio seems to think that there are SQL syntax errors, returning several SQL46010: Incorrect syntax near: errors. These are all from code generated by VS - I have not written any of it.

示例 1:

ALTER ROLE [db_owner] ADD MEMBER [SomeUser];
SQL46010: Incorrect syntax near ADD.

示例 2:

DECLARE @Foo NVARCHAR(7) = 'abcdefg';
SQL46010: Incorrect syntax near =.

如果我将代码复制/粘贴到 SSMS 中,一切正常.

If I copy/paste the code into SSMS, everything works fine.

不幸的是,这些会阻止项目构建,这意味着我无法发布.由于它们是错误而非警告,因此我无法在项目设置中将它们设置为忽略.

Unfortunately, these prevent the project from building, which means I can't publish. Since they are errors, not warnings, I cannot set them to be ignored in the project settings.

存在一种解决方法,我可以将问题文件的构建操作设置为无,但我需要在发布时包含这些文件.

A workaround exists where I can set the problem files' Build Action to None, but I need these files included when I publish.

我试过了:

  • 删除并重新添加相同的代码
  • 复制/粘贴代码到新的 SQL 文件
  • 关闭并重新打开解决方案
  • 关闭并重新打开 Visual Studio
  • 更新 Microsoft SQL Server 数据工具 (SSDT)
  • 更新 Visual Studio

我能找到的最接近的问题是 this MSDN thread 从 2012 年开始,说明有一个错误的 SSDT SQL 解析器(它促使我尝试更新 SSDT).

The closest problem I have been able to find is this MSDN thread from 2012, stating that there is a bug SSDT SQL parser (which prompted me to try updating SSDT).

推荐答案

在项目属性中有一个名为 Target platform 的设置,它告诉 VS 要检查语法的 SQL Server 版本.

There is a setting in the project properties called Target platform that tells VS what version of SQL Server to check the syntax against.

这些是对 T-SQL 语法的相对较新的补充,如果语法设置为例如,它们可能不起作用.SQL Server 2005.

These are relatively new additions to the T-SQL syntax, and they might not work if the syntax was set to e.g. SQL Server 2005.

这篇关于Visual Studio 认为正确的 SQL 语法不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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