【问题标题】:Trying to publish SQL DB on Visual Studio, I keep getting SQL72025 error尝试在 Visual Studio 上发布 SQL DB,我不断收到 SQL72025 错误
【发布时间】:2022-12-17 18:21:34
【问题描述】:

我正在尝试使用 Visual Studio 发布数据库,该项目没有问题,而且我下载了(数据存储和处理)工具集。然而,每次我尝试部署项目时,我都会收到 SQL:72025 错误。

SQL:72025: 引用的程序集 .DLL 已损坏或无效。

如果我也尝试构建项目,我会收到相同的消息。现在我注意到,通常我们在解决方案资源管理器下点击发布时会弹出一个窗口来配置目标数据库设置,我没有看到那个窗口,而是直接执行项目并失败。

数据库没有什么复杂的,它只是 4 个表和 1 个部署后脚本

Screenshot of the solution

这里还有数据库的脚本供您参考

CREATE TABLE [dbo].[RoomTypes]
(
    [Id] INT NOT NULL PRIMARY KEY IDENTITY,
    [Title] NVARCHAR(50) NOT NULL,
    [Description] NVARCHAR(MAX) NOT NULL, 
    [RoomPrice] MONEY NOT NULL, 
)

CREATE TABLE [dbo].[RoomDetails]
(
    [Id] INT NOT NULL PRIMARY KEY IDENTITY,
    [RoomTypeID] INT NOT NULL, 
    [RoomNumber] NVARCHAR(10) NOT NULL, 
    [Available] BIT NOT NULL, 
    CONSTRAINT [FK_RoomDetails_RoomTypes] FOREIGN KEY ([RoomTypeID]) REFERENCES RoomTypes(Id)
)

CREATE TABLE [dbo].[GuestDetails]
(
    [Id] INT NOT NULL PRIMARY KEY IDENTITY, 
    [FristName] NVARCHAR(50) NOT NULL, 
    [LastName] NVARCHAR(50) NOT NULL, 
    [Phone] NVARCHAR(50) NULL, 
    [Email] NVARCHAR(50) NULL
)

CREATE TABLE [dbo].[BookingDetails]
(
    [Id] INT NOT NULL PRIMARY KEY IDENTITY, 
    [FromDate] DATETIME2 NOT NULL, 
    [ToDate] DATETIME2 NOT NULL,
    [CheckIn] BIT NOT NULL DEFAULT 0, 
    [TotalCost] MONEY NOT NULL, 
    [GuestId] INT NOT NULL, 
    [RoomId] INT NOT NULL
    CONSTRAINT [FK_BookingDetails_GuestDetails] FOREIGN KEY ([GuestId]) REFERENCES GuestDetails(Id), 
    CONSTRAINT [FK_BookingDetails_RoomDetails] FOREIGN KEY ([RoomId]) REFERENCES RoomDetails(Id)
)

/*
Post-Deployment Script Template                         
--------------------------------------------------------------------------------------
 This file contains SQL statements that will be appended to the build script.       
 Use SQLCMD syntax to include a file in the post-deployment script.         
 Example:      :r .\myfile.sql                              
 Use SQLCMD syntax to reference a variable in the post-deployment script.       
 Example:      :setvar TableName MyTable                            
               SELECT * FROM [$(TableName)]                 
--------------------------------------------------------------------------------------
*/

if not exists (Select 1 from dbo.RoomTypes)
begin 
 insert into dbo.RoomTypes (Title,Description) values 
                           ('King Size Bed', 'A room with a king-size bed and a nice view'),
                           ('Two Queen Size Bed', 'A room with two queen-size beds and a nice view'),
                           ('Executive Suite', 'Two rooms, each with a King-size bed and a nice view');
end

if not exists (select 1 from dbo.RoomDetails)
begin
    declare @roomId1 int;
    declare @roomId2 int;
    declare @roomId3 int;

    select @roomId1 = Id from dbo.RoomTypes  where Title = 'King Size Bed';
    select @roomId2 = Id from dbo.RoomTypes  where Title = 'Two Queen Size Bed';
    select @roomId3 = Id from dbo.RoomTypes  where Title = 'Executive Suite';

insert into dbo.RoomDetails (RoomNumber,RoomTypeID,Available) values 
    ('101',@roomId1,1),
    ('102',@roomId1,1),
    ('202',@roomId1,1),
    ('105',@roomId2,1),
    ('205',@roomId2,1),
    ('505',@roomId3,1);

end

我还检查了下面的帖子,但解决方案对我不起作用,而且出现相同错误的原因也不同。 SQL:72025: The referenced assembly .DLL is corrupt or invalid

错误可能是因为我正在使用 parallels 桌面应用程序吗?我使用的 mac 是 intel mac。

谢谢你们。

【问题讨论】:

    标签: c# sql sql-server visual-studio asp.net-core


    【解决方案1】:

    你的问题是插入房间类型

    你设置 [RoomPrice] MONEY NOT NULL,

    但是当你将它插入你的数据库时,你在插入时没有价格,因为该列不允许 NULL 值,它会产生错误

    所以将您的插入更改为

    if not exists (select 1 from dbo.RoomDetails)
    begin 
    DECLARE @a int;
    SET @a =  1
     insert into dbo.RoomTypes (Title,Description,RoomPrice) values 
                               ('King Size Bed', 'A room with a king-size bed and a nice view',100),
                               ('Two Queen Size Bed', 'A room with two queen-size beds and a nice view',200),
                               ('Executive Suite', 'Two rooms, each with a King-size bed and a nice view',300);
    end
    

    这是example fiddle

    【讨论】:

    • 谢谢@nbk 的评论。我只是更改了所有表以允许空值,当然除了 ID 并添加了您在后记中提到的代码(添加房价)仍然如此,我遇到了同样的错误。
    • @IyadDante 不要那样做,除非您知道要存储空值,否则最好有一个列NOT NULL。另外 money 是一个糟糕的数据类型选择,它有舍入问题
    • 你没有提到有问题的dll,但你应该检查它是否与你的系统兼容
    • @Charlieface 好的,我会注意的。太感谢了。
    • @nbk 错误消息说这是一个 DLL 问题。所以你认为这是一个兼容性问题?我觉得问题出在点击publish时没有得到目标数据库配置窗口,代码直接执行了,还是你觉得这个错误与此无关?
    【解决方案2】:

    我只是想让大家知道我在这里遇到的问题是因为我使用的是 Parallels Desktop for mac。我在 Windows PC 上做了同样的事情,一切都很好。因此,如果有人计划使用 Desktop for mac 来开发 .net 应用程序,尽管它是一个非常强大的应用程序,但我个人建议坚持使用 Windows PC 来这样做。

    【讨论】:

      猜你喜欢
      • 2019-07-19
      • 2019-05-15
      • 2019-07-01
      • 2014-10-21
      • 1970-01-01
      • 2016-08-31
      • 2018-02-02
      • 2011-10-29
      • 2020-12-02
      相关资源
      最近更新 更多