169 posts categorized ".NET"

December 23, 2008

TSQL variables and null

It has been quite sometime since I actually coded TSQL. So I had to kind of brush up the hidden knowledge over the weekend when I wrote a small stored proc for a personal project I am working on.
(expect to see something in Codeplex, if I can get it finished before the new year)

I declared a variable and wrote out some code as follow:

    declare @tempstring as nvarchar(max)

    <More code here>

    select @tempstring=@tempstring + ' ' + @word


I was kind of left scratching my head as @tempstring always seem to end up being empty, even when @word did have some data.

Then I remembered something from my start up SQL classes... anything+null is always null. So I initialized @tempstring to an empty string and viola, there the data was, correct and ready to use.

Having been working so much in VB that it actually took me quite a while to figure out those small klinks that are specific to TSQL.

This is the kind of situation that may really affect someone moving from C# to VB or vice versa too. :)

December 19, 2008

Randomness of a Random number

If you are really into statistical analysis you may be able to discuss at length about true random numbers and pseudo random numbers. Almost all random number generators are pseudo-random number generators.

In .NET you have two ways to generate Random numbers. The easiest is to use System.Random. This is the least random, but also the easiest to use. The other is to use the RNGCryptoProvider, which generates more random numbers, but is a lot more difficult to use.

The problem with System.Random, is that for a given seed, it always generates the same set of numbers. The problem is how to get a random enough seed to generate a sequence that is of value to you. Obviously the easiest is to use somekind of time related seed, say minutes or seconds or milliseconds. The issue with this is that the range of this is quite limited (ie. 0-60), but also that you may get the same seed if you have very iterative processing (ie. you run tight loops or multi-threaded apps).

So I just thought that maybe I can generate a GUID and use that as a seed. So I kind of came up with the following:


    1         'Using the GUID to generate a seed may be more random than using the now.milliseconds.

    2         Dim seed As Integer = Convert.ToInt32(Guid.NewGuid.ToString("N").Substring(1, 8), 16)

    3         Dim rand As New System.Random(seed)


Then I did some searching and found a related post which uses the Hash of the GUID rather than the Guid itself to create a seed here: This is like, so random! Some Randomness from System.Random

There was also another recommendation on using something like this:


    1            Dim seed As Integer = Now.Ticks Mod Int32.MaxValue


But I found that using this in a tight loop, I did get seeds that were the same. So though this may still work out for most cases, it is not as random as using the GUID.

Using the GUID is ofcourse a lot more complex operation on the processor and so may have an impact if you are generating a lot of random numbers.

November 24, 2008

PDC 2008 Vide Viewer and Downloader - Version 1.0.0.2 Available

Over the weekend I fixed up a couple of bugs in the PDC 2008 Video Viewer and Downloader( My WPF based Viewer and Downloader for PDC 2008 Videos). This version is not available for download in CodePlex. All releases in Codeplex also contain the Source code. Do not download the source from the Source tab. The Source tab is a older version of the source and not the latest.

November 14, 2008

PDC 2008 Video Downloader and Viewer - v 1.0.0.1

I have already fixed a couple of bugs in the application. To make it easier to download and manage versions I have created a CodePlex project to manager this applications.

I am not using the source code part of Codeplex. Instead, I will use the releases system to upload zips with both the source and the executables.

PDC 2008 Viewer and Downloaded on Codeplex

Version 1.0.0.1 is already uploaded.

November 12, 2008

PDC 2008 Video Downloader and Viewer

I couple of years back I wrote a .NET tool the just download the whole set of PDC videos for offline viewing. So when the PDC 2008 videos became available I thought I would update the tool. But then I thought that this gives me a chance to kind of mess around with some newer technologies and so wrote a PDC video downloader and viewer using WPF, VS 2008 and SQL CE 3.5.

Pdc_viewer
The whole source and executable are available for download below. I also added the session and speaker information that is available online at the PDC site, so it is a true Offline PDC viewing experience. I have also added a few extras like try and find out the blog of the speakers (this is based on an automated live search and so I expect that there are quite a bit of wrong links. If you can update the database and send it back to me, I would update the application).

Note that the application currently only downloads WMV-HD, so make sure you have enough free space on your HDD and bandwidth to download (from what I found searching online the videos will be 50+ GBs).

I don't have too much of error handling code, so expect crashes when things go wrong. If you find a bug, let me know, I will fix it when I get time.

Download pdc_2008_video_downloader_and_viewer_v1.0.0.zip

Continue reading "PDC 2008 Video Downloader and Viewer" »

November 06, 2008

Height or Width in WPF

In XAML, when you want your controls to resize based on the Container, you set the Height or Width property to "Auto". Yesterday, I wanted to set this from code and I could not find a way to do this. Height/Width is a Double and setting 0 actually makes the control invisible (or almost so).

A little bit of searching pointed me to MSDN. The answer is documented in MSDN, but not very easy to find unless you are the type who reads every line that appears in the related pages. I usually just read the main parts and skip to the examples. :)

"In addition to acceptable Double values, this property can also be Double..::.NaN. This is how you specify auto sizing behavior in code. In XAML you set the value to the string "Auto" (case insensitive) to enable the auto sizing behavior. Auto sizing behavior implies that the element will fill the height available to it."

http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.height.aspx

November 04, 2008

SQLCE Dev Problems

I was doing some dev in VS 2008 using SQLCE for some data storage.

As soon as I put in a reference to the ce namespace and run, I get this error "Unable to load DLL 'sqlceme35.dll'. A little bit of searching around and I found that for development you need to have your app built for x86 as SQLCE only supports 32-bit. I have a 64-bit machine and all VS projects by default get built as "Any CPU", which means my exes were being built for 64-bit. As soon as I set it to x86, everything worked fine.

Compiler_optionsIn Visual Basic, this option is available under My Project->Compiler->Advanced Compiler Setting


More information on this problem can be found below:

Can’t find P/Invoke DLL sqlcemeNN.dll
x64 and SQL Compact

Side Note: As per my research, SQL CE 3.5 SP1 is supposed to have native support for x64. I am not aware what version I am running on. But the version that ships with VS 2008 has this problem. When I do check out SP1, I will update this post.

October 30, 2008

The new face of .NET

After almost 5 years .NET goes for a facelift. MS has released a new logo for .NET.

Net_logo

The result is a design we refer to as the “wave.” The design is strong, simple and distinctive. The suggestion of the letter ‘N’ in the design will become instantly recognizable over time as shorthand for the .NET brand name.

Read More.

October 24, 2008

Team System - 2008/2005 integration

With Visual Studio 2008 out and a lot of developers moving to it, the back end part of the Team System Block, Team Foundation Server in most enterprises is still TFS 2005. There are a number of problems that can arise when you want to integrate your VS 2008 IDE with TFS 2005.

My colleague, Madhu has written an article on some of the problems you may face and how to get around these.

Download this article here:

Integrating Visual Studio 2008 with Team Foundation Server 2005 (XPS Format)

Get a XPS Reader. If you have .NET 3.0 or above, you already have a XPS viewer and should be able to open this document inside of IE.

October 17, 2008

Free MS Press eBook Chapters

MS Press is offering a couple of chapters from some of their new books free for download.

 

You may be required to sign in and register before being allowed to download. Also note, these are not the complete ebooks, but rather selected chapters only.