ASP.NET 4.0 Features

May 27th, 2009 by Sameer | No Comments | Filed in Uncategorized

Here is a list of new features in ASP.NET 4.0.

Very interesting. Auto start feature, new ways to choose where data is cached, built in option for compression session (via gzip), and more!

LINQ to Entities Create Function Import Scalar Value Missing

April 9th, 2009 by Sameer | No Comments | Filed in .NET articles

LINQ to Entities seems really great. It can save you a lot of time in writing unnecessary db connection code, improve the performance many fold, only connect to the db when required (lazy loading), and easy concurrency handling for you.

However there is a missing feature which I found out the hard way. If you try to do a ‘Create Function Import’ and it returns a scalar, the code will not be automatically generated, due to ‘lack of time’ from the MS Team:

MSDN Forums – See the post by Noam.

So basically, you are handicapped! Either write the code yourself or just do it the old fashioned way

Write .NET 3.5 in a .NET 2.0 World

April 2nd, 2009 by Sameer | No Comments | Filed in Uncategorized

Wow, sweet. Use .NET 3.5 features in .NET 2.0.

A quick overview how to do it.
1. Edit your .CSPROJ file and manually add another reference to System.Core
Add a True

This will make the compiler copy it to the BIN folder.

Thats it. You can now use .NET 3.5 features

Copy Data from One SQL Instance to Another

February 3rd, 2009 by Sameer | 2 Comments | Filed in Uncategorized

When using SQL Server Management Studio you might want to copy data from one DB to another (using just a SELECT and INSERT statement)

It’s so easy you won’t believe it

sp_addlinkedserver @server='192.168.123.456', @provider='SQLNCLI',    @srvproduct='',@provstr='User Id=sa; Password=are-you-crazy-to-use-sa'

insert into [192.168.123.456].MYDB.dbo.tblRecords

select * from MYDB.dbo.tblRecords

and when you are done

sp_dropserver  [192.168.123.456]

References:
sp_addlinkedserver on MSDN

sp_dropserver on MSDN

What is hnc.cgi ?

December 13th, 2008 by Sameer | No Comments | Filed in Uncategorized

hnc.cgi is a spam script. Its also known as dm.cgi.

If you have this script running, chances are your server has been exploited.

Here is the actual dm.cgi script if you want to see it.

Changes in __doPostback in .NET 1.1 to .NET 2.0

November 27th, 2008 by Sameer | No Comments | Filed in Uncategorized

Before and After

If you manually want to simulate a postback, Here is how you would stick together a string manually calling __doPostBack in .NET 1.1
In this case its making a link in a particular linkbutton control inside a datagrid.

__doPostBack in .NET 1.0

string link = "<a href=\"javascript:__doPostBack('dataGridCart$_ctl" + i + "$linkButton','');\"";

__doPostBack in .NET 2.0

string link = "<a href=\"javascript:__doPostBack('dataGridCart$ctl0" + i + "$linkButton','');\"";

Dont use this function any more.  Use Page.GetPostBackClientHyperlink from .NET 2.0+.  This is because they might change __doPostBack yet again and your code will be broken.

Look at the comment thread on this codeproject article for more details

Further reading: Do Postback Hijacking

Tracking Influenza (flu) with Google Trends

November 13th, 2008 by Sameer | No Comments | Filed in Uncategorized

This is quite an astonishing use of Google Trends.  Google realized that when people get sick they (obviously) search for flu related keywords and they managed to find a correlation to actual published flu infection statistics.  Quite amazing and this is definately a unique and interesting application of technology.

How we track flu trends (Google blog)
Here is an explanation of how it works

What other ideas can we apply this to?

Read Pro ASP.NET 2.0 in C# free

November 11th, 2008 by Sameer | No Comments | Filed in .NET articles

Due to a recent agreement between Google and some book publishers, they are going to publish a large number of books online (limited content depending on each publishers agreement).

So you can now read Pro ASP.NET 2.0 C# for free online (a large chunk of it)!  Click the link for more.  This book is jam packed (1000 pages+) with well-written details on everything under the sun in .NET 2.0.  I was in particular looking for SQL Cache Dependency information which I found in there.

Apparently in SQL Server 2000, Cache Dependency is done on a table basis, you cannot have it dependent on a certain condition (for example select * from CONTACTS where location=’canada’).  If any data at all changes inside CONTACTS then the cache is considered invalidated and you will need fresh data.   Lots of improvements in SQL Server 2005 boys….

How to get session or other custom values into ELMAH

November 10th, 2008 by Sameer | No Comments | Filed in Uncategorized

In “Timing is Everything” I mentioned how I successfully managed to convince management to install ELMAH.  I wanted to add some comments as to how to easily get some values into ELMAH that you might have in your SESSION.

The easy way, with no code changes, is simply store those values in a COOKIE.

HttpCookie c = new HttpCookie("CUSTOMVAL");
c.Value = (string) Session["CUSTOMVAL"];
Response.Cookies.Add(c);

Viola! It will be in the ELMAH Error page!

Resharper by JetBrains

October 21st, 2008 by Sameer | No Comments | Filed in Software Engineering

What can I say.. I am impressed.. Very impressed.  Try it out now – Resharper.  Commercial license is only $349.00
What did I achieve?  Few small things at the moment, improved “extract this into a method” functionality, suggesting when to use “const” for strings, site-wide analysis for problems, convert method to static.  Very cool..
Here’s a list of features

Add parameters easily with Resharper

I was able to take a piece of code inside the function, say AccountsReceivable.GetReferenceNumber(“abc001″) and convert that to a parameter of my helper function just by highlighting it and selecting “introduce parameter”.  It then went ahead and updated all references to this function to pass the AccountsReceivable.GetReferenceNumber(“abc001″) as if it was a variable

Create variables to replace common values

Here’s another case.  Imagine you have some reference to something like dr["status"].ToString(), you can “Introduce Parameter” and it will ask you if you want to update just that one line, or update ALL references inside that function wtih the new variable name…  pretty neat!

Also have you encountered the situation where some variable is declared near the top of a function and then its used somewhere in the middle… and you are stuck wondering whether you can get rid of it or you can modify the code without breaking it ?  Well Resharper will allow you to join the declaration with the intiialization, so its re-partnered to its vaue :)

Easily worth the $350 price tag.

You will get the most bang for your buck in the first month or so anyway, use it to clean up and spiffy your app, and then try not to let it descend back into chaos.

Tags: