在VS2010数据库项目设置DefaultDataPath和DefaultLogPath上部署数据库、项目、DefaultDataPath、DefaultLogPath

2023-09-03 22:11:34 作者:ˉ人情淡薄怎抵世态炎凉

要为真下面的查询是不是本来我的,但我在我的工作所面临的具体问题。就这样复制问题的声明,因为它是。我无法找到任何解决方案。我真的AP preciate以下习题集的任何建议或亮点:

  

我没有在模式中的任何硬编码对象\数据库级   对象\存储\文件 - 无论是在数据库和日志文件

     

获取生成当我点击的部署部署脚本   DB项目有硬编码在:SETVAR与数据库和日志文件的路径   分配给$(DefaultDataPath)和$(DefaultLogPath) - 见下图:   :SETVAR DefaultDataPathC:\ DB \的Microsoft SQL   服务器\ MSSQL10_50.MITCHELL \ MSSQL \ DATA \​​:SETVAR DefaultLogPath   C:\ DB \ Microsoft SQL Server的\ MSSQL10_50.MITCHELL \ MSSQL \ DATA \。

     

我想部署脚本接受输入数据和日志路径。   但基于该当前正在生成的脚本,我得   手动评论上述2线和更改的CREATE DATABASE   如每一次下面的语句替换任何引用   DefaultDataPath和DefaultLogPath与InputDefaultDataPath和   InputDefaultLogPathCREATE DATABASE [$(数据库名)]       上       PRIMARY(NAME = [TEST_DB]中,filename ='$(InputDefaultDataPath)$(数据库名).MDF'> SIZE = 3072 KB,   FILEGROWTH = 1024 KB)       LOG ON(NAME = [TEST_DB_log]中,filename =>'$(InputDefaultLogPath)$(数据库名)_log.ldf',SIZE = 1024 KB,   MAXSIZE = 2097152 MB,FILEGROWTH = 10%)COLLATE   SQL_Latin1_General_CP1_CI_AS

 问题1:如何从脚本下面两行prevent DB项目,也
 

     

$ P $从subsituting这些变量pvent它   CREATE DATABASE语句? :SETVAR DefaultDataPathC:\ DB \微软   SQL Server的\ MSSQL10_50.MITCHELL \ MSSQL \ DATA \​​:SETVAR DefaultLogPath   C:\ DB \ Microsoft SQL Server的\ MSSQL10_50.MITCHELL \ MSSQL \ DATA \。

     

问题2:如何使数据库项目automaticaly脚本部署   以这样的方式脚本,它接受用户输入的DefaultDataPath   和DefaultLogPath没有我手动更改它包括   $(InputDefaultDataPath)和$(InputDefaultLogPath)变量?

解决方案 VS2010中Database项目模板统一管理数据库对象

在Visual Studio 2010中,有一个项目设置所谓的CommentOutSetVarDeclarations。如果选中此选项,你提到的两个默认SETVAR线将被注释掉。

这使您可以通过命令行从SQLCMD运行部署脚本时提供的$(DefaultDataPath)和$(DefaultLogPath)值。

To be true the following query is not originally mine, but I am facing the exact issue in my work. And thus copying the problem statement as it is. I am not able to find any solution. I would really appreciate any suggestions or highlights of the following Problem Set:

I do not have any hardcoding in Schema Objects\Database Level Objects\Storage\Files - both in database and log files.

The deployment script that gets generated when I click "deploy" from db project has hardcoding in :SETVAR with database and log file path assigned to $(DefaultDataPath) and $(DefaultLogPath) - see below: :setvar DefaultDataPath "C:\DB\Microsoft SQL Server\MSSQL10_50.MITCHELL\MSSQL\DATA\" :setvar DefaultLogPath "C:\DB\Microsoft SQL Server\MSSQL10_50.MITCHELL\MSSQL\DATA\".

I want the deployment script to accept input for data and log path. But based on script that is being currently generated, I'll have to manually comment the above 2 lines and modifiy the CREATE DATABASE statement as shown below every single time to replace any reference to "DefaultDataPath" and "DefaultLogPath" with "InputDefaultDataPath" and "InputDefaultLogPath" CREATE DATABASE [$(DatabaseName)] ON PRIMARY(NAME = [TEST_DB], FILENAME = '$(InputDefaultDataPath)$(DatabaseName).mdf', >SIZE = 3072 KB, FILEGROWTH = 1024 KB) LOG ON (NAME = [TEST_DB_log], FILENAME = >'$(InputDefaultLogPath)$(DatabaseName)_log.ldf', SIZE = 1024 KB, MAXSIZE = 2097152 MB, FILEGROWTH = 10 %) COLLATE SQL_Latin1_General_CP1_CI_AS

 Question 1: How do I prevent db project from scripting the below two lines and also 

prevent it from subsituting these variables in CREATE DATABASE statement? :setvar DefaultDataPath "C:\DB\Microsoft SQL Server\MSSQL10_50.MITCHELL\MSSQL\DATA\" :setvar DefaultLogPath "C:\DB\Microsoft SQL Server\MSSQL10_50.MITCHELL\MSSQL\DATA\".

Question 2: How do I make db project to automaticaly script deployment script in such a way that it accepts user input for DefaultDataPath and DefaultLogPath without me manually changing it to include $(InputDefaultDataPath) and $(InputDefaultLogPath) variable?

解决方案

In visual studio 2010, there is a project setting called 'CommentOutSetVarDeclarations'. If you check this option, the two default SETVAR lines you mention will be commented out.

This enables you to supply values for $(DefaultDataPath) and $(DefaultLogPath) from the command line when running the deployment script from SQLCMD.