[英]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.