SSRS Performance with Option(Recompile)

Sometimes, SQL Server isn’t as great as it usually is and can cause SSRS Performance issues when running queries that execute fast inside SSMS.

Just the other week I was writing a simple join script against close to 200k records in each of the 3 join tables. The script in question was for a report with a certain degree of complexity, meaning a lot of options and filter where being made available to those viewing the report. This in turn, meant a lot of variable parameters within the report query.

This report came with SSRS Performance issues. The query itself ran in less than two seconds inside SSMS, but gave up running after 4 minutes through SSRS.

Continue Reading →

15. October 2014 by Adam Riddick
Categories: Business Intelligence, SQL, Tips | Leave a comment

Sql Server Reporting Google Chrome Fix

Two weeks ago, I blogged about the need for Reporting Systems to support and influence the decisions being made by any organisation. Today, I’ll explore a Sql Server Reporting Google Chrome Fix, to enable the viewing of SSRS reports in the Google Chrome Browser.

In the article two weeks back, I mentioned the availability of many different reporting systems, from Sql server Reporting through to Crystal Reports. The organisations I have worked in have used one of these solutions, though have found more success with Sql Server Reporting. It’s no secret that Google Chrome is a popular browser, or that Sql Server Reporting doesn’t play nice with Chrome.

This is why we require a Sql Server Reporting Google Chrome Fix. And it’s pretty straight forward.

Continue Reading →

11. October 2014 by Adam Riddick
Categories: Business Intelligence, SQL, Tips | Leave a comment

Editable User Friendly URL Structure in MVC

User Friendly URL’s

There is a logic behind user friendly URL structures on a website. No matter what you call them, Clean, User Friendly, SEO Friendly, or Semantic URL’s, the purpose behind them is to improve a website experience by ensuring the website URL’s maintain an intuitive meaning amongst non-expert end user’s.

I’ll explore this in a little more depth.

www.mywebsite.com/?q=hG728kos99Dmmhe%77cv

www.mywebsite.com/mens/shoes/loafers

Considering the above two URL’s, it’s clear to see the latter user friendly URL has a much clearer meaning to the user, and can potentially be easily altered, in a breadcrumb manner, to easily navigate the structure of your website.

Imagine trying to edit the first URL to show trainers instead of loafers, wouldn’t know where to start right?

Continue Reading →

02. October 2014 by Adam Riddick
Categories: ASP.Net, C# | Leave a comment

Reporting Systems: A Requirement’s Document

Reporting Systems: The Needs

Reports, Reports, Reports.

There isn’t a single reason as to why a business maintains a set of reports, but the information provided by a solid reporting structure can be the difference between a booming business, and a receding one.

A report could have been made for legal reasons, a financial audit trail for example. They could offer operational insight to the businesses capacity, and be used to monitor behavioural patterns through the business operation, which allows for judgement calls to be created based on historical patterns, such as staffing levels and stock control.

No matter the reason for the report, when it has been correctly represented, it can make the world of difference to a business. Though, the opposite can be said of a poor report backed by poor data, which highlights the need for business analysts who understand the patterns in data and can act upon poor information, ensuring decisions won’t be made on erroneous information.

But static reports can’t do that. As the needs of an organisation change, the reporting solution in place must adapt to accommodate the new requirements. The reporting system is an assistant to that change, enabling a smoother transition from the old and into the new.

Reporting Systems: The Truth

Continue Reading →

25. September 2014 by Adam Riddick
Categories: Business Intelligence | 1 comment

C# Inherit from multiple interfaces with clashing method names

Recently, in one of those many projects on the go, I was working on an interface between two individual systems that are required to talk to each other. I can’t discuss much about the project itself, white label and all, but I can abstract to a level to explain the solution to a problem I stumbled across, which was the need to Inherit from multiple interfaces with clashing method names.

As you are probably aware, in the C# environment you can inherit from multiple interfaces without any great difficulties, we use the following template;


public interface IFoo

{

    void DoFoo();

}

public interface IBar

{

    void DoBar();

}

public class FooBar : IFoo, IBar

{

    public void DoFoo()

    { //Foo Happens }

    public void DoBar()

    { //Bar Happens }

}

But a less known concept is the ability to inherit from multiple interfaces with clashing method names, but first let me explain.

I’ll use the example of a solution to log stock values between two systems, let’s say they are stock provisioning systems. Each system allocates stock to varying clients by different means, one through a web interface, an e-commerce system, and the other through the manual scanning of a products barcode by a store worker (For completeness, well say this is an Argos style store, in which you order your goods and wait for the warehouse team to bring them down). Reporting is required to allow real-time transfer of the data into a single logging file.

To this end, a solution is being implemented in the middle of the two systems, we’ll call them A and B.

Continue Reading →

18. September 2014 by Adam Riddick
Categories: C#, Tips | Leave a comment

C# Dynamically Load Types From DLL

Reflection is a great way to allow us to Dynamically Load Types From External DLL’s.

I love reflection. I learned about Reflection when I started creating FakeModel, and haven’t looked back since. I use Reflection in many projects for lots of different purposes, and it solves problems in each and every one of them that would have required architectural changes without it. One such problem can be solved using reflections ability to dynamically load types from external DLL’s at runtime.

In order to dynamically load types from external dll’s, we can use the following snippet;


string dllPath = "c:\users\mypath\somewhere\else\myassembly.dll";

Assembly assembly = Assembly.LoadFrom(dllPath);

Type type = assembly.GetType("MyType");

dynamic instanceOfMyType = Activator.CreateInstance(type);

//We can now call the methods, but won't have intellisense

string result = instanceOfMyType.MyMethod("A Parameter", 7);

Which is rather straight forward.

As we use the dynamic keyword, we won’t get intellisense and the compiler won’t generate errors if calls against instanceOfMyType are wrong, keep this in mind when testing.

First, we define the full path to the dll file. This could be done searching directories and filtering files, or by direct access if you know the location.

Adding Some Peace Of Mind

The above snippet is great, but will fall flat on its face in the presence of a tampered DLL. For example, if somebody got hold of the dll and create a constructor on “MyType” which wiped the hard disk, we’d have some pretty unhappy clients.

To protect against this, we can use a checksum against the DLL. This will require pre-computation of the checksum so that a valid checksum can be used. For this, MD5 will suffice as it is faster than other Hashing algorithms.


static byte[] generateMD5(String filepath)
{
    using (FileStream stream = File.OpenRead(filepath))
    {
        return MD5.Create().ComputeHash(stream);
    }
}

Once we have a pre-computed hash value, we can check that against the DLL as we load it, giving the Hash and the method used to produce the hash as parameters;


string dllPath = "c:\users\mypath\somewhere\else\myassembly.dll";

//byte[] hash = ... Pre-Computed Hash Here, or the line below ...

byte[] hash = generateMD5 (dllPath);

Assembly assembly = Assembly.LoadFrom(dllPath, hash, AssemblyHashAlgorithm.MD5);

Type type = assembly.GetType("MyType");

dynamic instanceOfMyType = Activator.CreateInstance(type);

//We can now call the methods, but won't have intellisense

string result = instanceOfMyType.MyMethod("A Parameter", 7);

With the help of this snippet it’s possible to dynamically load types from dll’s at runtime in a secure manner.

Of course, you may want to go one further and add further security to the DLL itself.

 

You can read more about reflection on MSDN.

11. September 2014 by Adam Riddick
Categories: C# | Leave a comment

Introducing Foreign Key Constraint May Cause Cycles Or Multiple Cascade Paths

Introducing Foreign Key Constraint May Cause Cycles Or Multiple Cascade Paths

“Introducing Foreign Key Constraint May Cause Cycles Or Multiple Cascade Paths” may be a message you have seen before when using Entity Framework. The error message is thrown when a relationship being built by Entity Framework has multiple paths in which it can cascade a delete, without knowing which to choose.

Entity Framework doesn’t contain a mechanism to make a choice on a cascade path, so we must remove the cascade for the relationship to work.

Before exploring the fix, well take a look at a scenario that will cause the “Introducing Foreign Key Constraint May Cause Cycles Or Multiple Cascade Paths” error.

Introducing Foreign Key Constraint May Cause Cycles Or Multiple Cascade Paths

Introducing Foreign Key Constraint May Cause Cycles Or Multiple Cascade Paths

Continue Reading →

03. September 2014 by Adam Riddick
Categories: Databases, Entity Framework | Leave a comment

Isolating Unit Tests with Microsoft Fakes

Isolating unit tests is a large requirement of unit testing. Quite often, individual units of code will rely on, or access,  other sections to do their processing. For example, a method that saves an entity to the database will call a method in a repository that is responsible for the actual saving.

Such methods, as they stand, can only be unit tested by containing the requirement. For example, to unit test saving to the database you would require a database for testing, or do something ill-advised and test against a live database. Which is a bad idea, even inside a Transaction (Once upon a time I was very naïve and did this myself, tut tut!).

Thankfully, Isolating Unit Tests doesn’t have to be difficult.

There are many approaches to Isolating Unit Tests, which I suppose depends on the Unit Test Framework you are using. Personally, I use MsTest, Visual Studio’s built in testing suite, and to date I have found no reason to change, and within MsTest we can utilise Microsoft Fakes when Isolating Unit Tests.

Continue Reading →

23. August 2014 by Adam Riddick
Categories: C#, Testing, Tips | Leave a comment

MemoryCache V1.2.0

Announcing MemoryCache V1.2.0

Yesterday I was giving some thought to my small collection of NuGet packages, and I had told myself that MemoryCache V1.2.0 was just about due. Then I recieved an email shortly after 11pm last night from Erik Zettersten putting forward an idea that would improve the usage of MemoryCache.  So I decided to spend some time on some improvements to MemoryCache, and here we are with MemoryCache V1.2.0.

Erik pointed out that a setup, such as the following, could be improved with an Update method, which would improve the first block of code.


if (Cache.Exists(key))
 {
         int newItem = (int)Cache.Get(key)++;
         Cache.Remove(key);
         Cache.Store(key, newItem);
 }
 else
 {
         Cache.Store(key, 1);
         Cache.AddExpiration(key, 1000);
 }

Erik also pointed out a frustration. MemoryCache would not retain the original expiration, and to keep the original expiration, some form of tracking would be required. He suggested an Update method that would persist the original expiration time.

Continue Reading →

14. August 2014 by Adam Riddick
Categories: MemoryCache, News | Leave a comment

.Net Interview Q & A Resources

.Net Interview Q & A

Generally speaking, I’m an anxious person.

Not in the sense that I fear what is going to happen, on the contrary, I think that I’m a bit excitable when it comes to new things, and I drive myself mad with anxiety until the experience is done. Which in itself is a challenge. It’s tiring, and it does make it hard to enjoy things, in an epitomised sense.

But it does mean I enjoy a lot of experiences that many people find daunting, such as interviews, the topic for the day.

This week I found myself introducing a colleague to the Joel Test. For those of you who are unfamiliar and don’t want to click the link, the Joel Test is an unequivocal system to determine the quality and maturity of a software team.

I’ve experienced both ends of the scale of the Joel Test. A team who scored 4, which my influence turned into an 8 before moving on, to leading a team which, in the manner we operate, scores 9. This however, disappoints me. There is nothing preventing us from pushing this to a healthy 12, which we have the resources to maintain as a long-term position.

The reason I mention the Joel Test, if one of the points eludes many software companies but is a critical measure of maturity;

Do new candidates write code during their interview?
Would you hire a magician without asking them to show you some magic tricks? Of course not.

– Joel Spolksy

Continue Reading →

12. August 2014 by Adam Riddick
Categories: Bits & Bobs, Experiences, Tips | Leave a comment

← Older posts