Posts

Showing posts from May, 2019

EntityFramework Insert error due to PrimaryKey

MyProject.Controllers.CurrencyCodesController Unable to update the EntitySet 'CurrencyCodes' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.
System.Data.Entity.Infrastructure.DbUpdateException: Unable to update the EntitySet 'CurrencyCodes' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation. ---> System.Data.Entity.Core.UpdateException: Unable to update the EntitySet 'CurrencyCodes' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.​

Scenario:
The error occured while trying to insert the currencycodes entity to the database.
[HttpPost]
[ValidateAntiForgeryToken]
publicActionResult Create([Bind(Include = "cucCurrencyCode…

Fix for SSIS not picking correct configuration file

When there are more then one configuration file for a single package, the SSIS jobs sometimes do not automatically pick the correct configuration depending on how the settings has been made.

In the SSIS package (using Visual Studio) Make sure you've done following correctly: 1) In the package property, Set Delay Validation =  false
2) Uncheck , Enable Package Configuration.


steps for 2):
a) open the ssis package in visual studio. b) In the Control flow tab, right click on the blank space of the canvas. c) go to Package Configurations... d) uncheck Enable Package Configuartion and press Close. e) Save the ssis package and copy that to the deployed folder.

How to remove Workspace in TFS 2010-2018

This solution Works for TFS 2010+.

Open Visual studio Command prompt and run the following script.


tf workspace /delete /server:[Site:Port/path] WORKSPACENAME


for example:
tf workspace /delete /server:http://tfs.site.com:8080/tfs sanjeebPC

Use log4net for all logging in c# application

Exception logging is hugely important within an application, not just to ensure we know when an error has occured but also to help use trace back the thread to help investigate where the error originated. Our strategy is to use log4net for all our logging needs. This page helps cover the follow areas 1. Setting up logging across the entire applications 2. Including 2 appenders so we can be notified when they occur and ensure a tracable debug log file is available. Setting up your Applications for Logging Reference log4net in your applications in Global.asax under the start_application method include the following void Application_Start(object sender, EventArgs e) { // link up log4net configuration log4net.Config.XmlConfigurator.Configure(); } On the page where you wish to log information declare a new static variable in the class header log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Whenever you wis…

Create XML from class or Object in C-Sharp

public static string SerializeObjectToXML(object item)
        {
            try
            {
                string xmlText;
                Type objectType = item.GetType();
                XmlSerializer xmlSerializer = new XmlSerializer(objectType);
                MemoryStream memoryStream = new MemoryStream();
                using (XmlTextWriter xmlTextWriter =
                    new XmlTextWriter(memoryStream, Encoding.UTF8) { Formatting = Formatting.Indented })
                {
                    xmlSerializer.Serialize(xmlTextWriter, item);
                    memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
                    xmlText = new UTF8Encoding().GetString(memoryStream.ToArray());
                    memoryStream.Dispose();
                    return xmlText;
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.Write(e.ToString());
                return null;
            }
        }

Powershell script to create OS disk in azure from storage account blob image file (vhd)

Powershell script to create OS disk in azure from storage account blob image file (vhd)
#Provide the subscription Id where Managed Disks will be created
$subscriptionId = 'd7x2bxx8-62xe-4xdx-xa8x-20x0x3x2x5xx'

#Provide the name of your resource group where Managed Disks will be created. 
$resourceGroupName ='MYResourceGroupName'

#Provide the name of the Managed Disk
$diskName = 'Project_Disk2'

#Provide the size of the disks in GB. It should be greater than the VHD file size.
$diskSize = '90'

#Provide the storage type for Managed Disk. PremiumLRS or StandardLRS.
$storageType = 'Premium_LRS'

#Provide the Azure region (e.g. westus) where Managed Disk will be located.
#This location should be same as the storage account where VHD file is stored
#Get all the Azure location using command below:
#Get-AzLocation
$location = 'ukwest'

#Provide the URI of the VHD file (page blob) in a storage account. Please not that this is NOT the SAS URI of the storage containe…

Solution to the CORS issue

CORS:Cross-Origin Resource Sharing
In the web.config file, add the following:


<system.webServer><httpProtocol><customHeaders><add name="access-control-allow-origin" value="*" /> <add name="access-control-allow-headers" value="content-type" /></customHeaders> </httpProtocol> </system.webServer>Enable anonymous authentication

Convert Premium SSD to Standard HDD in Azure

Powershell script to convert Premium SSD disk to standard HDD 


# Name of the resource group that contains the VM
$rgName = 'MYResourceGroupName'

# Name of the your virtual machine
$vmName = 'MyVirtualMachineName'

# Choose between Standard_LRS and Premium_LRS based on your scenario
$storageType = 'Standard_LRS'

# Premium capable size
# Required only if converting storage from Standard to Premium
#$size = 'Standard_DS2_v2'


#Provide the subscription Id where Managed Disks will be created
$subscriptionId = 'd7x2bxx8-62xe-4xdx-xa8x-20x0x3x2x5xx'

Select-AzSubscription -SubscriptionId $SubscriptionId



# Stop and deallocate the VM before changing the size
Stop-AzVM -ResourceGroupName $rgName -Name $vmName -Force

$vm = Get-AzVM -Name $vmName -resourceGroupName $rgName

# Change the VM size to a size that supports Premium storage
# Skip this step if converting storage from Premium to Standard
#$vm.HardwareProfile.VmSize = $size
#Update-AzVM -VM $vm -ResourceGroupName $rgName

#…