2014-09-10 1 views
1

정말 이상한 오류가 있습니다. 프로덕션 환경에서 완벽하게 작동하는 저장 프로 시저를 실행하려고합니다. 이제 테스트 서버에서 Invalid object name 'master.dbo.TsqlSplit'. 오류가 발생합니다.SQL 업데이트 : 잘못된 개체 이름 '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 [email protected] 

     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 [email protected] AND [email protected] AND AdvertLevel = @AdvertLevel 
      ORDER BY AdvertID DESC 

     END 
    COMMIT TRANSACTION 
END 
ELSE 
BEGIN 
    -- UPDATE 

    SELECT @EV = EmailVerified 
      FROM [User] 
      WHERE [email protected] 

    SET @EV = ISNULL(@EV, 0) 

    UPDATE Advert 
    SET 
     ModifiedDate=GETDATE(), 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], 
     [email protected], -- Allow the Anonymous User ID to be changed 
     CompanyCountry = @CompanyCountry, 
     CompanyZip = @CompanyZip, 
     EmailVerified = @EV, 
     OperationType = @OperationType 
    WHERE 
     AdvertID = @AdvertID 
     --AND [email protected] -- 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

연결 문자열을 확인할 수 있습니까? – Steve

+0

@Steve connectionstring이 잘 작동해야합니다. 그것은 데이터베이스에 열 수 있고 쉽게 데이터베이스에서 다른 읽기/삽입을 만들 수 있습니다 –

+0

당신의 proc가 TsqlSplit라는 master 데이터베이스의 테이블/뷰를 사용하고있는 것 같습니다. 현재 작업중인 서버에는 그러한 객체가 없습니다. 또는 아마도 @Images 매개 변수를 분할하고 테이블을 반환하는 함수 일 수 있습니다. – Steve

답변

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 테이블에 새로운 레코드를 삽입하는 데 사용되는 테이블을 반환하는 함수이다, 그 이름에서, 가정합니다. 또한이 코드는 프로덕션 서버에서는 문제없이 작동하지만 테스트 서버에서는 작동하지 않는다고 언급했습니다. 따라서 오류의 유일한 원인은 테스트 서버에이 함수가 없다는 것입니다.