SQL Server 2008 R2 Intellisense broken after upgrading from SQL Server 2008

by Kev Ritchie 16. September 2011 13:05

After spending the last day trying to figure out why; after upgrading from SQL Server 2008 to 2008 R2, my intellisense stopped working, it turns out that all you need to do is install SQL Server 2008 R2 SP1 – Simples.

That is all Winking smile

TFS Build Error MSB4019

by Kev Ritchie 12. May 2011 14:05

I’ve managed to get some time to look at a problem that started a while back after we upgraded a project to Visual Studio 2010, thankfully it was a relatively easy one to fix.  But, I thought I’d post a resolution to it anyway, just in case.

During our daily build we kept getting the following error:

“error MSB4019: The imported project "C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.”

To resolve the error, you need to create the folder structure (C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\) on the build server and copy the Microsoft.WebApplication.Build.Task.dll and Microsoft.WebApplication.targets files from your development machine to the new directory on the build server.

You should now get a successful build Smile

Reflection and Non-Public Properties

by Kev Ritchie 23. November 2010 11:34

Ever wondered how to get to those Non-Public properties of an object?

With Reflection, here’s how you do it:

object propertyValue = anyObject.GetType().GetProperty("TheProperty", 
BindingFlags.Instance | BindingFlags.NonPublic).GetValue(anyObject, null);

All you need to do is replace “anyObject” with the name of object you are trying to get the Non-Public property from, then change “TheProperty” to the name of the Non-Public property you are trying to access.

A little explanation.

When we call the GetProperty method on a type, we supply some parameters to search the associated object with.

Our first parameter is the name of the property that we’re looking for.  The second parameter; BindingFlags, is a bitmask comprised of one or more BindingFlags that specify how the search is conducted; in really basic terms, a filter.  In the example above, we are specifying a Binding Flag of Instance, this must be specified in order to get a return from the search.  We are then using an “Or” operator to tell the search that we want to include Non-Public properties.

The GetValue method is then called to return the value of the property you were looking for.

Hope this is of some use to someone and if anything else will be a little reminder to myself in case I forget Winking smile

MS Access vs. Visual Studio LightSwitch

by Kev Ritchie 14. November 2010 11:59

On 3rd August at VSLive! 2010 in Redmond; Corporate Vice President of Visual Studio, Jason Zander, unveiled Visual Studio LightSwitch.

Yes, it’s taken this long for me to get around to writing about it.

What is LightSwitch?  LightSwitch is a member of the Visual Studio family targeted at developers who need to rapidly build LOB (Line of Business) Applications.

What relevance does this have to Access?

Well, recently a colleague of mine was asked to look into LightSwitch as an alternative to building database applications using Access.  Yes, there are still applications in use today that use Access!  So, I thought I’d take this opportunity to find out if LightSwitch really is; what has been seen by some developers, as a replacement for Access.

It seems that even though Access was developed as a package to help business end users store, report on and share business data with other business end users, the Access package has been leveraged by developers to create what you could class as LOB applications.

This brings to light a common issue with this type of development. Whilst this method of application development fits personal or small business usage, scalability of the application is limited.  As a business grows the reliance on the application grows and with it the data.  It wouldn’t be long before you had to compress and archive off the data, to allow for further storage.

Oh, and let’s not forget, have you ever seen a nice looking Access application UI? J  If you have or have created one, then I apologise.

To overcome the issues of using Access as a platform for developing business applications, I believe, is where LightSwitch comes in.

I fully understand that at first glance, LightSwitch seems to be a glorified version of Access with a Visual Studio IDE.  But look closer!  You are getting so much more.  Here are a few that I thought were worth mentioning:

Out-of-the-box you get a classic three tier architecture built on top of .NET (WCF, RIA Services and Entities), ASP.NET and Silverlight. Nice!

Microsoft are also working with Partners, like Infragistics, to develop Shell and Theme components that developers can install to dramatically change the look and feel of their application at the click of a button.  If you’re rubbish at UI design like me, this is a brilliant addition.

You also have the ability to connect to data sources such as SQL Server and SharePoint.  But Access 2010 can do that as well, so why was it worth mentioning?  Well, really to highlight the point that the major difference between the two packages is that LightSwitch is capable of connecting to the Cloud (Windows Azure and SQL Azure Platform) albeit Post beta.  Ah, scalability!

So, is LightSwitch a replacement for Access?

In my honest opinion, LightSwitch is not a replacement for Access.

LightSwitch is a product that gives developers the tools to provide feature-rich and scalable business applications that can be deployed to multiple platforms.

Access is a product that; as I mentioned before, is for allowing business end users to store, report on and share business data.  It was never intended to be a platform to build business applications.

Now that LightSwitch is here, the weight of being a business application can be taken off of Access’s shoulders!

The lines are clearly defined between these two products and both are here to stay.

For more information on LightSwitch and the Keynote from VSLive! head over to http://www.microsoft.com/visualstudio/en-us/lightswitch. You won’t be disappointed.

AnonymousType to DataTable madness!

by Kev Ritchie 5. November 2010 21:53

Today I was working on converting a project over to WPF.  Everything was going well until I needed to put the results of a LINQ query into a DataTable.

There didn't seem to be any easy way to do it, unless I'm being really blind Laughing.  Well, after some research and tinkering, I chucked together this little handy method:

private DataTable QueryResults<T>(IEnumerable<T> anon)
{
    DataTable results = new DataTable();
 
    if (anon != null)
    {
        PropertyInfo[] columns = null;
 
        foreach (T item in anon)
        {
            if (columns == null)
            {
                columns = ((Type)item.GetType()).GetProperties();
 
                foreach (PropertyInfo column in columns)
                {
                    Type columnType = column.PropertyType;
 
                    if ((columnType.IsGenericType) && (columnType.GetGenericTypeDefinition()
                        == typeof(Nullable<>)))
                    {
                        columnType = columnType.GetGenericArguments()[0];
                    }
 
                    results.Columns.Add(new DataColumn(column.Name, columnType));
                }
            }
 
            DataRow dr = results.NewRow();
 
            foreach (PropertyInfo column in columns)
            {
                dr[column.Name] = column.GetValue(item, null) == null ?
                    DBNull.Value : column.GetValue(item, null);
            }
 
            results.Rows.Add(dr);
 
        }
    }
 
    return results;
}
You can also pass in objects of type ISingleResult e.g Stored Procedures, into this method.

Have a go and let me know what you think

Powered by BlogEngine.NET 2.5.0.6
Theme by Mads Kristensen | Modified by Mooglegiant