Category Archives: Code

SSIS Package Incompatible in SSDT and Visual Studio 2017

Having installed Visual Studio 2017 Professional with the SQL Data Tools component I tried to open a SSIS package.  This failed to load and was listed as incompatible and that the application wasn’t installed.

I ran the SQL Server Data Tools (SSDT) install and added the SQL Server Integration Services component to my existing Visual Studio installation.  Unfortunately, it was still showing as incompatible and that the application wasn’t installed.

The resolution was to right click on the project and click reload.  This reloaded the project files from disk and I was able to edit the package.

Generate Code Signing Certificates Using An Enterprise Certificate Authority

If you’re creating macros in Microsoft Office, or other code that needs to be signed and trusted for internal use, you can easily create code signing certificates using an Enterprise Certificate Authority (ECA).

Log onto the ECA and open Server Manager

Expand Roles -> Active Directory Certificate Services

Navigate to the Certificate Templates section.  In the right hand pane, right click on the Code Signing certificate. choose Properties and click on the Security tab

Add the Read and Enroll permissions for the users that need to be able to generate certificates.

 

In Group Policy, add the ECA server to Trusted Sites in Internet Explorer and enable “Initialize ActiveX unsafe for scripting” for the Trusted Sites zone.  This resolve the “CA must be configured to use HTTPS authentication error.

Navigate to the ECA website address, e.g. http://%ECA_SERVER_NAME%/certsrv/

Choose Request a certificate, then choose the option for and advanced request, followed by Create and submit a request to this CA

Accept any security prompts that follow

From the certificate type drop down choose Code Signing, provide a friendly name and click Submit

Finally, click Install this certificate

The certificate is now installed and ready for use.

 

Unhandled exception was thrown by the sandboxed code wrapper’s Execute method in the partial trust app domain

I’ve been developing a sandboxed web part for SharePoint 2010.  The web part retrieves images from a SharePoint image library and uses Silverlight to display them in a slideshow.  I deployed the web part solution to the live environment and added it to a simple test page.  The web part displayed the images without error.  In preparation for the release of the web part I added it to the home page and configured an audience to hide the web part from all but a test group of users.  As soon as I added an audience to the web part it failed to load and just displayed an error.  Looking in the SharePoint log file showed the error below

01/17/2012 11:55:26.18 SPUCWorkerProcess.exe (0x8790) 0x92CC SharePoint Foundation Sandboxed Code Service fe8s Medium – – Unhandled exception was thrown by the sandboxed code wrapper’s Execute method in the partial trust app domain: An unexpected error has occurred. – userCodeWrapperType = “Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper”, userAssemblyGroupId = “BCC815A08E2A4C64923709F32FA00B92-by0V1RUaCe3c88sryp9ER7slGEpZXlqosRuCBMbd6hY=”, siteCollectionId = “1eb54e14-572f-4fd9-a8e7-33b9869d3e96” – Inner Exception: Microsoft.SharePoint.UserCode.SPUserCodeSolutionProxiedException: Value cannot be null. Parameter name: path1 at System.IO.Path.Combine(String path1, String path2) at System.Web.HttpRawUploadedContent.TempFile..ctor() at System.Web.HttpRawUploadedContent.AddBytes(Byte[] data, Int32 offset, Int32 length) at System.Web.HttpRequest.GetEntireRawContent() at System.Web… 9b39d39d-ebb5-4ddd-9387-efff7785962b

01/17/2012 11:55:26.18* SPUCWorkerProcess.exe (0x8790) 0x92CC SharePoint Foundation Sandboxed Code Service fe8s Medium ….HttpRequest.GetMultipartContent() at System.Web.HttpRequest.FillInFormCollection() at System.Web.HttpRequest.get_Form() at System.Web.HttpRequest.get_HasForm() at System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) at System.Web.UI.Page.DeterminePostBackMode() at Microsoft.SharePoint.UserCode.SPUserCodePage.DeterminePostBackMode() at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 9b39d39d-ebb5-4ddd-9387-efff7785962b

01/17/2012 11:55:26.18 SPUCHostService.exe (0x6404) 0x97F0 SharePoint Foundation Sandboxed Code Service 0000 Medium – – Value cannot be null. Parameter name: path1 – Request executing userSolution Id “bcc815a0-8e2a-4c64-9237-09f32fa00b92″ for site collection id ” 1eb54e14-572f-4fd9-a8e7-33b9869d3e96″ has encountered an unhandled exception while executing user code. 9b39d39d-ebb5-4ddd-9387-efff7785962b

Searching Google indicated that the error could be due to the size of the HTTP request.   In order to resolve the error I opened the sandbox solution web.config file in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\UserCode\web.config.  I added <httpRuntime requestLengthDiskThreshold = “4096” /> to the system.web section of the file according to the information here http://msdn.microsoft.com/en-us/library/e1f13641.aspx .

 

Calling a function in PowerShell

This is a quick example that shows how you can call a function in PowerShell.  The example has a function that accepts an Active Directory (AD) Organisation Unit (OU) name, enumerates the computers within that OU and kills any process with the name “Application1.exe”.

Create two files in a folder called PowerShell in the root of C:\, one called KillProcess.ps1, which will contain the function and another called EnumPCsKillProcess.ps1, which will call the function.  Below is the contents of each file:

KillProcess.ps1

Function KillProcess
{
ForEach ($child In $ou.psbase.Children)
{
if ($child.ObjectCategory -Like ‘*computer*’)
{
$Procs = gwmi -ComputerName $child.Name -Query “Select * from Win32_Process Where Name = ‘Application1.exe'”
ForEach ($Proc In $Procs)
{
Write-Host $child.Name
$Proc.Terminate()
}
}
}
}

EnumPCsKillProcess.ps1

. C:\PowerShell\KillProcess.ps1
$ou = [ADSI]”LDAP://OU=ENTER 1ST OU PATH HERE”
KillProcess
$ou = [ADSI]”LDAP://OU=ENTER 2nd OU PATH HERE”
KillProcess

The key line is the one in red above, which references the KillProcess.ps1 file, which contains the function.

Using Visual Studio 2008 With Visual Studio Team Foundation Server 2010

In order to use Visual Studio 2008 With Visual Studio Team Foundation Server 2010, you need to follow the steps below in the following order:

  1. Install Visual Studio 2008
  2. Install Team Explorer 2008
  3. Install Visual Studio 2008 SP1
  4. Install Visual Studio 2008 Forward Compatibility Update for Team Foundation Server 2010

 

 

 

Reporting Virtual Machine Dynamic Disk Space Using PowerShell And System Center Virtual Machine Manager 2008 R2

Dynamically expanding disks enable you to thin provision virtual machines (VMs)  storage.  This means you can pack more VMs onto a given amount of disk, but you need to ensure that if you provision more storage than is physically available, you don’t run out of space on the host.  The PowerShell script below produces a csv file showing the space available for growth on each VM with a dynamically expanding disk.  You can use this script to see how much space could still be used by your VMs and therefore see if you’re likely to run out of space on the host.  It’ll also show you if a dynamic disk is about to reach it’s maximum size.

Load PowerShell from the icon in the SCVMM console

Next copy and paste the code below into the PowerShell console, replacing VMMHOST with the name of your SCVMM host and the path of the csv file as appropriate.

Get-VirtualHardDisk -VMMServer VMMHOST -All | Select-Object @{Label=”VM Host”;Expression={$_.VMHost}},@{Label=”Name”;Expression={$_.Name}},@{Label=”Space To Grow”;Expression={[Math]::Truncate(($_.MaximumSize-$_.Size) / 1GB)}},@{Label=”VHDType”;Expression={$_.VHDType}} | Where-Object {($_.VHDType -Match “DynamicallyExpanding” -And $_.Name -NotMatch “{“)} | Sort-Object “Space To Grow” -Descending |  Export-Csv C:\DiskInformation.csv

Opening the csv in Excel produces

 

The PowerShell script is a one liner and breaks down as follows:

Get-VirtualHardDisk -VMMServer VMMHOST -All | Gets the virtual disk for the VMMServer specified

Select-Object @{Label=”VM Host”;Expression={$_.VMHost}},@{Label=”Name”;Expression={$_.Name}},@{Label=”Space To Grow”;Expression={[Math]::Truncate(($_.MaximumSize-$_.Size) / 1GB)}},@{Label=”VHDType”;Expression={$_.VHDType}} | Selects the VM host name, disk name, calculates the maximum disk size – current disk size and converts to GB, VHD type

Where-Object {($_.VHDType -Match “DynamicallyExpanding” -And $_.Name -NotMatch “{“)} | Filters the results to only include dynamically expanding disks whose names don’t start {

Sort-Object “Space To Grow” -Descending | Sorts the output by space to grow, descending

Export-Csv C:\DiskInformation.csv Exports the results to a csv file

 

Storing URLs With Query Strings In XML

Suppose you have a URL like  http://www.test.com?1=2&2=3 and you need to store it in an XML file like the one below.  The & character will cause and error.  Replace the & with &amp; e.g. http://www.test.com?1=2&amp;2=3

<?xml version=”1.0″ encoding=”utf-8″ ?>
<Regions>
<Europe>
<Region ID=”1981″ Name=”Denmark” IAURL=”http://www.test.com?1=2&2=3/>
</Europe>
</Regions>