Visual Studio 2010 - 无法构建包含导入数据库的数据库项目

发布于 2024-10-27 21:57:52 字数 352 浏览 1 评论 0原文

我正在查看 VS2010 中的数据库项目,我的想法是我想要一些可以用来跟踪数据库架构(在源代码控制中)以及生成“新安装”脚本和更改脚本的能力。

当我创建新的数据库项目向导并导入现有的数据库架构时,它不会“构建”。我收到错误:

SQL03006:用户:[扫描仪]有一个 未解决的登录引用 [扫描仪]。

产生此错误的 SQL:

创建用户[扫描仪]用于登录 [扫描仪];

用户“scanner”是我导入的数据库中定义的登录名。我不知道它在告诉我什么,谷歌也没有给出太多信息。有什么想法吗?

I'm looking at the Database Project in VS2010, the idea being that I want something I can use to keep track of the database schema (in source control) and the ability to generate "new install" scripts, and change scripts.

When I create a new database project wizard and import my existing database schema, it won't "build". I get the error:

SQL03006: User: [scanner] has an
unresolved reference to Login
[scanner].

The SQL that generates this error:

CREATE USER [scanner] FOR LOGIN
[scanner];

The user "scanner" is a login defined in the database I imported. I have no idea what it's teling me, and google isn't throwing much up. Any ideas?

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

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

发布评论

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

评论(5

老娘不死你永远是小三 2024-11-03 21:57:52

登录名实际上是在服务器安装的主数据库中定义的。 CREATE USER 语句需要指向现有的登录名,否则会出错。数据库项目不知道服务器级别的登录。您可以创建一个服务器项目来处理登录,也可以关闭对数据库项目中的安全对象的检查。有关更多详细信息,请参阅 Demetri M 的答案: http://social.msdn.microsoft.com/Forums/eu/vstsdb/thread/1f8226fe-b791-4344-8735-3d38307e8664

The Login is actually defined in the master database of the server install. The CREATE USER statement needs to point at an existing Login otherwise it errors. The Database Project is not aware of the Login at the server level. Either you can create a Server Project to handle the Logins, or you can turn off the checking of Security objects in your Database Project. See the answer by Demetri M for more details: http://social.msdn.microsoft.com/Forums/eu/vstsdb/thread/1f8226fe-b791-4344-8735-3d38307e8664

她说她爱他 2024-11-03 21:57:52

我正在将 Visual Studio 2012 用于 SQL Server 2008 R2 数据库项目。 @Judah 列出的选项似乎不再起作用。

它们现在似乎是您在进行架构比较时配置的设置:

右键单击数据库项目>
选择“架构比较”>
选择“设置”齿轮图标 >
选择“对象类型”选项卡 >

登录不属于应用程序范围。数据库角色、权限、角色成员身份和用户都属于应用程序范围。

不幸的是,我能找到保留这些的唯一方法是保存模式比较。如果您在团队中共享此内容并且希望对任何模式比较进行项目/数据库(或服务器)设置,这可能会有点不方便。

不过,它完成了工作。

I'm using Visual Studio 2012 for a SQL Server 2008 R2 database project. The options listed by @Judah don't appear to work anymore.

They now appear to be Settings that you configure while doing a Schema Compare:

Right click database project >
Choose 'Schema Compare' >
Choose the 'Settings' gear icon >
Choose the 'Object Types' tab >

Logins are Non-Application-scoped. Database roles, Permissions, Role Memberships, and Users are all Application-scoped.

Unfortunately, the only way that I can find to preserve these is to save the schema compare. This can be a little inconvenient if you're sharing this on a team and would like project/database (or server) settings for any schema compare.

It gets the job done, though.

我很坚强 2024-11-03 21:57:52

您可以更改创建用户脚本来创建角色。
因此,而不是“创建用户 userName 用于登录 loginName;”

使用“创建角色[用户名]授权dbo;”

这是一个 hack,但只要您不必处理项目中的用户和角色,您就可以愉快地执行以下操作:

GRANT EXECUTE
ON OBJECT::[dbo].[sp_name] TO [用户名];

You can change the create user scripts to create roles.
So instead of "Create user userName for login loginName;"

use "Create Role [userName] authorization dbo;"

This is a hack, but as long as you aren't having to deal with users and roles in your project, you can happily do the following:

GRANT EXECUTE
ON OBJECT::[dbo].[sp_name] TO [userName];

养猫人 2024-11-03 21:57:52

显然,这个问题在 VS2017 数据库项目上仍然出现。

我已经通过首先创建登录名然后创建用户来解决这个问题。

    -- Windows Account
    CREATE LOGIN [Domain\Username]
    FROM WINDOWS WITH DEFAULT_LANGUAGE = [us_english];

    GO

    CREATE USER [Domain\Username] FOR LOGIN [Domain\Username];
    GO

    -- Sql Acccount

    CREATE LOGIN [sql_account] WITH PASSWORD = 'Ch@ngeth1spA$swurD'
    GO

    CREATE USER [sql_account]
    FROM LOGIN [sql_account]
    WITH DEFAULT_SCHEMA = dbo

    GO



    -- Then set the sql file Build Action to "Build"

Apparently, this issue is still occurring on VS2017 database projects as well.

I've managed to solve it by first creating the login and then create the user.

    -- Windows Account
    CREATE LOGIN [Domain\Username]
    FROM WINDOWS WITH DEFAULT_LANGUAGE = [us_english];

    GO

    CREATE USER [Domain\Username] FOR LOGIN [Domain\Username];
    GO

    -- Sql Acccount

    CREATE LOGIN [sql_account] WITH PASSWORD = 'Ch@ngeth1spA$swurD'
    GO

    CREATE USER [sql_account]
    FROM LOGIN [sql_account]
    WITH DEFAULT_SCHEMA = dbo

    GO



    -- Then set the sql file Build Action to "Build"
七月上 2024-11-03 21:57:52

在数据库项目中打开“Security”文件夹(假设这就是数据库的导入方式)。对于导致问题的每个用户配置文件,在属性面板中将构建操作设置为“无”。您还必须从它们出现的任何其他文件中删除它们,包括 Permissions.sql 和 RoleMemberships.sql。

输入图片此处描述

In the database project open the 'Security' folder (assuming that's how your database was imported). For each user profile that is causing an issue, set the build action to 'None' in the properties panel. You will also have to remove them from any other files in which they appear, including Permissions.sql and RoleMemberships.sql.

enter image description here

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