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.
我正在为远程机器上的数据库(MDF文件DB)创建一个脚本,并使用它在本地创建相同的数据库。我在两台机器上都有Visual Studio 2010,所以使用数据库发布向导来生成脚本。
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.
接下来,我在Visual Studio中创建了一个空白DB(另一个MDF文件DB)并选择创建一个新的查询。我粘贴了复制的脚本,但是当我尝试运行它时,我得到了许多“错误语法接近GO”的错误。我不确定在我的屏幕底部弹出警报时总共有多少个。这似乎是很多。
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.
我仍然会得到“错误语法接近GO”的错误。
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.
远程DB是2008 R2,而我的本地文件是普通的2008,因此我不只是将MDF文件复制过去。
If anyone has any suggestions, they would be most welcome.
如果有人有什么建议,他们将是最受欢迎的。
2 个解决方案
#1
19
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.
GO不是Transact-SQL语句;它是由sqlcmd和osql实用程序以及SQL Server Management Studio代码编辑器识别的命令。
Either use such a tool to execute the script or omit the GO commands.
要么使用这样的工具执行脚本,要么省略GO命令。
#2
8
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.
如果在行尾使用SQL Server Management Studio代码编辑器以外的随机编辑器创建查询,您可能会得到一个回车(\r)字符,而不是回车+换行(\r\n)。即使你在最后点了DEL键然后输入它也不会改变。
Use Notepad++ to replace CR (\r) for CRLF (\r\n) - keep the order, it's important!
使用记事本++替换CRLF (\r\n) -保持顺序,这很重要!
#1
19
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.
GO不是Transact-SQL语句;它是由sqlcmd和osql实用程序以及SQL Server Management Studio代码编辑器识别的命令。
Either use such a tool to execute the script or omit the GO commands.
要么使用这样的工具执行脚本,要么省略GO命令。
#2
8
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.
如果在行尾使用SQL Server Management Studio代码编辑器以外的随机编辑器创建查询,您可能会得到一个回车(\r)字符,而不是回车+换行(\r\n)。即使你在最后点了DEL键然后输入它也不会改变。
Use Notepad++ to replace CR (\r) for CRLF (\r\n) - keep the order, it's important!
使用记事本++替换CRLF (\r\n) -保持顺序,这很重要!