如何修复“GO 附近语法错误”使用 Microsoft 数据库发布向导生成的脚本中存在错误?

发布于 2024-10-04 02:52:29 字数 559 浏览 0 评论 0原文

我已经花了几个小时寻找“最终”解决方案,但无法准确找出问题所在,所以我希望有人能指出正确的方向。

我正在尝试为远程计算机上的数据库(MDF 文件数据库)创建脚本,并使用它在本地创建相同的数据库。我的两台计算机上都有 Visual Studio 2010,因此使用数据库发布向导来生成脚本。

接下来,我在本地 Visual Studio 中创建了一个空白数据库(另一个 MDF 文件数据库),并选择创建一个新查询。我已经粘贴了复制的脚本,但是当我尝试运行它时,我收到了数十个“GO 附近语法不正确”错误。当警报弹出窗口从屏幕底部消失时,我不确定总共有多少。不过似乎很多。

我修剪掉了脚本中除了最顶部之外的所有内容,但仍然遇到相同的错误。现在看起来像这样:

SET ANSI_NULLS ON

GO

我仍然收到“GO 附近语法不正确”错误。

该工具生成的脚本是否存在本质上的错误,或者我是否做错了什么?

远程数据库是 2008 R2,而我的本地数据库只是普通的 2008,因此我不只是复制 MDF 文件。

如果有人有任何建议,我们将非常欢迎。

I've been searching for a "definitive" solution to this for a couple of hours now and can't find out exactly what the problem is so am hoping someone can point me in the right direction.

I'm trying to create a script for a database (an MDF file DB) on a remote machine and use it to create the same database locally. I've got Visual Studio 2010 on both machines so used the Database Publishing Wizard to generate the script.

I next created a blank DB in Visual Studio locally (another MDF file DB) and selected to create a new query. I've pasted the copied script in but when I try and run it I get dozens of "incorrect syntax near GO" errors. I'm not sure how many in total as the alert pop-up goes off the bottom of my screen. It would seem to be a lot though.

I trimmed off all but the very top of the script and I still get the same errors with it. It now looks like this:

SET ANSI_NULLS ON

GO

I still get the "incorrect syntax near GO" error with this.

Is there something inherently wrong with the scripts this tool generates or am I doing something wrong with it?

The remote DB is 2008 R2 and my local is just plain 2008, hence why I don't just copy the MDF file across.

If anyone has any suggestions, they would be most welcome.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寄意 2024-10-11 02:52:29

来自文档:

GO 不是 Transact-SQL 语句;它
是 sqlcmd 识别的命令
和 osql 实用程序和 SQL Server
Management Studio 代码编辑器。

要么使用这样的工具来执行脚本,要么省略 GO 命令。

From the docs:

GO is not a Transact-SQL statement; it
is a command recognized by the sqlcmd
and osql utilities and SQL Server
Management Studio Code editor.

Either use such a tool to execute the script or omit the GO commands.

陌路黄昏 2024-10-11 02:52:29

我最近遇到了同样的问题并找到了正确的答案(我认为)。

如果您在 SQL Server Management Studio 代码编辑器之外的某个随机编辑器中在行尾创建查询,您可能会得到一个 回车 (\r) 字符,而不是 回车 +换行 (\r\n)。即使您在行尾按下 DEL 键,然后按 Enter,它也不会改变。

使用 Notepad++ 将 CR (\r) 替换为 CRLF (\r\n) - 保持顺序,这很重要!

I ran into the same problem recently and found the right answer to it (I think).

If you create a query in some random editor other than SQL Server Management Studio Code editor at the end of a line you may get a CARRIAGE RETURN (\r) character instead of a CARRIAGE RETURN + LINE FEED (\r\n). And even if you hit the DEL key at the end of the line and then Enter it doesn't change.

Use Notepad++ to replace CR (\r) for CRLF (\r\n) - keep the order, it's important!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文