Blog posts


  • Sync user and login for SQL database

    February 01, 2011 | Tags: Frax, Database, Troubleshooting, SQL, Snippet
    Got a login on your SQL server and the same user in a database but they are not connected? Even though the names are the sames the unique IDs are not. Here's a snippet from my college Fredrik that's very useful connecting the user name between server login and database user. Replace 'user' with 'your user name':
    EXEC sp_change_users_login 'Auto_Fix', 'user'

    And a small celebration! This is the 100th post :)

  • Use default values in Javascript

    January 28, 2011 | Tags: Javascript, Nils, Snippet
    This cool way to use default values for javascript function parameters was provided by Nils:

    <script>

    function(param1) {
    param1 = param1 || "my default value";
    }

    </script>

    Update: Fixed typo in the script above (| should have been ||), thanks Nathan for pointing that out! Took the opportunity to add an alternative way to implement below:
    <script>

    function(param1) {
    param1 = typeof param1 !== 'undefined' ? param1 : "my default value";
    }

    </script>

  • Add Using by shortcut in Visual Studio 2008

    January 20, 2011 | Tags: C#
    There's a nice little keyboard shortcut to resolve namespaces and add the to the using directives.

    When trying to use a class that is outside of the using directives present the editor will display it as an error since it doesn't know of the namespace that the class we want to use.
    There's a little dropdown arrow in the lower right where you can add the using statement. But there's an even faster way.

    While standing on the class name, just press CTRL + . (that's holding down CTRL and then .) and you get up the options for which namespace to use. Often just enter is needed to add the preselected.

  • Major Microsoft code sample library

    January 18, 2011 | Tags: ASP.NET, Windows, Open source, C#, Snippet
    The Microsoft Community team provide an awesome collections of code samples over at CodePlex.

    Among these you can find:

    # ASP.NET Code Samples
    # Silverlight Code Samples
    # Windows Azure Code Samples
    # WPF Code Samples
    # Windows Forms Code Samples
    # Windows 7 Code Samples
    # Data Platform Code Samples
    # Office Development Code Samples
    # Windows Workflow Code Samples
    # Interop and Fusion Code Samples
    # Windows Base and .NET General Code Samples
    # Windows UI Code Samples
    # Security Code Samples
    # Windows Shell Code Samples
    # XML Code Samples
    # COM Code Samples
    # IPC and RPC Code Samples
    # Diagnostics Code Samples
    # Visual Studio Extensibility Code Samples
    # File System Code Samples
    # IIS Code Samples
    # Windows Service Code Samples


    You'll find the samples in the All-In-One Code Framework Sample Catalog.

    Or why not download the complete library?

  • Get version info from SQL backup

    January 17, 2011 | Tags: SQL, Snippet
    This neat little snippet shows you alot of information from a SQL database backup (.bak file)

    RESTORE HEADERONLY

    FROM DISK = N'c:\temp\dbMyDatabase.bak'

    WITH NOUNLOAD;

    If this doesn't work you're probebly trying to run it on an older SQL Server version than the backup was taken from.

    Unfortunately I haven't found a proper lookup table to translate the version number to SQL Server version, but here's two:
    611 = SQL Server 2005
    655 = SQL Server 2008

    If you find a good resource for version lookup, please post it in the comments, thanks!