2014-09-10 2 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, и на вашем текущем рабочем сервере нет такого объекта. Или, возможно, функция, которая разбивает параметр @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. Вы также отметили, что этот код работает без проблем на вашем рабочем сервере, но не на вашем тестовом сервере. Таким образом, единственной возможной причиной ошибки является тот факт, что эта функция отсутствует на вашем тестовом сервере.

Смежные вопросы