Tuesday, March 29, 2005

In a web application, it’s often useful to be able to find out the geographic location of your visitors. For instance, you could use that data to either render the page in a language native to that geography or you could supply user with geographically relevant information. (Google for instance redirects you to google.co.in if you are coming from an IP that belongs to an ISP in India). There are of course caveats – the user might be coming from behind a proxy server which is different from his actual geography. (Often happens to me at work!). Worse still the user could be traveling and checking your website from a cybercafé in Thailand. There are ways you can handle these exceptions gracefully but for now let’s focus on finding user’s country given his IP.

First of all you need to get hold of the IP to Country database. You can obtain it in CSV format from: http://ip-to-country.webhosting.info/ (thanks Anil). The database is updated regularly and you should check for updates every month or so. The database contains a series of IP ranges and the country corresponding to each range. You can import it (DTS) into SQL Server. Your table could look something like:

Note that we are using bigint data type for the IP data since the IP addresses in the csv file are not in the dotted decimal notation. Once you have the data in this table, you can simply use the stored procedure below to find the country corresponding to an IP (ok so this is not the most elegant piece of t-sql you’ll see but then t-sql has never been my strong point):

Monday, March 14, 2005

You can find the code snippets used during the VSTO workshop in Bangalore on Saturday here. A few of you asked about the complete process by which an office document loads an assembly and executes it. This slide sheds light on it: