Contents tagged with .NET

  • sp_lock2 and sp_lockcount

    Here are two helpful procedures to help with sqlserver database work. 

    1. The code for both of these are based on the system stored procedures sys.sp_lock that comes built in the master database.
    2. build both of these in your master database if you want to use them in all databases across your database instance.
    • sp_lock2 -- provides object_name for the object_id normally presented with sp_lock
    • sp_lockcount -- provides a count of the locks. useful when doing etl processes and you are monitoring locks but do not care to receive the tens of thousands of lock data coming back...when all you want to know is the count.

    sp_lock2 code

    USE [master]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- ==================================================================
    -- Author:        Mathew Nolton (based on sp_lock in sqlserver)
    -- create date: 05/15/2009
    -- Description:    Returns lock information similar to sp_lock but
    --                with additional object name information.
    -- ==================================================================
    create procedure [dbo].[sp_lock2]
        @spid1 int = NULL,        /* server process id to check for locks */
        @spid2 int = NULL        /* other process id to check for locks */
    as
        -- ======================================================================================================
        -- set options
        -- ======================================================================================================
        set nocount on
        set transaction isolation level read committed
    
        -- ======================================================================================================
        -- do the work.
        -- ======================================================================================================
        select     convert (smallint, [req_spid])    as [spid],
                [rsc_dbid]                        as [dbid],
                db_name([rsc_dbid])                as [dbname],
                [rsc_objid]                        as [ObjId],
                object_name([rsc_objid])        as [ObjName],
                [rsc_indid]                        as [IndId],
                object_name([rsc_indid])        as [IndName],
                substring ([v].[name], 1, 4)    as [Type],
                substring ([rsc_text], 1, 32)    as [Resource],
                substring ([u].[name], 1, 8)    as [Mode],
                substring ([x].[name], 1, 5)    as [Status]
        from     [master].[dbo].[syslockinfo] [s]
                inner join [master].[dbo].[spt_values] [v]
        on        [s].[rsc_type]        = [v].[number]
                inner join [master].[dbo].[spt_values] [x]
        on        [s].[req_status]    = [x].[number]
                inner join [master].[dbo].[spt_values] [u]
        on        [s].[req_mode] + 1    = [u].[number]
        where    [v].[type]            = 'LR'
        and        [x].[type]            = 'LS'
        and        [u].[type]            = 'L'
        and        ( @spid1 is null or [req_spid] in (@spid1, @spid2) )
        order by [spid]
    
    

    sp_lockcount code

    -- ==================================================================
    -- Author:        Mathew Nolton (based on sp_lock in sqlserver)
    -- create date: 05/15/2009
    -- Description:    Returns count of locks.
    -- ==================================================================
    create procedure [dbo].[sp_lockcount]
        @spid1 int = NULL,        /* server process id to check for locks */
        @spid2 int = NULL        /* other process id to check for locks */
    as
        -- ======================================================================================================
        -- set options
        -- ======================================================================================================
        set nocount on
        set transaction isolation level read committed
    
        -- ======================================================================================================
        -- do the work.
        -- ======================================================================================================
        select     count(*)
        from     [master].[dbo].[syslockinfo] [s]
                inner join [master].[dbo].[spt_values] [v]
        on        [s].[rsc_type]        = [v].[number]
                inner join [master].[dbo].[spt_values] [x]
        on        [s].[req_status]    = [x].[number]
                inner join [master].[dbo].[spt_values] [u]
        on        [s].[req_mode] + 1    = [u].[number]
        where    [v].[type]            = 'LR'
        and        [x].[type]            = 'LS'
        and        [u].[type]            = 'L'
        and        ( @spid1 is null or [req_spid] in (@spid1, @spid2) )
    

    Read more...

  • Add-In for updating all reference paths in a solution

    Update Project References Add-In 

    Visual Studio doesn't natively support the ability to update all selected project's within a Solution with the same reference paths. This is important (at least to me) if you have to download from your source control system a different version of your source code. Since you typically do not check in your project preferences into source control, you will be stuck with the mundane task of selecting your project, setting the reference path, select the next project, etc.

    This add-in enables you to select a given set of projects within your solution, set your reference paths and make updates across all selected projects. For example:
    UpdateReferencePaths Image

    You have a couple of options

    1. Completely Replace Existing References...enough said
    2. Do nothing if a reference exists (and append to end of list if it doesn't)
    3. Prepend to List...(note: if the reference already exists, it will be moved).
    4. Append to List...(note: if the reference already exists, it will be moved).

    To use the add-in, copy the files UpdateReferencePaths.AddIn and UpdateReferencePaths.dll to your add-in directory. Typically, this is located at: C:\Documents and Settings\[Your User Name Here]\My Documents\Visual Studio 2005\Addins

    Get the Add-In and the source code here: http://www.cybral.com/tools.aspx#updatereferencepaths

    -Mathew Nolton
    http://www.cybral.com

    Read more...

  • Using skmRss.RssFeed

    I have been evaluating the use of Scott Mitchell's RSSFeed control for a new version of my website (it's not done yet) for my consulting company that focuses on the Cable Sector of the Telecommunications Industry and I wanted to display relevant information for both Web Services and the Cable Sector. The control is very nice (and free). During my investigation I wanted to perform a couple of actions that were not quickly apparent but still quite doable once I dug a bit deeper. Specifically, I wanted to be able to:

    Read more...

  • Creating your own XmlSerializer

    Very recently I came across an issue that required the creation of a new class derived from XmlSerializer. For reasons I don't want to get into here, we serialize an object instance into XML and store it into a database column so that we can reconstitute it later. This is a great approach except for the issue of changing class definitions.

    Read more...

  • New Version of XmlPreCompiler

    Well, I finally got around to making the XmlPreCompiler even easier to use. As some of you may or may not know, the XmlPreCompiler is a tool based on a tool Chris Sell's originally created to help developer's handle the xml serialization error:

    Read more...

  • Part 2: Consulting in the Cable and Wireless Sectors....The Power of the Bundle....

    The Cable sector as well as the entire Telecommunications industry has been expending a large amount of resources to sell bundled products and services. This means that instead of just offering Analog and Digital Cable Services, Cable and Telecommunication Companies are offering Cable, High Speed Internet, Digital Telephone, Digital Video Recorders, High Definition TV, etc. in a "Bundled" product.

    Read more...

  • Fail Fast

    I found this paper about "Failing Fast" while reading Paul Lockwood's blog. It refers to Martin Fowler's wiki about writing code to Fail Fast. This technique has been around for a while; however,  I honestly have always been more of a proponent of writing defensive code. 

    Read more...

  • Be Careful Generating XML Documentation with .Net

    If you are like me, you like to use the XML commenting feature that comes with .Net. Personally, I only turn this feature on when I am creating a release build. However, if you do this make sure that you turn-off the read-only property on the output xml file. Failure to do so can will cause your build to fail.

    Read more...

  • Using the <remove> tag with web.config can be helpful.

    Most people use the web.config file to define features or pieces of functionality to be used by their application. You may or may not know it, but there is a feature of the web.config file that enables you to remove definitions defined by a parent web.config file. This is especially important when an application (either rightly or wrongly) places a web.config file in the root web directory or your parent directory that adds functionality or puts a constraint on all child directories that you do not want or that will break your application.

    Read more...