.net - 在 VS2010 数据库项目中部署时设置 DefaultDataPath 和 DefaultLogPath

标签 .net visual-studio-2010 sql-server-2008 sql-server-2005 database-project

说实话,以下查询最初不是我的,但我在工作中面临着确切的问题。从而按原样复制问题陈述。我无法找到任何解决方案。我非常感谢以下问题集的任何建议或亮点:

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?

最佳答案

在 Visual Studio 2010 中,有一个名为“CommentOutSetVarDeclarations”的项目设置。如果您选中此选项,您提到的两个默认 SETVAR 行将被注释掉。

这使您能够在从 SQLCMD 运行部署脚本时从命令行提供 $(DefaultDataPath) 和 $(DefaultLogPath) 的值。

关于.net - 在 VS2010 数据库项目中部署时设置 DefaultDataPath 和 DefaultLogPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10085124/

相关文章:

c# - 核心 3.1 - 绑定(bind) Body 中的一些属性和 Header 中的其他一些属性

c# - Collection<T>的IEnumerable的实现在哪里

asp.net-mvc - Windows XP上的Visual Studio 2010突然崩溃,然后停止工作,直到重新安装

c# - 在用户控件中更改默认背景颜色的问题

jquery - Visual Studio 2010 附带 jQuery 支持吗?

c# - 我们如何更改 SQL Server(2008) 数据库的日期格式?

c# - ASP.NET Web 应用程序 - 在部署时,System.Speech.dll 对象未设置为对象的实例

c# - 如何检测 C++ 标识符字符串?

java - SQL Server 2008 的 JDBC 驱动程序

sql - 得到两个计数,然后将它们相除