Showing posts with label Error. Show all posts
Showing posts with label Error. Show all posts

Monday, October 7, 2019

SSIS Exception - The Script Task uses version 15.0 script that is not supported in this release of Integration Services

I recently encountered SSIS exception - The Script Task uses version 15.0 script that is not supported in this release of Integration Services , when I included the script task in SSIS package to zip the generated text file and tried to run the SSIS package through command prompt.

   Source: Script Task Script Task
   Description: There was an exception while loading Script Task from XML: System.Exception: The Script Task "ST_08f0882909d74636bd9612a8d0e85790" uses version 15.0 script that is not supported in this release of Integration Services. To run the package, use the Script Task to create a new VSTA script. In most cases, scripts are converted  automatically to use a supported version, when you open a SQL Server Integration Services package in %SQL_PRODUCT_SHORT_NAME% Integration Services.
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask.LoadFromXML(XmlElement elemProj, IDTSInfoEvents events)
End Error

SSIS Package:

SSIS Package - Script Task

Here is command script to run ETL SSIS package

C:\Users\rtiwari>DTEXEC /FILE C:\Users\rtiwari\source\repos\PDFSharp_Merge\ETL_Extract.dtsx


After researching all possible cause, I found there could be two reason, why this SSIS exception is getting encountered.

1.   Deployed SSIS package ‘s target framework is not matching on deployed server :

Here is steps to fix the target framework for deployed SSIS package

Ø  Right click the SSIS project in the Project Explorer -> Click on Property


Ø  Click on Configuration Properties and Change TargetServerVersion è SQL Server 2017 



2.   Second reason really surprised me it was version of DTEXEC.exe. If the version of DTEXEC.exe command is not latest version, then also it throw exception.

Might be there are different version of SQL server Data Tool installed on your machine, Please look the below folders for different version of DTEXEC.exe
               
·         Open a Command Prompt window, change to the directory that contains the latest version of utility command, and then run the utility from that location
C:\Program Files(x86)\Microsoft SQL Server\140\DTS\Binn> DTEXEC /FILE C:\Users\rtiwari\source\repos\PDFSharp_Merge\ETL_Extract.dtsx
·         At the command prompt, run the utility DTEXEC.exe by entering the full path (:\Program Files\Microsoft SQL Server\140\DTS\Binn).
C:\Program Files(x86)\Microsoft SQL Server\140\DTS\Binn\DTEXEC.exe /FILE C:\Users\rtiwari\source\repos\PDFSharp_Merge\ETL_Extract.dtsx



Wednesday, September 11, 2019

Entity Framework - When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects.

I recently encountered the below Entity Framework error message while mapping to entity data to domain object.

System.InvalidOperationException: When an object is returned with a NoTracking merge option, Load can only be called when the EntityCollection or EntityReference does not contain objects

Here is Entity Framework Model (edmx) diagram and repository method GetOrder() which is  used to get order information on based on order number.

Entity Framework Model (edmx) diagram:


Domain Class:

    public class OrderData
    {
        public int OrderID { getset; }
        public int OrderNumber { getset; }
        public int? StatusID { getset; }
        public string  OrderStatusCode { getset; }
    }


Repository Class:
           
    public OrderData GetOrder(int orderNumber)
        {
           Order orderEntity =  _dbContext.Orders.AsNoTracking().FirstOrDefault(x => x.OrderNumber == orderNumber);

            return orderEntity != null ? new OrderData
            {
                OrderID = orderEntity.OrderID,
                OrderNumber = orderEntity.OrderNumber,
                OrderStatusCode = orderEntity.OrderStatu.StatusCode
            }: null;
        }


In above EF query, AsNoTracking() option is used for Orders entity, it means EF will not track the instantiated Order value and Order entity ‘s navigation properties also will be OFF.

In above Edmx diagram, we can see the Order has a navigation property ‘OrderStatu’ but due to asNoTracking option, all navigation properties of Order entity will be OFF and when we will try to access any navigation property value and It will be throw entity framework  exception

Order orderEntity = _dbContext.Orders.AsNoTracking().FirstOrDefault(x => x.OrderNumber == orderNumber);

So in this scenario, we need to explicitly include navigation property OrderStatu’ by using Include () function

Order orderEntity = _dbContext.Orders.Include(x => x.OrderStatu).AsNoTracking().FirstOrDefault(x => x.OrderNumber == orderNumber);

In other way

Order orderEntity =  _dbContext.Orders.Include("OrderStatu").AsNoTracking().FirstOrDefault(x => x.OrderNumber == orderNumber);

Tuesday, October 30, 2018

ASP.NET MVC Exception : Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions


{InvalidOperationException: Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions}

I recently encountered above exception, when I tried to bind Data Model to View to show count of Order and here is Code:



HTML View:

<div class="form-group">
            @Html.LabelFor(m => m.PostedOrders)
                <div class="col-md-3">
                    @Html.DisplayFor(m => m. PostedOrders.Count())
                </div>
</div>

If you see exception, it tell, you can only bind @Html.DisplayFor with Field, Property of Model and it does not support function or expression.



To fix this problem, you need to add one additional property or field in Model Class [OrderDataModel] that holds the total count of posted orders and you can bind this field/property with view to display total count of posted order

C# :

public class OrderDataModel
    {
        public List<Order> PostedOrder { get; set; }
        public int Total => PostedOrder.Count;
    }


HTML View:

<div class="form-group">
            @Html.LabelFor(m => m.Total)
                <div class="col-md-3">
                    @Html.DisplayFor(m => m.Total)
                </div>
</div>

Thanks for visiting, please leave your comments if it helps

Tuesday, October 23, 2018

WCF Exception : The message with Action 'http://tempuri.org ' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher


WCF Exception: The message with Action 'http://tempuri.org/IProduct/GetProduct ' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None)



There would be many reason for this exception and it can be :

·         Requested Method ‘GetProduct’ signature has been changed.
·         Requested Method ‘GetProduct’ has been deleted from WCF server.
·         Existing Binding Information has been modified or delete.
·         Binding security setting are not consistent between client and server

To resolve this contract mismatch issue, recreate or refresh the wcf client proxy, most proabaly this issue will be resolved.

Thanks for visiting!!

Friday, October 20, 2017

LINQ To EF : Error "The LINQ expression node type 'Invoke' is not supported in LINQ to Entities in entity framework"

In LINQ -to-EF query, First EF query is translated into SQL and when we are trying to translate some code into SQL and something is not supported in SQL and then this exception occurred.




"The LINQ expression node type 'Invoke' is not supported in LINQ to Entities in entity framework"

    public List<PersonData> GetAll()

        {

             return _db.Persons.Select(x => MapToPersonData(x)).ToList();

        }

internal static Func<Person, PersonData> MapToPersonData = m =>
    {
        if (m == null)
        {
            return null;
        }
        else
        {
            return new PersonData()
            {
              PersonID = m.PersonID,
              Name = m.Name,
              Location = m.Location.City +""+ m.Location.Street
            };
        }
    };


In above EF Query, the function MapToPersonData()  is being used to map the person entity into person data object and in this function, we are concatenating  of the city and Street string and the concatenating of string will not be supported in LINQ to entties, so the above error is occured.

What solution I found, we have to fetch data from database table in your local memory by calling .ToList()/.ToEnumerable() function and then we can apply logic on top of that similar like LINQ-To-Object 


       public List<PersonData> GetAll()

        {

           return _db.Persons.AsEnumerable().Select(x => MapToNameData(x)).ToList();

        }

  
Other entity framework related links

SQL Server - Identify unused indexes

 In this blog, we learn about the index usage information (SYS.DM_DB_INDEX_USAGE_STATS) and analyze the index usage data (USER_SEEKS, USER_S...