Tag: Uncategorized

  • XAML in Visual Studio

    The XAML previewer in Visual Studio is pretty bad and slow to load. You can get past this by setting XAML files to open by default in source code rather than the WPF Designer…

    1. Right click any XAML file
    2. Open With…
    3. choose Source Code (text) Editor
    4. Click the Set as Default button
    5. Click OK
  • Updating Silverlight 2 solution to Silverlight 3

    For my own reference these are the steps I took, and the problems I had. Naturally YMMV.

    Download the requisites from www.silverlight.net:

    • Silverlight 3 Beta Tools for Visual Studio
    • Blend 3 Preview

    Uninstall Silverlight 2 elements:

    • Blend 2
    • Silverlight Toolkit
    • Silverlight Tools
    • Silverlight SDK
    • Silverlight 2 Plugin

    Install the Silverlight 3 elements:

    • Install Silverlight 3 Tools
    • Install Blend 3 Preview

    Update the solution:

    • Check out all the files in the Solution. (ensure Read-only is off)
    • Open solution in Visual Studio 2008 – the conversion wizard will convert the SL projects.

    Troubles…

    Service references all wrong (custom tool errors for references.svcmap). Might have been caused by  the project files not being set to readonly the first time this was run. Might not. Anyway;

    • Uninstall
    • Reinstall
    • Update the service references
    • Check the configuration for the services is brining back collections as List (not ObservableCollection)
    • Open and close the datasource files

    • Rebuild
  • SharePoint “Service Unavailable”

    I had this problem recently. Turns out the problem on my environment was an expired password for the account under which the SharePoint Central Administration application pool was running (DOMAIN\WSSSERVICE). Policy removed, password updated, problem solved.

    There are lots of other solutions too…

  • Finding missing numbers in a sequence

    From http://www.sqlservercentral.com/articles/Datetime+Manipulation/61822/

    Find Missing Numbers

    It is obvious that, to find missing numbers, we need to have a table or resultset which contains all the numbers. Then we can apply a NOT IN clause and identify the missing numbers.

    If you are wondering, why I needed missing numbers, here is the reason. In one of my applications, there is an entity that we call coordinator. Each coordinator has a 4 digit numeric code. The code starts at 1000 and ends at 9999. (There is no chance that we will have more than 9000 coordinators at any point of time, so a 4 digit code is sufficient). When the user creates a new coordinator, the system automatically generates a new coordinator number. However, the user can still edit it. The system will allow the user to edit the coordinator number (during a new entry) as long as it does not produce a duplicate code.

    With the above functionality, we needed a way to reuse un-used/missing numbers. When we create a new coordinator, we need to find the lowest unused coordinator code. For this purpose we needed a way to identify the missing numbers.

    As mentioned earlier in this article, I did not want to keep a temp table. I want to generate the numbers on the fly. There are several ways to do this. I like to use a CTE to do this.

    In one of my previous articles, I had presented a way to generate a sequence of numbers by using a CTE. It was fast. But a faster code fragment was posted by Kathi Kellenberger in the discussion forum. It was taken from Itzik Ben-Gan’s book “Inside Microsoft SQL Server 2005 T-SQL Querying”. Here is the code fragment which generates 1 million records in the fraction of a second. [code]

    WITH
    L0 AS (SELECT 1 AS C UNION ALL SELECT 1), --2 rows
    L1 AS (SELECT 1 AS C FROM L0 AS A, L0 AS B),--4 rows
    L2 AS (SELECT 1 AS C FROM L1 AS A, L1 AS B),--16 rows
    L3 AS (SELECT 1 AS C FROM L2 AS A, L2 AS B),--256 rows
    L4 AS (SELECT 1 AS C FROM L3 AS A, L3 AS B),--65536 rows
    L5 AS (SELECT 1 AS C FROM L4 AS A, L4 AS B),--4294967296 rows
    num AS (SELECT ROW_NUMBER() OVER(ORDER BY C) AS N FROM L5)
    SELECT N FROM NUM WHERE N <= 1000000;

    This code is VERY VERY fast and I find it to be the best candidate for generating a sequence of numbers on the fly. I wanted to re-use this code and hence I created a function that takes a Minimum and Maximum value and returns a resultset containing sequence numbers within the given range. [code]

    CREATE FUNCTION dbo.GetNumbers
    (
    @Start BIGINT,
    @End BIGINT
    )
    RETURNS @ret TABLE(Number BIGINT)
    AS
    BEGIN
    WITH
    L0 AS (SELECT 1 AS C UNION ALL SELECT 1), --2 rows
    L1 AS (SELECT 1 AS C FROM L0 AS A, L0 AS B),--4 rows
    L2 AS (SELECT 1 AS C FROM L1 AS A, L1 AS B),--16 rows
    L3 AS (SELECT 1 AS C FROM L2 AS A, L2 AS B),--256 rows
    L4 AS (SELECT 1 AS C FROM L3 AS A, L3 AS B),--65536 rows
    L5 AS (SELECT 1 AS C FROM L4 AS A, L4 AS B),--4294967296 rows
    num AS (SELECT ROW_NUMBER() OVER(ORDER BY C) AS N FROM L5)

    INSERT INTO @ret(Number)
    SELECT N FROM NUM WHERE N BETWEEN @Start AND @End
    RETURN
    END

    Once we have the function to generate the sequence number, we can easily write the code to identify the missing numbers. [code]

        1 SELECT MIN(Number)

        2 FROM dbo.GetNumbers(1000, 9999)

        3 WHERE Number NOT IN (SELECT CoordinatorID FROM Coordinators)

    Find Missing Dates

    I guess the requirement to find missing dates must be more common than the missing number requirement I mentioned above. To find the missing dates (Dates at which no sales took place, Dates at which a given employ was absent etc) we need to have a table or resultset which contains all the dates within a given range.

    The following example shows how to generate a sequence of dates using the same logic we discussed earlier. [code]

    --Generate a sequence of all the dates for the month of October, 2007

    SELECT
    CAST('2007-10-01' AS DATETIME) + Number-1
    FROM dbo.GetNumbers(1, 30)
    --Generate a sequence of all the dates for year 2007

    SELECT
    CAST('2007-01-01' AS DATETIME) + Number-1
    FROM dbo.GetNumbers(1, 365)

    Once we have a sequence of dates, we can easily apply a NOT IN clause and find the missing dates based on the specific requirement.

  • Are you sitting comfortably?

    …Then we shall begin…

    Blogs are brilliant. There are a ton of brilliant contributors out there that make learning new technologies so simple. So i guess that it’s high time that I stop leeching so much information and start giving something back too.. I don’t expect too much interaction, this is more about logging my thoughts and findings, and if someone else can benefit from that, then great!

    So this blog is going to be about anything I wan (it’s mine after all)… expect information on .NET coding, Silverlight, WCF, ASP.NET (MVC, jQuery, Dynamic Data etc), Photography and so on.

    ..the name… well it appeared to be one of only a few that remained..damn bloggers…

  • Debugging Replication Errors

    use distribution
    --------------------------------------------------------------------------------
    select top 100 e.*, * from MSrepl_commands c inner join MSrepl_errors e on c.xact_seqno =e.xact_seqno order by e.id desc
    --------------------------------------------------------------------------------
    exec sp_replmonitorhelpsubscription @publisher=NULL, @publication_type=0
    --------------------------------------------------------------------------------
    exec sp_helpdistpublisher
    --------------------------------------------------------------------------------
    exec distribution..sp_replmonitorsubscriptionpendingcmds @publisher=pubservername, @subscriber=subservername, @publisher_db='pubdbname', @subscriber_db='subdbname', @publication='pubname', @subscription_type=0
    --------------------------------------------------------------------------------
    exec sp_replqueuemonitor @publisher = pubservername, @publisherdb = 'pubdbname', @publication = 'pubname', @tranid = NULL, @queuetype = 0
    --------------------------------------------------------------------------------
    exec sp_replshowcmds
  • Dropping Replication

    when struggling to drop a publication or subscription from the API, try one of these:

    use [SysTest_1]

    exec sp_dropsubscription @ignore_distributor =1,@publication = N'all', @subscriber=N'all',@article = N'all'

    exec sp_droppublication @publication = N'all',@ignore_distributor =1

    exec sp_removedbreplication 'systest_1'
  • Trusted Logins

    Trusted logins with IIS and IE6.

    Tools | Internet Options | Security Tab | Intranet Zone | Security Levels | Custom Level

    Scroll to the bottom of the list and make sure that User Authentication | Logon is set appropriately.