【问题标题】:Why is my Deployment script causing me errors?为什么我的部署脚本会导致我出错?
【发布时间】:2016-02-10 13:47:47
【问题描述】:

我正在 Visual Studio 2012 中处理一个项目。最近,我在解决方案中添加了一个数据库项目。在我将数据库添加到解决方案之前,该数据库已经存在并且一切正常。 但是,现在,当我尝试运行应用程序时出现错误。这些错误是由名为 [database name].sql 的计算机生成文件引起的。在图块的顶部,写着:

/*
Deployment script for [the database name here]

This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/

每次应用程序运行时都会重新创建此文件。发生的错误似乎是语法错误。我无法修复它们,因为我对文件所做的任何更改都无关紧要,因为每次运行都会生成一个新文件并且错误会重新出现。

我尝试在网上进行更多调查,但遇到了麻烦。这对我来说都是新的。

以下是一些正在创建的错误:

GO
:setvar DatabaseName "(the database name is here)"

这给了我三个错误:

Error   88  SQL80001: Incorrect syntax near ':'.    
Error   89  SQL80001: 'DatabaseName' is not a recognized option.
Error   90  SQL80001: Incorrect syntax near '"(the database name is here in the code)"'.    

另外,还有一行代码如下:

CREATE USER [(the domain)\(the username)] FOR LOGIN [(the domain)\(the username)];


GO

这给出了以下错误:

Error   119 SQL72014: .Net SqlClient Data Provider: Msg 15401, Level 16, State 1, Line 1 Windows NT user or group '(the domain)\(the username)' not found. Check the name again.    

【问题讨论】:

  • 也许包括实际错误可能会有所帮助。 stackoverflow.com/help/how-to-ask
  • 有什么错误?即使生成错误的代码不能直接更改,也将有另一种方法来确保生成的代码是正确的。
  • 更新:包含错误

标签: sql database visual-studio stored-procedures deployment


【解决方案1】:

从您发布的错误看来,有两个问题:

  1. Windows NT user or group '(the domain)\(the username)' not found. - 用于访问数据库的用户不存在。由于它是 Windows 用户,我猜它使用当前用户的凭据。

    确保您的 SQL 实例可以接受 Windows 登录,并且您(以及构建该软件的任何其他人)拥有必要的访问权限。

  2. 'DatabaseName' is not a recognized option. - 这很可能也是由第一个问题引起的,但请仔细检查数据库是否存在。

【讨论】:

    【解决方案2】:

    该错误消息最近引起了我的注意,因为它根本与我的问题的原因无关。原来我的 SQL 脚本写错了(就我而言 - 我忘了在我的 PK 列中添加 IDENTITY (1,1))。

    对我来说,这个故事的寓意是首先在 SSMS 中测试 SQL 数据文件。

    【讨论】:

      猜你喜欢
      • 2012-09-28
      • 1970-01-01
      • 1970-01-01
      • 2012-12-24
      • 2021-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-11
      相关资源
      最近更新 更多