|
 Wednesday, February 21, 2007

Google Maps on your Mobile

If you're like me, you visit new places quite often and you need to find your way around. Or, maybe you're just terrible with directions and you can't find your way out of a wet paper bag, either way, its Google to the rescue.

For awhile now Google has offered Google Maps for mobile devices.

I installed it on my Blackberrry 7105t. I swear to the gods that be, I use this thing DAILY.

Uses
Finding stores: "Target in Stamford, CT". BLAMMO! It finds it.

Directions: Get directions to and from a location.

Favorites: Store favorite locations, such as home, work, the wife's office, etc. This saves a TON of typing on a handheld.

How to get it

Go to www.google.com/gmm on your mobile phone.

Supported Devices:

  • Most Java-enabled (J2ME) mobile phones.
  • Palm devices with Palm OS 5 and above.
  • All color BlackBerry devices.
  • Windows Mobile devices with Windows Mobile 2003, 5.0 and above.

I've seen it installed on Razr's as well as a few Sprint phones (not sure what models) that have internet access.

Once you get this bad-boy installed, you'll never be lost.

#    Comments [0] |
 Tuesday, February 20, 2007

Updated: Formatted XML From SQL

In my previous post I showed you how to return XML from the SQL Server Database. To further this topic, you can also format your XML to use Xml elements. This time, we're going to take a list of Customers and view their orders along with some information from the order, thats right, its straight from MSDN (with a couple tweaks).

This SQL Query will return Xml formatted as formatted elements.

USE AdventureWorks;
GO

SELECT TOP 10
     Customer.CustomerID,
OrderHeader.CustomerID,
OrderHeader.SalesOrderID,
OrderHeader.Status,
Customer.CustomerType
FROM Sales.Customer Customer, Sales.SalesOrderHeader OrderHeader
WHERE Customer.CustomerID = OrderHeader.CustomerID
ORDER BY Customer.CustomerID
FOR XML AUTO, ELEMENTS, ROOT('Customers')

Returns:

<Customers>
   <Customer>
      <CustomerID>1</CustomerID>
      <CustomerType>S</CustomerType>
         <OrderHeader>
            <CustomerID>1</CustomerID>
            <SalesOrderID>43860</SalesOrderID>
            <Status>5</Status>
         </OrderHeader>
         <OrderHeader>
            <CustomerID>1</CustomerID>
            <SalesOrderID>44501</SalesOrderID>
            <Status>5</Status>
         </OrderHeader>
         <OrderHeader>
            <CustomerID>1</CustomerID>
            <SalesOrderID>45283</SalesOrderID>
            <Status>5</Status>
         </OrderHeader>
         <OrderHeader>
            <CustomerID>1</CustomerID>
            <SalesOrderID>46042</SalesOrderID>
            <Status>5</Status>
         </OrderHeader>
      </Customer>
      ...
<Customers>

 

Explanation

The XML AUTO mode tells SQL Server to return the data in a XML format. We have provided the Sales.Customer table an alias of "Customer". If I had not done this, the results would have printed each element as:

<Sales.Customer>...</Sales.Customer>

This is not desirable.

The ELEMENTS option tells SQL Server to return the data as Xml elements, not as attributes. Had we eliminated this from the query, our query would have returned this:

<Customers>
   <Customer CustomerID="1" CustomerType="S">
      <OrderHeader CustomerID="1" SalesOrderID="43860" Status="5" />
      <OrderHeader CustomerID="1" SalesOrderID="44501" Status="5" />
      ...
   ...
</Customers>

This can work, but this time I wanted to demostrate the ELEMENT option.

The ROOT('Customers') allows us to set a root Xml element named "Customers".

 

Conclusion

While this may not be the next best thing you've ever seen, its still cool and it can save you time in the long run. Possible uses might include a quick way to get data out of your system and into a XML format for a one time use. Or you could use it for your data access layer and have it return XML to the business layer that might be used in a web service.

Its been reported that working with large XML Docs in .NET can be memory intensive, so perhaps this might help in processing and in saving memory on that server thats running on an old desktop that your boss had laying around. (We've all worked at a company who had a 'server' which was nothing more than a beefy desktop sitting in the server room.) :)

kick it on DotNetKicks.com

#    Comments [0] |
 Monday, February 19, 2007

Generate XML in SQL

You can easily generate Xml from a DataTable by using the .WriteXml() method.

But you can also bypass this and retrieve the Xml directly SQL Server 2005 by running the following command:

USE Northwind;

SELECT    EmployeeID,
        LastName,
        FirstName
FROM    dbo.Employees
FOR XML AUTO;

 

This will return an Xml representation of the data that looks like this:

<dbo.Employees EmployeeID="1" LastName="Davolio" FirstName="Nancy" />
<dbo.Employees EmployeeID="2" LastName="Fuller" FirstName="Andrew" />
<dbo.Employees EmployeeID="3" LastName="Leverling" FirstName="Janet" />
<dbo.Employees EmployeeID="4" LastName="Peacock" FirstName="Margaret" />
<dbo.Employees EmployeeID="5" LastName="Buchanan" FirstName="Steven" />
<dbo.Employees EmployeeID="6" LastName="Suyama" FirstName="Michael" />
<dbo.Employees EmployeeID="7" LastName="King" FirstName="Robert" />
<dbo.Employees EmployeeID="8" LastName="Callahan" FirstName="Laura" />
<dbo.Employees EmployeeID="9" LastName="Dodsworth" FirstName="Anne" />

For more information on FOR XML and its modes, click here.

#    Comments [0] |
 Tuesday, February 13, 2007

The hidden Trace page, trace.axd

Most developers dont know about the virtual trace output page available in ASP.NET. This page allows you to see the Trace Output provided by ASP.NET. You can view many statistics about the pages that have been executed on the system.

The virtual page trace.axd is enabled by enabling tracing in your application by enabling tracing in the web.config file like this:

<trace enabled="true" />

You can now compile and run your web page. Hit refresh a few times to get some info into the trace cache.

Visit the trace.axd file by typing it manually into your browser address bar.

For Example: http://localhost:1234/TraceExample/trace.axd

When yo view this page, you should see something similar to this:



Click on the "View Details" links and you'll see the trace out put listed for that request. (Note: I have cut off the image because there is too much data listed to list in this post. Download the example and try it out yourself to see all the details.)




How To Write Info To The Trace
You can write information to the trace by using the Trace.Write method.

Trace.Write("We're writing to the trace output.");


In the downloadable example below, I override the OnPreRender event and write info to the trace. By doing this:

protected override void OnPreRender(EventArgs e)
{
Trace.Write("We're inside of the OnPreRender Event.");
base.OnPreRender(e);
}

This will write info to the trace, which can be viewed on the trace output page:


*Note: The trace.axd can only be viewed when executed on the local machine where the pages are being executed from.

Download Example

TraceExample.zip (1.77 KB)
#    Comments [0] |
 Wednesday, February 07, 2007

Simian Upgrade

For those of you who use Simian, please be aware, they upgraded the product and the old "-recurse" option no longer works. Read below on how to fix it.

The Issue

I downloaded it last night to test it with my teams current continuous integration environment through Cruise Control .NET (CCNET).  I looked at some examples on the CCNET website on how to run this as a NAnt task and found that it should be fairly easy. I just needed to recurse through the directories and have it run on all C# files (*.cs). Unfortunately I was getting a "Invalid Option" each time I ran this code:

simian-2.2.13.exe -recurse=*.cs -formatter=xml:simian.xml

 

The Issue, Part 2

I finally figured out that the docutmentation on the CCNET site was incorrect. The new product removed the -recurse option and replaced it with -includes and -excludes options to resemble the file globbing method of retrieving files.

I then ran the command as they recommended on the site:

simian-2.2.13.exe -includes=**/*.cs -formatter=xml:simian.xml

I then got this error: "Error: Illegal characters in path."

 

The battle continues

I continue to battle this until I finally give up I try wrapping paths in quotes, executing using different syntax, passing in different wild cards. I combed the documentation with a fine tooth comb, only to find, NOTHING.

 

Resolution

I resorted to emailing support to ask for help.

To my amazement, I had a reply within 2 hours stating that I found a bug in the new release. They said they would fix it and upload a new version ASAP. 5 Hours later, the new version was live on the site.

I downloaded the new version, version 2.2.14, and ran the command

simian-2.2.14.exe -includes=**/*.cs -formatter=xml:simian.xml

I ran the command and the system placed my results into my requested XML File. I was now able to integrate it into my continuous integration system.

With it in place, I can now see my similiarity results.

Cruise Control .NET Website support link

#    Comments [0] |