数据库部署(vsdbcmd.exe):DatabaseName 和 DefaultDataPath 被忽略?

发布于 2024-07-16 07:12:21 字数 1392 浏览 2 评论 0原文

Visual Studio 数据库版本附带一个工具 vsdbcmd.exe,它应该允许某人将 .dbschema 文件(由数据库项目在构建时生成)部署到数据库。 它通过首先构建脚本,然后执行它来实现此目的:

vsdbcmd.exe /a:部署 /cs:"数据源=(本地);集成安全性=True;池=False" /dsp:Sql /dd /model:"..\Database.dbschema" /p: TargetDatabase=TargetDB /manifest:"..\Database.deploymanifest"

我希望它可以毫无问题地将脚本部署到不同的数据库服务器。 但是,实际 .mdf 文件的完整路径以及对原始数据库的一些其他引用都编码在脚本中。 要么没有选项可以控制它,要么我找不到它。

有人用这个吗? 你如何部署? 我是否应该使用不同类型的数据库项目(我记得在“数据库项目”和“服务器项目”之间有选择方式,但我不知道这是否重要)?

编辑

我可以很好地覆盖 .sqlcmdvars,但这并不能解决问题。 这是使用上面的命令从生成的 .sql 文件中提取的内容:

GO
:setvar DatabaseName "TargetDB"
:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\"

因此,“targetdb”目标数据库被正确记录。 但是,再多写几行:

CREATE DATABASE [$(DatabaseName)]
ON 
PRIMARY(NAME = [Original], FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Original.mdf', SIZE = 3072 KB, MAXSIZE = UNLIMITED, FILEGROWTH = 1024 KB)
LOG ON (NAME = [Original_log], FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Original_log.ldf', SIZE = 1024 KB, MAXSIZE = 2097152 MB, FILEGROWTH = 10 %)

其中 Original.mdf 是原始数据库的名称(即我们在开发过程中部署的数据库,在数据库项目的项目属性中设置)。 这是部署失败的地方,要么是因为目标计算机上的确切路径可能不同,要么是因为该数据库已存在而在我的计算机上。

这些值似乎只是硬编码在生成的脚本中。

Visual Studio database edition comes with a tool, vsdbcmd.exe, that should allow someone to deploy a .dbschema file (which is generated by the database project on build) to a database. It does this by first building the script, then executing it:

vsdbcmd.exe /a:Deploy /cs:"Data Source=(local);Integrated Security=True;Pooling=False" /dsp:Sql /dd /model:"..\Database.dbschema" /p:TargetDatabase=TargetDB /manifest:"..\Database.deploymanifest"

I would expect that it can deploy the script to a different database server without problems. However, the complete path to the actual .mdf file is encoded in the script, along with some other references to the original databse. Either there isn't an option to control this, or I can't find it.

Is anyone using this? How do you deploy? Should I have used a different kind of database project (I remember having the choice way back when between "Database project" and "Server project", but I don't know whether that matters)?

EDIT

I can override the .sqlcmdvars just fine, but this does not solve the problem. This is an extract from the generated .sql file using a command like above:

GO
:setvar DatabaseName "TargetDB"
:setvar DefaultDataPath "C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\"

So there is the "targetdb" target database gets recorded correctly. But, a few lines further:

CREATE DATABASE [$(DatabaseName)]
ON 
PRIMARY(NAME = [Original], FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Original.mdf', SIZE = 3072 KB, MAXSIZE = UNLIMITED, FILEGROWTH = 1024 KB)
LOG ON (NAME = [Original_log], FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Original_log.ldf', SIZE = 1024 KB, MAXSIZE = 2097152 MB, FILEGROWTH = 10 %)

where Original.mdf is the name of the original database (i.e. the db where we deploy during development, and that is set in the project properties of the database project). This is where the deployment fails, either because that exact path may be different on the target machine, or on my machine because that db already exists.

These values just seem hardcoded in the generated script.

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

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

发布评论

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

评论(2

多情癖 2024-07-23 07:12:21

这可能是在执行数据库模式同步时引起的 -> 数据库项目。 (我的环境是VS2010 Enterprise RTM)。

生成的 ALTER DATABASE 语句是为了镜像数据库而生成的,而不考虑任何替换值(它还包括初始数据库大小等)。 初始数据库导入时不会出现该问题。

下找到的文件

编辑在... Schema Objects\Database Level Objects\Storage\Files

...并修复它们以包含正确的$(DefaultDataPath)$(DatabaseName).mdf/$(DefaultLogPath)$(DatabaseName)_log.ldf 值或其他适当的值。 (现在在架构比较中将它们标记为“跳过”:-P)

通过上述“更正”,将值保留在外部将再次起作用,并且是管理此类属性的首选方法。

快乐编码。

This can be (is) caused when doing a Database Schema Synchronization -> Database Project. (My environment is VS2010 Enterprise RTM).

The generated ALTER DATABASE statements are generated to mirror the source database without taking any substitution values into account (it will also include initial database sizes, etc). The problem does not appear on an Initial Database Import.

Edit the files found under...

Schema Objects\Database Level Objects\Storage\Files

...and fix them to contain the correct $(DefaultDataPath)$(DatabaseName).mdf/$(DefaultLogPath)$(DatabaseName)_log.ldf values -- or other -- as appropriate. (Now mark them as "Skip" in your Schema Compare :-P)

With the above "correction" keeping the values external will once again work and is the preferred method of managing such properties.

Happy coding.

我是男神闪亮亮 2024-07-23 07:12:21

根据您的编辑,这也许会有帮助。
https://blogs.msdn.com/gertd/Default.aspx?p= 7

添加变量

到目前为止,我们一直在研究事情是如何工作的,现在是时候添加一些新变量并使它们发挥作用了。 变量派上用场的地方之一是定义文件的部署后文件:storage.sql。 变量将允许使用来使位置环境相关。

在存储文件中,您会发现类似以下内容:

IF NOT EXISTS(SELECT 1 FROM dbo.sysfiles WHERE name = 'fgdb_data')
开始
更改数据库 [$(数据库名称)]
添加文件

NAME = N'fgdb_data',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\fgdb_data.ndf',
最大大小 = 100MB,
文件增长 = 10MB

至文件组 [表]
我们可以对其

进行参数化,以便通过变量将驱动器和目录抽象为:

:setvardrive "C:"
:setvar 目录 "Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA"

IF NOT EXISTS(SELECT 1 FROM dbo.sysfiles WHERE name = 'fgdb_data')
开始
更改数据库 [$(数据库名称)]
添加文件

NAME = N'fgdb_data',
FILENAME = N'$(驱动器)\$(目录)\fgdb_data.ndf',
最大大小 = 100MB,
文件增长 = 10MB

至文件组 [表]
现在

我们已经对脚本进行了参数化,接下来我们希望将变量作为项目文件的一部分,因此我们将它们定义在一个位置,而不是通过 :setvar 语句分散在代码中的各个位置。

抱歉,我自己刚刚开始学习东德,但我需要这个问题的答案

Based on your edit, perhaps this is helpful.
https://blogs.msdn.com/gertd/Default.aspx?p=7

Adding variables

So far we have been looking at how things work, now it is time to add some new variables and put them to work. One place where variables come in handy is in the post deployment file that defines files: storage.sql. Variables will allow use to make the location environment dependent.

Inside the storage file you will find something like this:

IF NOT EXISTS(SELECT 1 FROM dbo.sysfiles WHERE name = 'fgdb_data')
BEGIN
ALTER DATABASE [$(databasename)]
ADD FILE
(
NAME = N'fgdb_data',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\fgdb_data.ndf',
MAXSIZE = 100MB,
FILEGROWTH = 10MB
)
TO FILEGROUP [TABLES]
END

We could parameterize this so the drive and directory get abstracted through a variable to:

:setvar drive "C:"
:setvar directory "Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA"

IF NOT EXISTS(SELECT 1 FROM dbo.sysfiles WHERE name = 'fgdb_data')
BEGIN
ALTER DATABASE [$(databasename)]
ADD FILE
(
NAME = N'fgdb_data',
FILENAME = N'$(drive)\$(directory)\fgdb_data.ndf',
MAXSIZE = 100MB,
FILEGROWTH = 10MB
)
TO FILEGROUP [TABLES]
END

Now that we have parameterized the script, next we want to make the variables part of the project file, so we have them defined in a single place instead of scattered around in the code at various places through :setvar statements.

Sorry I am just starting to learn the GDR myself but I'll need the answer to this to

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