我有一个非常奇怪的错误。我正在尝试运行一个存储过程,它在我们的生产环境中完美运行。现在,在我们的测试服务器上,我收到Invalid object name 'master.dbo.TsqlSplit'.
错误。
我有下面的代码,它在执行标量时失败(并给出无效错误)。
bool res = false;
using (
var conn =
new SqlConnection(
ConfigurationManager.ConnectionStrings["VirksomhedsborsRestrictedAccess"].ConnectionString))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "dbo.Saxis_UpdateCreateAdvert";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@AdvertId", SqlDbType.Int).Value = this.AdvertID;
//this.ActivatedDate;
cmd.Parameters.Add("@Address", SqlDbType.NVarChar, 200).Value = this.Address.NullToDbNull();
cmd.Parameters.Add("@AdvertLevel", SqlDbType.Int).Value = this.AdvertLevel.NullToDbNull();
cmd.Parameters.Add("@AdvertType", SqlDbType.NVarChar, 200).Value = this.AdvertTypeRaw.NullToDbNull();
cmd.Parameters.Add("@BusinessEntityType", SqlDbType.Int).Value = this.BusinessEntityType.NullToDbNull();
cmd.Parameters.Add("@CanMove", SqlDbType.Bit).Value = this.CanMove.NullToDbNull();
cmd.Parameters.Add("@City", SqlDbType.NVarChar, 200).Value = this.City.NullToDbNull();
cmd.Parameters.Add("@CompanyName", SqlDbType.NVarChar, 200).Value = this.CompanyName.NullToDbNull();
cmd.Parameters.Add("@Competition", SqlDbType.NText).Value = this.Competition.Value.NullToDbNull();
cmd.Parameters.Add("@ContactEmail", SqlDbType.NVarChar, 200).Value = this.ContactEmail.NullToDbNull();
cmd.Parameters.Add("@ContactName", SqlDbType.NVarChar, 200).Value = this.ContactName.NullToDbNull();
cmd.Parameters.Add("@ContactTelephone", SqlDbType.NVarChar, 200).Value = this.ContactTelephone.NullToDbNull();
//this.CreatedDate;
cmd.Parameters.Add("@Description", SqlDbType.NText).Value = this.Description.Value.NullToDbNull();
cmd.Parameters.Add("@Employees", SqlDbType.Int).Value = this.Employees.HasValue ? (int)this.Employees.Value : (object)DBNull.Value;
cmd.Parameters.Add("@ExpiryDate", SqlDbType.DateTime).Value = this.ExpiryDate.NullToDbNull(); // Expiry date extended package
cmd.Parameters.Add("@FinancingBySeller", SqlDbType.Bit).Value = this.FinancingBySeller.NullToDbNull();
cmd.Parameters.Add("@FinancingInterest", SqlDbType.Float).Value = this.FinancingInterest.NullToDbNull();
cmd.Parameters.Add("@FinancingMonths", SqlDbType.Int).Value = this.FinancingMonths.NullToDbNull();
cmd.Parameters.Add("@FinancingPayout", SqlDbType.BigInt).Value = this.FinancingPayout.NullToDbNull();
cmd.Parameters.Add("@FoundedYear", SqlDbType.Int).Value = this.FoundedYear.NullToDbNull();
cmd.Parameters.Add("@FurnitureIncluded", SqlDbType.Bit).Value = (this.Furniture == null ? DBNull.Value : this.Furniture.IsIncluded.NullToDbNull());
cmd.Parameters.Add("@FurnitureValue", SqlDbType.BigInt).Value = (this.Furniture == null ? DBNull.Value : this.Furniture.Value.NullToDbNull());
cmd.Parameters.Add("@IdealPartner", SqlDbType.NText).Value = this.IdealPartner.Value.NullToDbNull();
cmd.Parameters.Add("@OperationType", SqlDbType.Int).Value = (int)this.OperationType;
// Must have room for 9 images. Filenames are GUID + .ext + separator
cmd.Parameters.Add("@Images", SqlDbType.NVarChar, 400).Value = this.Images != null ? string.Join(",", this.Images.ConvertAll(f => f.Filename).ToArray()) : "";
cmd.Parameters.Add("@OnlyVIPContact", SqlDbType.Bit).Value = this.OnlyVIPContact.NullToDbNull();
cmd.Parameters.Add("@Price", SqlDbType.Int).Value = this.Price.NullToDbNull();
cmd.Parameters.Add("@PrimaryRegion", SqlDbType.Int).Value = this.PrimaryRegion.Id.NullToDbNull();
cmd.Parameters.Add("@PrimarySector", SqlDbType.Int).Value = this.PrimarySector.Id.NullToDbNull();
cmd.Parameters.Add("@ProfitBeforeTaxes", SqlDbType.BigInt).Value = this.ProfitBeforeTaxes.NullToDbNull();
cmd.Parameters.Add("@RealEstateIncluded", SqlDbType.Bit).Value = this.RealEstate == null ? DBNull.Value : this.RealEstate.IsIncluded.NullToDbNull();
cmd.Parameters.Add("@RealEstateValue", SqlDbType.BigInt).Value = this.RealEstate == null ? DBNull.Value : this.RealEstate.Value.NullToDbNull();
cmd.Parameters.Add("@ReasonForSale", SqlDbType.Int).Value = this.ReasonForSale.NullToDbNull();
cmd.Parameters.Add("@Regions", SqlDbType.NVarChar, 400).Value = this.Regions != null ? string.Join(",", this.Regions.ConvertAll(r => r.Id.ToString()).ToArray()) : "";
cmd.Parameters.Add("@RevenuePrediction", SqlDbType.Int).Value = this.RevenuePrediction.NullToDbNull();
cmd.Parameters.Add("@RevenueStatus", SqlDbType.Int).Value = this.RevenueStatus.NullToDbNull();
cmd.Parameters.Add("@SearchTerms", SqlDbType.NVarChar, 200).Value = this.SearchTerms != null ? string.Join(",", this.SearchTerms.ToArray()) : "";
cmd.Parameters.Add("@Sectors", SqlDbType.NVarChar, 400).Value = this.Sectors != null ? string.Join(",", this.Sectors.ConvertAll(s => s.Id.ToString()).ToArray()) : "";
if (this.AdvertLevel == AdvertLevel.Regular
&& (this.Status == AdvertStatus.Enabled
|| this.Status == AdvertStatus.ApprovedNotPublished
|| this.AdvertID == -1))
this.Status = AdvertStatus.PendingApproval;
cmd.Parameters.Add("@Status", SqlDbType.Int).Value = this.Status.NullToDbNull();
cmd.Parameters.Add("@StockIncluded", SqlDbType.Bit).Value = this.Stock == null ? DBNull.Value : this.Stock.IsIncluded.NullToDbNull();
cmd.Parameters.Add("@StockValue", SqlDbType.BigInt).Value = this.Stock == null ? DBNull.Value : this.Stock.Value.NullToDbNull();
cmd.Parameters.Add("@Subtitle", SqlDbType.NVarChar, 200).Value = this.Subtitle.NullToDbNull();
cmd.Parameters.Add("@Training", SqlDbType.NText).Value = this.Training.Value.NullToDbNull();
cmd.Parameters.Add("@TransactionType", SqlDbType.Int).Value = this.TransactionType.NullToDbNull();
cmd.Parameters.Add("@Turnover", SqlDbType.Int).Value = this.Turnover.NullToDbNull();
cmd.Parameters.Add("@UserID", SqlDbType.UniqueIdentifier).Value = this.UserID.NullToDbNull();
cmd.Parameters.Add("@VATnumber", SqlDbType.NVarChar, 200).Value = this.VATNumber.NullToDbNull();
cmd.Parameters.Add("@ZipCode", SqlDbType.NVarChar, 50).Value = this.ZipCode.NullToDbNull();
cmd.Parameters.Add("@CompanyCountry", SqlDbType.VarChar, 3).Value = this.CompanyCountry.NullToDbNull();
cmd.Parameters.Add("@CompanyZip", SqlDbType.NVarChar, 25).Value = this.CompanyZip.NullToDbNull();
int id = (int) cmd.ExecuteScalar();
if (this.AdvertID == -1) this.AdvertID = id;
res = (this.AdvertID == id);
conn.Close();
}
我的存储过程非常简单,如下所示:
USE [Virksomhedsbors]
GO
/****** Object: StoredProcedure [dbo].[Saxis_UpdateCreateAdvert] Script Date: 10-09-2014 10:03:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Saxis_UpdateCreateAdvert]
@AdvertID INT,
@Address NVARCHAR(200),
@AdvertLevel INT,
@AdvertType NVARCHAR(200),
@BusinessEntityType INT,
@CanMove BIT,
@City NVARCHAR(200),
@CompanyName NVARCHAR(200),
@Competition NTEXT,
@ContactEmail NVARCHAR(200),
@ContactName NVARCHAR(200),
@ContactTelephone NVARCHAR(200),
@Description NTEXT,
@Employees INT,
@ExpiryDate DATETIME,
@FinancingBySeller BIT,
@FinancingInterest FLOAT,
@FinancingMonths INT,
@FinancingPayout BIGINT,
@FoundedYear INT,
@FurnitureIncluded BIT,
@FurnitureValue BIGINT,
@IdealPartner NTEXT,
@Images NVARCHAR(400),
@OnlyVIPContact BIT,
@Price INT,
@PrimaryRegion INT,
@PrimarySector INT,
@ProfitBeforeTaxes BIGINT,
@RealEstateIncluded BIT,
@RealEstateValue BIGINT,
@ReasonForSale INT,
@Regions NVARCHAR(400),
@RevenuePrediction INT,
@RevenueStatus INT,
@SearchTerms NVARCHAR(200),
@Sectors NVARCHAR(400),
@Status INT,
@StockIncluded BIT,
@StockValue BIGINT,
@Subtitle NVARCHAR(200),
@Training NTEXT,
@TransactionType INT,
@Turnover INT,
@UserID UNIQUEIDENTIFIER,
@VATNumber NVARCHAR(200),
@ZipCode NVARCHAR(50),
@CompanyCountry VARCHAR(3) = NULL,
@CompanyZip NVARCHAR(25) = NULL,
@OperationType INT = NULL
AS
IF @AdvertId = -1
BEGIN
-- CREATE if @AdvertId is -1
DECLARE @now DATETIME
SET @now = GETDATE()
DECLARE @EV BIT
SET @EV = 0
BEGIN TRANSACTION
SELECT @EV = EmailVerified
FROM [User]
WHERE MembershipId=@UserId
SET @EV = ISNULL(@EV, 0)
INSERT INTO Advert (
CreatedDate,
ModifiedDate,
EmailVerified,
EmailVerificationGuid,
Address,
AdvertLevel,
AdvertType,
BusinessEntityTypeID,
CanMove,
City,
CompanyName,
DescCompetition,
ContactEmail,
ContactName,
ContactTelephone,
Description,
Employees,
ExpiryDate,
FinancingBySeller,
FinancingInterest,
FinancingMonths,
FinancingPayout,
FoundedYear,
FurnitureIncluded,
FurnitureValue,
DescIdealPartner,
OnlyVIPContact,
Price,
Region,
Sector,
ProfitBeforeTaxes,
RealEstateIncluded,
RealEstateValue,
ReasonForSale,
RevenuePrediction,
RevenueStatus,
SearchTerms,
Status,
StockIncluded,
StockValue,
Subtitle,
DescTraining,
TransactionType,
Turnover,
UserID,
CVR,
ZipCode,
CompanyCountry,
CompanyZip,
OperationType
)
VALUES
(
@now,
@now,
@EV,
NEWID(),
@Address,
@AdvertLevel,
@AdvertType,
@BusinessEntityType,
@CanMove,
@City,
@CompanyName,
@Competition,
@ContactEmail,
@ContactName,
@ContactTelephone,
@Description,
@Employees,
@ExpiryDate,
@FinancingBySeller,
@FinancingInterest,
@FinancingMonths,
@FinancingPayout,
@FoundedYear,
@FurnitureIncluded,
@FurnitureValue,
@IdealPartner,
@OnlyVIPContact,
@Price,
@PrimaryRegion,
@PrimarySector,
@ProfitBeforeTaxes,
@RealEstateIncluded,
@RealEstateValue,
@ReasonForSale,
@RevenuePrediction,
@RevenueStatus,
@SearchTerms,
@Status,
@StockIncluded,
@StockValue,
@Subtitle,
@Training,
@TransactionType,
@Turnover,
@UserID,
@VATNumber,
@ZipCode,
@CompanyCountry,
@CompanyZip,
@OperationType
)
IF @@ROWCOUNT > 0
BEGIN
--SET @AdvertID = SCOPE_IDENTITY() -- is scope_identity f*cked? -- maybe because of the trigger
SELECT TOP 1 @AdvertID = AdvertID FROM Advert WHERE CreatedDate=@now AND UserID=@UserID AND AdvertLevel = @AdvertLevel
ORDER BY AdvertID DESC
END
COMMIT TRANSACTION
END
ELSE
BEGIN
-- UPDATE
SELECT @EV = EmailVerified
FROM [User]
WHERE MembershipId=@UserId
SET @EV = ISNULL(@EV, 0)
UPDATE Advert
SET
ModifiedDate=GETDATE(),
Address=@Address,
AdvertLevel=@AdvertLevel,
AdvertType=@AdvertType,
BusinessEntityTypeID=@BusinessEntityType,
CanMove=@CanMove,
City=@City,
CompanyName=@CompanyName,
DescCompetition=@Competition,
ContactEmail=@ContactEmail,
ContactName=@ContactName,
ContactTelephone=@ContactTelephone,
Description=@Description,
Employees=@Employees,
ExpiryDate=@ExpiryDate,
FinancingBySeller=@FinancingBySeller,
FinancingInterest=@FinancingInterest,
FinancingMonths=@FinancingMonths,
FinancingPayout=@FinancingPayout,
FoundedYear=@FoundedYear,
FurnitureIncluded=@FurnitureIncluded,
FurnitureValue=@FurnitureValue,
DescIdealPartner=@IdealPartner,
OnlyVIPContact=@OnlyVIPContact,
Price=@Price,
Region=@PrimaryRegion,
Sector=@PrimarySector,
ProfitBeforeTaxes=@ProfitBeforeTaxes,
RealEstateIncluded=@RealEstateIncluded,
RealEstateValue=@RealEstateValue,
ReasonForSale=@ReasonForSale,
RevenuePrediction=@RevenuePrediction,
RevenueStatus=@RevenueStatus,
SearchTerms=@SearchTerms,
Status=@Status,
StockIncluded=@StockIncluded,
StockValue=@StockValue,
Subtitle=@Subtitle,
DescTraining=@Training,
TransactionType=@TransactionType,
Turnover=@Turnover,
CVR=@VATNumber,
ZipCode=@ZipCode,
UserID=@UserID, -- Allow the Anonymous User ID to be changed
CompanyCountry = @CompanyCountry,
CompanyZip = @CompanyZip,
EmailVerified = @EV,
OperationType = @OperationType
WHERE
AdvertID = @AdvertID
--AND UserID=@UserID -- Only accept the change the advert if user id is the same
END
IF (ISNULL(@AdvertID, -1) <> -1)
BEGIN
BEGIN TRANSACTION
DELETE FROM AdvertRegion
WHERE AdvertID = @AdvertID
INSERT INTO AdvertRegion (AdvertID, RegionID)
SELECT @AdvertID, Item
FROM master.dbo.TsqlSplit(@Regions)
COMMIT TRANSACTION
BEGIN TRANSACTION
DELETE FROM AdvertSector
WHERE AdvertID = @AdvertID
INSERT INTO AdvertSector (AdvertID, SectorID)
SELECT @AdvertId, Item
FROM master.dbo.TsqlSplit(@Sectors)
COMMIT TRANSACTION
BEGIN TRANSACTION
DELETE FROM AdImages
WHERE AdvertID = @AdvertID
INSERT INTO AdImages (AdvertID, FileName)
SELECT @AdvertId, Item
FROM master.dbo.TsqlSplit(@Images)
COMMIT TRANSACTION
END
SELECT @AdvertID
知道master.dbo.TsqlSplit
错误可能是什么?
答案 0 :(得分:1)
在StoredProcedure的这一部分(以及之后),您使用TSqlSplit对象。
BEGIN TRANSACTION
DELETE FROM AdvertRegion
WHERE AdvertID = @AdvertID
INSERT INTO AdvertRegion (AdvertID, RegionID)
SELECT @AdvertID, Item
FROM master.dbo.TsqlSplit(@Regions)
COMMIT TRANSACTION
我认为,从名称来看,它是一个分割参数@Regions,@Images和@Sectors的函数,并返回一个用于在AdvertRegion,AdvertSector和AdImages表中插入新记录的表。您还提到此代码在生产服务器中没有问题,但在测试服务器中没有问题。因此,错误的唯一可能原因是测试服务器中缺少此功能。