Copy Data from One SQL Instance to Another

February 3rd, 2009 by Sameer | No 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:

Automated .NET testing with WatiN

October 20th, 2008 by Sameer | No Comments | Filed in .NET articles, Software Engineering

This software is super cool.  WatiN – Automated Web Application Testing!

Here’s how you can use it.  Download it.  Download the test recorder (it’s not perfect, but its pretty good).  Create a trivial test case so you know it’s working.  Then build on that test case.    It will output code for NUnit, MBUnit, or even VS2005Test

Load up your VS IDE, then execute it from Visual Studio 2005 or 2008 Test Runner.    It will give you the results right there!  Super cool or what??

With this framework I was able to create some pretty simple test SUPER fast.  – Login test, check for correct page loaded.   Then I tested some shopping cart logic (adding items, removing items, clearing cart.)

In conclusion you can effectively create tests with WatiN.  Give it a try.  It’s compatible with practically every testing framework (including Fitnesse) that you probably use.

Tags:

.NET Blogging Softwares

October 7th, 2008 by Sameer | 2 Comments | Filed in Hosting

When I first started this blog, it was done in Subtext, which is a very impressive .NET blog software. It is a fork off the old .TEXT blog engine. To give you a bit of history, .TEXT codebase was left and eventually became Community Server. That was my preferred choice of blogging engines, but I did not want to pay money for it at this point in time when I wasn`t even sure if I was going to have time or energy to continue the site over the yeras.

Actually Wordpress was really the option I wanted, being the most popular and the most feature comprehensive blogging software out there (tons of plugins, tons of templates/themes, and so on)…

Now, Subtext can work great for you if you are willing to contribute some features. Otherwise you will find yourself dependent on a code base maintained by just a few people (rapidly growing, no doubt), but really in this case my business is blogging, not contributing to .NET blogging softwares, so I am abandoning the Subtext ship and switching to Wordpress.

Some of the new features on this site you will find

  • faster response rate due to caching plugin
  • see related posts at the bottom of each post
  • subscribe to comments so that you can continue the discussion if someone responds to you
  • and more coming…

I wanted to add these features to make the site more interactive for everyone, plus nicer looking (I don`t have time to develop my own theme, I plan to utilize an already existing one online).

Lets see where it goes :) So for me, the clear winner is Wordpress (even though its not running .NET).
I claimed that .NET is superior to PHP, however, of course, that does not mean that every single software written in PHP sucks, nor that every .NET software rocks.. Far from it

Setup ASP.NET 1.1 on VISTA

October 7th, 2008 by Sameer | 2 Comments | Filed in Uncategorized

As strange as it sounds, yes, you might need to setup ASP.NET 1.1 and VISUAL STUDIO 2003 to work on VISTA.

Here’s how to do it. I read maybe ten other pages and tried tons of different things but this is the definite guide on how to make ASP.NET/VS2003 work on Vista.

Thanks dude!

A few comments about developing on Vista. I am running a lenovo T61 (Vista 32bit) with 2GB ram with VS, IIS7, SQL Server 2008 with Full Text catalog, and the whole works, so when memory was getting full (i.e. had Outlook open, Excel open, as well as all that other stuff) it was actually TOTALLY FREEZING for literally 5 minutes a time (even the clock was frozen).

I managed to remedy this problem by buying and using a ReadyBoost compatible USB disk and I don’t have this problem any more. Try it out. I think it’s a pretty creative and useful feature that they put in Vista!