Thursday 21 November 2013

Cannot browse for Files in SSMS 2008 R2–Cannot access the specified path or file on the server

Recently, while dealing with a client, I can across an issue where I couldn’t restore a database.

Whenever I pressed the “Add” button, I was shown a warning box, similair to;

image

After which, pressing Ok, would leave me with an empty Browse Dialog.

image

It seems as though, if your user does not have the "sysadmin" role, then they will not have sufficient access to the filesystem on the machine in order to open the file browser.

Setting aside the security concerns for one moment....

In order to grant this role;

  1. Log in to SSMS using Windows Authentication
  2. Navigate to Security->Logins
  3. Either double Click, or Right Click and select Properties on the user you're interested in .
  4. In the "Select a page" box, select "Server Roles"
  5. Make sure that the "sysadmin" role is selected
  6. Press Ok to save the change and close the dialog
  7. Exit SSMS
  8. Reopen SSMS and login as the User you wanted, and you should now have sufficient Privileges to browse.

Wednesday 9 October 2013

Redirecting .co.uk to .com with ASP.net MVC IIS7 URL ReWrite 2.0

I recently started work on a new website, where I’ve purchased the .co.uk and .info domain names. However, I wanted to redirect people automatically to the main .com domain.
As my host supports the IIS7 URL ReWrite 2.0 moduke, adding the following section to the primary web.config file solved this for me;
   1: <rewrite>

   2:       <rules>

   3:         <rule name="RedirectToWWW1" stopProcessing="true">

   4:           <match url=".*" ignoreCase="true" />

   5:           <conditions logicalGrouping="MatchAny">

   6:             <add input="{HTTP_HOST}" pattern="^mydomain.co.uk$" />

   7:             <add input="{HTTP_HOST}" pattern="^mydomain.info$" />

   8:             <add input="{HTTP_HOST}" pattern="^www.mydomain.co.uk$" />

   9:             <add input="{HTTP_HOST}" pattern="^www.mydomain.info$" />

  10:           </conditions>

  11:           <action type="Redirect" url="http://www.mydomain.com/{R:0}" redirectType="Permanent" />

  12:         </rule>

  13:       </rules>

  14:     </rewrite>

Tuesday 1 October 2013

svchost.exe consumes 100% CPU on Windows XP, caused by Windows Updates

I reinstalled Windows XP on a clients PC recently, and came up against an issue where I couldn’t update Windows using Windows Update. I then noticed that the PC had slowed down to a crawl. Opening up Task Manager, Processes and Sorting by CPU, I found that svchost.exe was consuming 100% CPU.

I tried killing the process, and retrying the updates, but svchost.exe was back to 100% as soon as I did.

Having searched around multiple forums for a long time, I finally found a solution which sorted the problem;

Firstly, download Internet Explorer 8 for Windows XP - http://www.microsoft.com/en-gb/download/internet-explorer-8-details.aspx

Once that has downloaded, install the hotfix KB2870699 for IE8 - http://www.microsoft.com/en-us/download/details.aspx?id=40119

Hey presto, problem solved. You can now use Windows update and install the 300+ updates that are required!

Saturday 27 July 2013

Entity Framework Code First Seeding with Related Data

A quick tip I stumbled upon while working on an MVC application using Entity Framework Code First.

In order to Seed Related Data when using Entity Framework Code First, it’s important to give items temporary ID’s before calling the seed method. Otherwise, when the database is seeded you will end up with Conflicted Inserts

Wednesday 26 June 2013

Knockout (or any javascript) Intellisense not working if move script file locations

I found while playing around with Knockout.js, that my Visual Studio Intellisense wasn’t working. This turned out to be because I had formatted my Scripts folder, and moved standard Javascript libraries into another folder.

This meant that Visual Studio couldn’t find my _references.js file.

At first I added the following to the @Scripts Section in my .vbhtml file;

   1: @Code 
   2:  
   3:        If (False) Then
   4:  
   5:            @<script src="/Scripts/lib/knockout-2.2.1.debug.js" type="text/javascript"></script>
   6:                
   7:        End If
   8:              
   9: End Code
Where the If (False) code forces the compiler to ignore the file when publishing.


But this would end up being silly if I had lots of files. So, I had a quick look around and found a couple of useful answers on Stack Overflow;


http://stackoverflow.com/a/12016530/1305169 and
http://stackoverflow.com/a/12628049/1305169


Where, basically, you need to add a reference to your new _references.js file to the Intellisense list options in Visual Studio;



  • In Visual Studio, go to Tools > Options > Text Editor > Javascript > Intellisense > References
  • In the “Add a reference to current group”, type in the relative path to your _references.js file (for me this was “~/Scripts/lib/_references.js”

Hey presto, you should now have working intellisense!

Wednesday 19 June 2013

Slow WPF DataGrid when Grouping Styles Added

I found while working a project recently, that when I added the styling for Grouping, even if I wasn’t actually using it, that the load time for my data was massively affected.

Evidently, the reason or this slow down is due to the fact that, unbeknown to me, when grouping is enabled in WPF, then Virtualisation is disabled by default.

Virtualisation allows WPF to not physically render items which don’t appear directly in the UI, thus it doesn’t need to perform all the complicated UI math related to showing UI elements. This vastly improves performance, in my case, when dealing with Data Sources which have rows exceeding a few hundred.

Thankfully, WPF and .Net 4.5 has enabled a way for Virtualisation to be re-enabled when grouping. Simply adding the following to the Datagrid re-enabled Virtualisation.

   1: VirtualizingStackPanel.IsVirtualizing="True”

Friday 7 June 2013

Installing IE10 offline

Today I came up against a problem where an application I was working on required IE10 to be installed. This all well and good, however this pc didn’t have access to an internet connection.

As such, I needed to download the IE10 install package, and copy it across to the machine.

However, when I came to install IE10, it simply told me that it needed to download “An Update” before it could be installed.

After a little searching around I found the following forum which lists the updates IE10 requires prior to being installed;

http://www.askvg.com/direct-download-link-full-standalone-offline-installers-of-microsoft-internet-explorer-10-ie10/

Basically, you need to download the following files, some of which require you to validate your copy of windows;

  1. KB2729094 - http://www.microsoft.com/en-gb/download/details.aspx?id=30521 (Requires Validation)
  2. KB2731771 - http://www.microsoft.com/en-gb/download/details.aspx?id=34863 (Requires Validation)
  3. KB2533623 - http://www.microsoft.com/en-gb/download/details.aspx?id=26767 (Requires Validation)
  4. KB2670838 - http://www.microsoft.com/en-us/download/details.aspx?id=36805
  5. KB2786081 - http://www.microsoft.com/en-gb/download/details.aspx?id=36326 (Requires Validation)

Download and install all of the above, there’s no need to restart between each update, but you must restart afterwards.

Once you’ve completed that, download the IE10 install package from;

http://www.microsoft.com/en-us/download/internet-explorer-10-details.aspx

Your install should then work smoothly!

Note: there are two different versions for x86 and x64 platforms.

SGEN: Mixed mode assembly is built against version 'v2.0.50727'…

I found while building an VB application in Visual Studio 2012, in release mode for the first time, that I was confronted with cryptic build error;
SGEN: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
After trawling through some Google results, I found the following post by Microsoft;

http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

And also a couple of forums;

http://stackoverflow.com/questions/3749368/team-build-sgen-mixed-mode-assembly
http://social.msdn.microsoft.com/Forums/en-US/clr/thread/2a5bf31e-df96-4bf1-a846-699da46b62fb

Which suggests adding (or creating if it it doesn’t exist already) the following XML to the sgen.exe.config file;
<?xml version ="1.0"?>

<configuration>

    <startup useLegacyV2RuntimeActivationPolicy="true">

                <supportedRuntime version="v4.0" />

    </startup>   

</configuration>
For .Net 4.0 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools  (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools (for x64 systems)
For .Net 4.5 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools (for x64 systems)
Edit - 03-06-14:

For .Net 4.5.1 Projects, the sgen.exe.config file can be found at;
c:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x86 systems) 
c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.5.1 Tools (for x64 systems)
Once I’d added the xml, the application built just fine.

The other alternative was to disable the option to Generate Serialization Assemblies in the offending project;

  • Project Settings for the offending Project
  • Compile Tab
  • Advance Compile Options Button
  • Set “Generate Serialization Assemblies” from “Auto” to “Off”

However, I recommend that you go with the XML option as suggested by Microsoft.

Thursday 6 June 2013

WPF Binding Integer Validation with Null Values

I found a small hole in an application I am developing where a null value in a textbox bound to an integer value wouldn’t get validated.

It was slightly more complicated than that however. The xaml was as follows;

<TextBox Text="{Binding MyTextBoxText, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay}"/>

Where my Validation was set for when the control lost focus.

When I added a new record, the value of the binding was set to null, this enforced by validation correctly. Same when I edited the text and left the control. However, if I edited the control when it had a value, say changing the value from a 2 to nothing, then the validation wouldn’t occur.

This was because the binding didn’t have a value for a null entry. Adding a TargetNullValue parameter to the binding and thus changing the binding to the following fixed the issue nicely;



<TextBox Text="{Binding TaskOrder, UpdateSourceTrigger=LostFocus, ValidatesOnDataErrors=True, NotifyOnValidationError=True, Mode=TwoWay, TargetNullValue=''}"/>

More information on the TargetNullValue Property can be found here;

http://msdn.microsoft.com/en-us/library/system.windows.data.bindingbase.targetnullvalue.aspx

Tuesday 4 June 2013

Adding EF POCO Classes to TFS Source Control

I have various projects which included Entity Framework POCO (Plain Old CLR Object) Classes. By default, these are not automatically included in TFS Source Control.

To add these classes in VS2012;

  1. Open the Team Explorer Window using View>Team Explorer
  2. You will see a list of shortcuts... My Work, Pending Changes and so on;
  3. Under "Pending Changes" is a link to "Source Control Explorer"
  4. Click this link, to open the Source Control Explorer Window
  5. Navigate through your solution to the Project containing your edmx file
  6. Above the "Source Location" will be a toolbar
  7. The fourth icon from the left is "Add Items To Folder"
  8. Clicking this icon will bring up the "Add to Source Control" Dialog, showing all the files in this project which aren't currently under Source Control.
  9. Select all the files you wish to now include under Source Control
  10. Press Next, then Finish

Now Check In your Solution again, and your POCO's should now be included.

Visual Studio – Solutions not configured for Integrated Source Control

I recently ran into an issue where, when I opened up one of my Solutions which were under TFS Source Control, I was presented with a message box which showed;

The solution you have opened is under source control but not currently configured for integrated source control in Visual Studio. Would you like to bind this solution to source control now?

Turns out that this is Visual Studio’s way of telling me that parts or all of my solution isn’t bound correctly to the source control provider.

To rectify this issue I needed to;

  1. Open the Project directly using Visual Studio, rather than with the Source Control Explorer
  2. Goto File ->Source Control –>Advanced –> Change Source Control

This will open up the “Change Source Control” dialog, which shows which items in your solution are bound and which aren’t.

From here you simply need to select which Items need to rebound and hit the “Bind” button.

Visual Studio will then checkout the unbound items, and you then need to check them back in, and your done.

Tuesday 21 May 2013

XBMCbuntu Frodo 12.2 no Sound over SPDIF after upgrade

I recently upgraded to XBMC Frodo 12.2 and lost my sound over SPDIF. The option for SPDIF wasn’t available in the options.

After some searching around, I found the following forum post;

http://forum.xbmc.org/showthread.php?tid=161251

Which suggested;

1. Set speaker config to 2.0 or 2.1 in XBMC.
2. Set speaker config to 2.0 in osx audio-midi-setup
3. Activate AC3 and DTS options in XBMC
4. Disable LPCM otption in XBMC

Done

Binding the WPF WebBrowser Source Property

In an MVVM application I am currently creating, I had the need to embed the WPF WebBrowser control and quickly discovered that the Source Property is not a dependancy object, and so cannot be bound.

I quickly search around on StackOverflow.com and found a neat solution in c#;

http://stackoverflow.com/a/265648/1305169

The VB Version of which is;

   1: Namespace Helpers
   2:  
   3:     ''' <summary>
   4:     ''' Allows for the Source Property of the WebBrowser to be Bindable to the DataContext
   5:     ''' </summary>
   6:     ''' <remarks></remarks>
   7:     Public Class WebBrowserUtility
   8:         Private Sub New()
   9:         End Sub
  10:         Public Shared ReadOnly BindableSourceProperty As DependencyProperty = DependencyProperty.RegisterAttached("BindableSource", GetType(String), GetType(WebBrowserUtility), New UIPropertyMetadata(Nothing, AddressOf BindableSourcePropertyChanged))
  11:  
  12:         Public Shared Function GetBindableSource(obj As DependencyObject) As String
  13:             Return DirectCast(obj.GetValue(BindableSourceProperty), String)
  14:         End Function
  15:  
  16:         Public Shared Sub SetBindableSource(obj As DependencyObject, value As String)
  17:             obj.SetValue(BindableSourceProperty, value)
  18:         End Sub
  19:  
  20:         Public Shared Sub BindableSourcePropertyChanged(o As DependencyObject, e As DependencyPropertyChangedEventArgs)
  21:             Dim browser As WebBrowser = TryCast(o, WebBrowser)
  22:             If browser IsNot Nothing Then
  23:                 Dim uri As String = TryCast(e.NewValue, String)
  24:                 browser.Source = If(uri IsNot Nothing, New Uri(uri), Nothing)
  25:             End If
  26:         End Sub
  27:     End Class
  28:  
  29: End Namespace

You then use your new Bindable Property in the XAML as;



<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    xmlns:Helpers="clr-namespace:FrontEnd.Helpers"
    x:Class="frmKiosk"
    x:Name="Window"
    
    Width="1920" Height="1080" WindowStyle="None" WindowStartupLocation="CenterScreen" WindowState="Maximized" Background="#FF1327D0" Cursor="None">
 
    <WebBrowser x:Name="wbMain" Helpers:WebBrowserUtility.BindableSource="{Binding KioskWebAddress}" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" />
 
</Window>

Then simply creating a Property in the DataContext, and setting the source like;



KioskWebAddress = "c:/HTML/index.html"

Wednesday 8 May 2013

Unable to open Database .SQL Files in Visual Studio 2012 Update 1 and onwards

This morning I attempted to open a .SQL file in my Visual Studio 2012 Update 2 installation, and was faced with the following Message Box;

enter image description here

Clicking the “Learn more…” link took me to a “Page Not Found” page, which wasn’t very handy.

A quick search on StackOverflow and I found;

http://stackoverflow.com/questions/15798422/what-about-sql-server-data-tools-for-vs2012-being-incompatible-with-sql-server-2

With a helpful answer by JorgenH directing me to update the SQL Server Data Tools found at this page;

http://msdn.microsoft.com/en-us/jj650015

I downloaded and installed the SQL Server Data Tools, shown at Step 2, from;

http://go.microsoft.com/fwlink/?LinkID=274984

Hey presto, problem sorted!

Wednesday 1 May 2013

SSRS 2008 R2 on Windows 8… Cannot log in

I recently installed SQl Server 2008 R2 with Advanced Services on a Windows 8 Box. However, when I tried to log into the ReportManager of SSRS, I found that it wouldn’t accept my Username and Password Combo.

After some searching, I found this poston Stack Overflow, which explained it nicely;

http://stackoverflow.com/questions/14433068/user-does-not-have-required-permissions-ssrs-2008-on-windows-8

Turns out, that as standard, the Administrator account isn’t active in Windows 8, and needs to be turned on. More annoyingly, this means that SSRS needs to be uninstalled, and reinstalled using the hidden Administrator account.

The steps I took to finally resolve were;

  1. Uninstall SSRS Node COMPLETELY by going to control panel>SQL Server 2008>Remove>Check Reporting Services
  2. Enable default admin account: command prompt>run as administrator>net user administrator, hit enter.
  3. New line: net user administrator /active:yes
  4. Reboot
  5. Logging in as default administrator
  6. Setup a Password of your Choice
  7. Reinstall the SSRS Node
  8. Install SP3 as administrator
  9. Go to IE.exe DIRECTLY in Windows 8: C:\Program Files\Internet Explorer\iexplore.exe>Run as administrator.
  10. Go to http:// (servername)/Reports
  11. You SHOULD now be able to finally see site settings. NOW YOU CAN FOLLOW everyone's directions of adding YOUR USER under site settings. Also go to folder permissions and add the user as a default here as well.
  12. (optional) For safety I would hide the default admin account now by using step 2 but substitute /active:no in.

SSRS 2008 R2 Reports are blank in Chrome

I stumbled across this apparently well documented problem today, where my SSRS 2008R2 Report was showing up fine in IE, but blank in Chrome;

http://stackoverflow.com/questions/5968082/ssrs-2008-r2-reports-are-blank-in-safari-and-chrome

It seems as though the main Div Tag uses IE compatible only Overflow styles, which Chrome doesn’t interpret well.

I found a nice blog post here which explained how to work around this issue;

http://grumpydba.blogspot.co.uk/2012/02/sql-2008-r2-report-doesnt-show-on.html

The Short and curlies of it are;

Connect to your Reporting Services server, and find the relevant ReportingServices.js file - this will probably be somewhere like "C:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportManager\js\ReportingServices.js", or on a 64 bit machine, "C:\Program Files (x86)\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportManager\js\ReportingServices.js"


First up, take a copy of this file - let's not be silly here and assume this is a 100% foolproof solution!
Next, edit this file in notepad. Do a quick search for PageLoad, to ensure no-one else has already hacked applied this fix, then jump to the bottom of the existing text.
Simply append the following code:

function pageLoad() 
{
    var element = document.getElementById("ctl31_ctl10");
    if (element)
    {
        element.style.overflow = "visible";
    } 
}


Save the file, and restart Reporting Services - you should now find that Chrome displays your reports again.


You’ll need to find the correct ElementId, by viewing the Source of the report in Chrome. If you search for “VisibleReportContent”, you should find something like “VisibleReportContentctl31_ctl09”. Where the “ctl31_ctl09” is the ElementID you’re looking for!

Tuesday 26 March 2013

WPF - Programmatically Adding Buttons the MVVM Way

I recently came across a requirement to Programmatically Add Buttons to a WPF View in my MVVM based app. Obviously this is not entirely trivial as each Button must contain the correct Bindings to interact with the underlying ViewModel.

The way I tackled this was to use an ItemsControl, with a Canvas Control in the ItemsPanelTemplate. I then added a DataTemplate to the ItemTemplate, with our Button Template in this.

This Button Template contained the relevant binding to hook up the Command Property to my ViewModel.

For ease of use, I then created a Class which housed the various Properties I wanted to expose to each Button, such as it’s Position, CommandParameter and Content, and allowed me to return a Tickness for the Button Position.

From here I created an ObservableCollection of my new Button Class, and bound this to the ItemsControl.

The code can be seen below;

XAML:

<Window x:Class="MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
    <Canvas x:Name="MyCanvas">
        <ItemsControl ItemsSource="{Binding MyButtons}" Height="237" Width="507">
            <ItemsControl.ItemsPanel >
                <ItemsPanelTemplate>
                    <Canvas IsItemsHost="true"></Canvas>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Button Margin="{Binding ControlMargin}" Content="{Binding Content}" Command="{Binding DataContext.ButtonCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" CommandParameter="{Binding ProductId}"></Button>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Canvas>
</Window>

FluidButton Class:



 

Public Class FluidButton
 
    Public Property Content As String
    Public Property LeftPos As Double
    Public Property TopPos As Double
    Public Property ProductId As Double
 
    ''' <summary>
    ''' Returns the Control Margin, using the Class Properties
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public ReadOnly Property ControlMargin As Thickness
        Get
            Return New Thickness With {.Left = LeftPos, .Top = TopPos}
        End Get
    End Property
    
End Class

Properties:



 

    ''' <summary>
    ''' Our Collection of Buttons or Products
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property MyButtons As ObservableCollection(Of FluidButton)
 
    ''' <summary>
    ''' Used to expose the Button Pressed Execute Commands to the UI for Binding
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>Newed up in the Form Load Event</remarks>
    Public Property ButtonCommand As DelegateCommand
Adding Buttons:


 

MyButtons = New ObservableCollection(Of FluidButton)
 
MyButtons.Add(New FluidButton With {.Content = "Test1", .LeftPos = 0, .TopPos = 20, .ProductId = 1})
MyButtons.Add(New FluidButton With {.Content = "Test2", .LeftPos = 40, .TopPos = 30, .ProductId = 2})
MyButtons.Add(New FluidButton With {.Content = "Test3", .LeftPos = 80, .TopPos = 40, .ProductId = 3})
MyButtons.Add(New FluidButton With {.Content = "Test4", .LeftPos = 120, .TopPos = 50, .ProductId = 4})
MyButtons.Add(New FluidButton With {.Content = "Test5", .LeftPos = 160, .TopPos = 60, .ProductId = 5})