Tuesday, 28 February 2012

Cannot create database diagram


Got this today on SQL 2008 R2. Work around was this one...

Right click database in  management studio then click properties.
select "files" page
then set owner as "sa"

    • Proposed As Answer by Jerome2606 Wednesday, January 11, 2012 11:46 AM

    Visual Studio hanging / running slowly

    Suffered from this today, and discovered that deleting the large > 350MB .suo file for the solution fixed the problem.

    Turns out that if you use a lot of bookmarks, and break points this file can grow exponentially, as the file never appears to decrease in size, even after deleting old breakpoints and book marks, only keeps growing!

    Baretail, showed that devenv.exe was just constantly writing out that same lines to the .suo file over and over again.

    Have renamed the .suo file now, and VS appears to be working a little better. Not sure what project / solutions settings I will be missing though.

    Also appears from Proc mon that it keeps trying to find the .suo file for the solution


    However, VS is behaving fine for now, so going to keep on working like this.

    More info about it here


    There is however a work around that someone has listed on the community content section of this msdn post, on how to create a macro that will automatically delete the .suo file after the solution closes.


    How to prevent the .suo file from being persisted.

    It is possible to do this with macros that respond to the IDE's SolutionEvents.BeforeClosing and SolutionEvents.AfterClosing events.

    1. In the BeforeClosing event, store the value of the DTE.Solution.FullName property in the EnvironmentEvents module.
    2. In the AfterClosing event, get the .suo file by using System.IO.Path.ChangeExtension on the stored file name.
    3. Delete the file with File.Delete.

    Bam. No more persisted .suo files for any VS 2010 solutions. An absolute MUST if your 150-project solution takes 20+ minutes for C# IntelliSense to load.


    Stick this in the Public Module EnvironmentEvents body...

    Dim solutionName As String

    Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing

        solutionName = DTE.Solution.FullName

    End Sub

    Private Sub SolutionEvents_AfterClosing() Handles SolutionEvents.AfterClosing

        Dim suoFilePath As String

        suoFilePath = System.IO.Path.ChangeExtension(solutionName, "suo")

        If Not System.IO.File.Exists(suoFilePath) Then
        End If

        Dim fileInfo As System.IO.FileInfo = New IO.FileInfo(suoFilePath)

        If fileInfo.Length > 3000000 Then '3MB file size would be quite large.

            Dim response As MsgBoxResult

            response = MsgBox("The solution user options file '" & suoFilePath + "' is " _
                              & fileInfo.Length.ToString() & _
                              " bytes large. Do you wish to delete this file in order to increase the performance of the solution?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, _
                               "Delete solution user options file?")

            If response = MsgBoxResult.Yes Then


            End If
        End If

    End Sub


    Further to this, I've just been informed of this trick as well for speeding things up...

    Another solution I’ve used in the past is to close Visual Studio, then clear the cache.

    You would go to C:\Users\[user]\AppData\Local\Microsoft\Team Foundation\[version#]\Cache, and delete all contents. In older Windows versions, you would navigate to C:\Documents and Settings\[USER]\Local Settings\Application Data\Microsoft\Team Foundation\[Version#]\Cache, and delete all contents.

    The first time you start VS after that will be a little slow, as it has to recreate the VersionControl settings, but after that you should see a big improvement.

    Using Beyond Compare with TFS source compare




    1. In Visual Studio Choose Options from the Tools menu.
    2. Expand Source Control in the treeview.
    3. Click Visual Studio Team Foundation Server in the treeview.
    4. Click the Configure User Tools button.
    5. Click the Add button.
    6. Enter ".*" in the Extension edit.
    7. Choose Compare in the Operation combobox.
    8. Enter the path to BComp.exe in the Command edit.
    9. In the Arguments edit, use:
      %1 %2 /title1=%6 /title2=%7

    3-way Merge (v3 Pro)

    1. Follow steps 1-6 above.
    2. Choose Merge in the Operation combobox.
    3. Enter the path to BComp.exe in the Command edit.
    4. In the Arguments edit, use:
      %1 %2 %3 %4 /title1=%6 /title2=%7 /title3=%8 /title4=%9

    2-way Merge (v3 Std, v2)

    Use the same steps as the 3-way merge above, but use the command line:
    %1 %2 /savetarget=%4 /title1=%6 /title2=%7

    Monday, 27 February 2012

    NuGet training video


    I was watching perhaps the best training video I've ever watched on the weekend http://channel9.msdn.com/Events/MIX/MIX11/FRM09, and one of the libraries they were saying they can't live without is ELMAH (Error Logging Modules and Handlers) …

    Also checkout Scott Hansleman coding from a dos prompt about 18 mins into the first video link… Class


    Also worth noting that codeplex.com is based on a hybrid of both ASP.NET webforms and MVC.

    Assuming you guys all have NuGet installed for VS 2010 extensions, then I can thoroughly recommend the MoodSwings package written by Phil Haack (mate of Scott H's).

    To install, open the package manager console window, and simply type Install-Package MoodSwings

    The command .. Set-Mood Rick will then provide you hours of fun ;)




    Monday, 20 February 2012

    How to transpose row data to column data in Excel

    Say you have a row of data, and you want to lay it out vertically as a column instead, then you can simply select the row, copy it to the clipboard, and then using Microsoft Excel, from the paste special menu, select the Transpose option...


    How to concatenate multiple rows into one row in TSQL

    The following query will achieve this quite nicely.

                '; ' + COALESCE (Surname + ',' + Forename + ' ' + MiddleInitial ,  Surname + ',' + Forename, Surname)
                FROM Person
                FOR XML PATH('')),

    The important pieces of this query are that we're using the STUFF function to remove the starting '; ' from the resulting string, and also using FOR XML PATH('') to get the results of the inner SQL select into a single row result set instead of 10 rows.

    Results come back in the format...

    Surname1, Forename1; Surname2, Forename2; Surname3, Forename3

    Wednesday, 1 February 2012

    Composite key mapping in NHibernate


    Create your identifier class...

    public class CategoryProductIdentifier {
            public virtual int ProductId { get; set; }
            public virtual int CategoryId { get; set; }

            public override bool Equals(object obj)
                if (obj == null)
                    return false;
                var t = obj as CategoryProductIdentifier;
                if (t == null)
                    return false;
                if (ProductId == t.ProductId && CategoryId == t.CategoryId)
                    return true;
                return false;
            public override int GetHashCode()
                return (ProductId + "|" + CategoryId).GetHashCode();

    Update your existing class to make use of the identifier class

    public class CategoryProduct
            private CategoryProductIdentifier _categoryProductIdentifier = new CategoryProductIdentifier();
            public virtual CategoryProductIdentifier CategoryProductIdentifier
                get { return _categoryProductIdentifier; }
                set { _categoryProductIdentifier = value; }

            private Product _Product;
            public virtual Product Product
                get { return _Product; }
                set { _Product = value;
                    _categoryProductIdentifier.ProductId = _Product.Id; }

            private Category _Category;
            public virtual Category Category
                get { return _Category; }
                set { _Category = value;
                    _categoryProductIdentifier.CategoryId = _Category.Id; }
            public virtual string CustomizedProductDescription { get; set; }


    Change your mapping to make use of the new <composite-id> mapping for the key

    <class name="CategoryProduct" table="CategoryProducts">
        <composite-id name="CategoryProductIdentifier" class="CategoryProductIdentifier">
            <key-property name="ProductId" column="ProductID" type="Int32" />
            <key-property name="CategoryId" column="CategoryID" type="Int32" />
            <version name="LastModifiedOn" type="timestamp" column="LastModifiedOn" />
        <many-to-one name="Product" column="ProductID" class="Product" insert="false" update="false" access="field.pascalcase-underscore" />
        <many-to-one name="Category" column="CategoryID" class="Category" insert="false" update="false" access="field.pascalcase-underscore" />
        <property name="CustomizedProductDescription" column="CustomizedProductDesc" />

    Ctrl+Shift+WinKey+B in Windows 10

    Ctrl+Shift+WinKey+B in Windows 10  This resets the graphics display on your laptop and can sort out lagging issues as well "Since yeste...