简体   繁体   English

Visual Studio-部署数据库-数据库参数

[英]Visual Studio - deploy database - Database parameters

At the moment, I am deploying to a server, and part of the deployment, when publishing from Visual studio, calls a script that adds a user to a group: 目前,我正在部署到服务器,从Visual Studio中发布时,部署的一部分会调用将用户添加到组的脚本:

ALTER ROLE [geodeveloper] ADD MEMBER [OTWGEODI01\GEO Application Developers];

The server I am using is called OTWGEODI01 我正在使用的服务器称为OTWGEODI01

However, I create a new publish profile that points to OTWGEODI02 - but the script above fails, as there is now member OTWGEODI01\\GEO Application Developers 但是,我创建了一个指向OTWGEODI02的新发布配置文件-但是上面的脚本失败了,因为现在有成员OTWGEODI01\\GEO Application Developers

Is there a way I can have a parameter as part of the publish that changes this value in the script? 有没有一种方法可以让我在发布中将参数更改为脚本中的该值?

I tried to add properties to my database solution, but adding a cariable called ServerName. 我试图向数据库解决方案中添加属性,但添加了一个名为ServerName的可移植对象。 I set it to 'OTWGEODI02'. 我将其设置为“ OTWGEODI02”。 I then went to one of my scripts that had a direct reference to the server name: 然后,我转到直接引用服务器名称的脚本之一:

ALTER ROLE [geodeveloper] ADD MEMBER [OTWGEODI01\GEO Application Developers];

And replaced it with: 并替换为:

ALTER ROLE [geodeveloper] ADD MEMBER [[$(ServerName)\GEO Application Developers];

But it tells me I have an Invalid Syntax near '\\' 但这告诉我'\\'附近有无效的语法

Can you see an error I am making? 您能看到我犯的错误吗? Also, every time I need to publish to different environment, I will need to go and update the database properties? 另外,每次需要发布到不同的环境时,都需要去更新数据库属性吗? Or can that somehow be based on the .publish file I am using. 或者可以某种方式基于我正在使用的.publish文件。 (I have a .publish file per database). (我每个数据库都有一个.publish文件)。 Maybe I can end up with one publish file, and somehow select the Solution Configurations and add my environments there? 也许我可以得到一个发布文件,然后以某种方式选择“解决方案配置”并在其中添加我的环境?

Edit: 编辑:

Results in a publish error saying: 导致发布错误,提示:

SQL72014: .Net SqlClient Data Provider: Msg 15401, Level 16, State 1, Line 1 Windows NT user or group '($ServerName)\\GEO Application Developers' not found. SQL72014:.Net SqlClient数据提供程序:消息15401,级别16,状态1,行1 Windows NT用户或组“($ ServerName)\\ GEO应用程序开发人员”未找到。 Check the name again. 再次检查名称。

CREATE USER [($ServerName)\GEO Application Developers] FOR LOGIN [($ServerName)\GEO Application Developers];

It didn't seem to replace the variable... 它似乎没有取代变量...

Also: 也:

CREATE USER [$(ServerName)\GEO Application Developers] FOR LOGIN [$(ServerName)\GEO Application Developers];

Results in a built time error saying that I can't put parameters here. 导致建立时间错误,提示我无法在此处放置参数。

You can define variables in the Project properties (defining a new variable in the SQLCMD Variables tab). 您可以在“项目”属性中定义变量(在“ SQLCMD变量”选项卡中定义新变量)。 Then you can use this variable in your scripts (like [$(ServerName)]). 然后,您可以在脚本中使用此变量(例如[$(ServerName)])。
While publishing, you can set different values depending on the server you want it to publish to. 发布时,您可以根据要发布到的服务器设置不同的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 部署Visual Studio 2010数据库项目 - Deploy Visual Studio 2010 Database Project Visual Studio Web部署后清空数据库表 - Empty database tables after Visual Studio Web Deploy Visual Studio数据库项目+部署+ TFS构建+多租户 - Visual Studio Database Project + Deploy + TFS Build + Multi Tenancy 将 Visual Studio 数据库项目对象部署到“dbo”以外的架构 - Deploy Visual Studio Database Project Objects to Schema other than “dbo” Visual Studio 数据库项目不会部署到 SQL Azure - Visual Studio database project won't deploy to SQL Azure 数据库“master”中的CREATE DATABASE权限被拒绝 - 使用Web Deploy,EF Code First,Visual Studio - CREATE DATABASE permission denied in database 'master' - using Web Deploy, EF Code First, Visual Studio 数据库未连接到Visual Studio - Database is not connecting to visual studio 使用Visual Studio 2012将带有sql数据库的Windows窗体应用程序部署到另一台PC - deploy a windows form application with sql database to another PC using visual studio 2012 SQL Server数据库项目:在预部署脚本上获取Visual Studio程序集版本 - SQL Server Database Project: Get Visual Studio Assembly Version on Pre-Deploy Scripts 如何在数据库项目中使用SqlFunctionAttribute 生成SQL 来自己部署函数? Visual Studio 失败 - How can I use the SqlFunctionAttribute in a database project to generate the SQL to deploy the functions myself? Visual studio fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM