英文:
SQLCMD fails on INSERT with "Syntax error at line xxxxx near command '&'"
问题
我使用SQLCMD导入由mssql-scripter生成的DDL,并出现了以下错误:
引发错误的INSERT语句如下:
INSERT [dbo].[Settings_ContentPartFieldDefinitionRecord] ([Id], [Name], [Settings], [ContentFieldDefinitionRecord_id], [ContentPartDefinitionRecord_Id]) VALUES (12, N'JavascripttoRun', N'以下为正确的插入语句,如果我在SSMS或Azure Data Studio中运行它,它可以正常工作。
我在互联网上找到了一些类似的错误消息文章,但没有适用于我的解决方法。
有什么想法吗?
英文:
I use SQLCMD to import DDL generated by mssql-scripter and i got this error:
The offending INSERT is the following:
> INSERT [dbo].[Settings_ContentPartFieldDefinitionRecord] ([Id], [Name], [Settings], [ContentFieldDefinitionRecord_id], [ContentPartDefinitionRecord_Id]) VALUES (12, N'JavascripttoRun', N'<settings DisplayName="Javascript to Run" InsertStuffFieldSettings.RawHtml="<script type="text/javascript">
 $(document).ready(function() {
 ShowAdvancedLinkSettings();
 });
 $("#AdvancedLink_LinkType_Value").change(function() {
 ShowAdvancedLinkSettings();
 });
 
 function ShowAdvancedLinkSettings() {
 switch($("#AdvancedLink_LinkType_Value").val()) {
 case "External":
 $(".content-picker-field[data-field-name=''InternalContent'']").hide()
 $("#AdvancedLink_Caption_Text").parent().hide();
 $("#AdvancedLink_ExternalUrl_Value").parent().parent().show();
 $("#AdvancedLink_UrlBancaDati_Value").parent().parent().hide();
 break;
 case "Internal":
 $("#AdvancedLink_ExternalUrl_Value").parent().parent().hide();
 $(".content-picker-field[data-field-name=''InternalContent'']").show()
 $("#AdvancedLink_Caption_Text").parent().show();
 $("#AdvancedLink_UrlBancaDati_Value").parent().parent().hide();
 break;
 case "Banca dati":
 $("#AdvancedLink_ExternalUrl_Value").parent().parent().hide();
 $(".content-picker-field[data-field-name=''InternalContent'']").hide()
 $("#AdvancedLink_Caption_Text").parent().hide();
 $("#AdvancedLink_UrlBancaDati_Value").parent().parent().show();
 break;
 default:
 $("#AdvancedLink_ExternalUrl_Value").parent().parent().hide();
 $(".content-picker-field[data-field-name=''InternalContent'']").hide()
 $("#AdvancedLink_Caption_Text").parent().hide();
 $("#AdvancedLink_UrlBancaDati_Value").parent().parent().hide();
 break;
 }
 }
</script>

" InsertStuffFieldSettings.OnFooter="true" />', 7, 51)
The INSERT is correct, if i run it with SSMS or Azure Data Studio it works.
I found on internet various articles with similar error messages but no solutions that worked for me.
Any ideas?
答案1
得分: 1
SQLCMD具有一种变量机制,格式为$(variable_name),可以在运行时替换。
我的数据不应该是这些变量,会导致机制受骗并引发错误。
解决方案是使用-x选项,该选项会抑制变量替换机制(请参考https://learn.microsoft.com/it-it/sql/tools/sqlcmd/sqlcmd-utility?view=sql-server-ver16以供参考)。
英文:
It come out that SQLCMD has a mechanism of variables with the format $(variable_name) that can be replaced at run time .
My data are not meant to be such variables, with the effect of fooling the mechanism and cause the error.
The solution is to use the -x option which suppresses the variable substitution mechanism (for reference see https://learn.microsoft.com/it-it/sql/tools/sqlcmd/sqlcmd-utility?view=sql-server-ver16).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论