Tony’s Weblog

ASP.NET, MVC, AJAX, SilverLight, C#, WCF Web Service, SQL 2005 and other interesting stuff.

Archive for September, 2008

SQL Prompt Visual Studio .NET Add-on

Posted by Tony on September 1, 2008

SQL Prompt is Visual Studio .NET add-on. It makes writing queries very fast and easy and It does parse queries as you type and suggests keywords, table names, and join conditions (amongst others).

The demo below shows some of what SQL Prompt can do, though it also has support for Updates, stored procedures, and many other SQL statements. 14-day trail download is available here

Main features of SQL Prompt Visual Studio .NET add-on:

  • Intelligent code completion for fast, accurate script building
  • Cross-database and linked-server query support
  • Integrates with SSMS, SSMS Express, Query Analyzer and Visual Studio 2005
  • Keyword formatting, code snippet integration, column picker and many more features


Posted in Uncategorized | Leave a Comment »

Compression Decompression in .NET

Posted by Tony on September 1, 2008

DeflateStream and GZipStream classes present in System.IO.Compression namespace provide compression and decompression capabilities. GZipStream compresses the serialized content of application, with great results. These classes operate on file streams.


The compression through these classes will likely be less than what can be achieved with a file compression utility. But the good thing is that we have this functionality include in .NET Framework 2.0 and above. As Microsoft said this namespace will be further enhanced and modified in the next versions.

Posted in Uncategorized | Leave a Comment »

Implement a simple captcha in C#.NET

Posted by Tony on September 1, 2008

1. Create a page with name “Captcha.aspx”

2. Place the following html code in body part of the page

   1: IMG height="30" alt="" src=BuildCaptcha.aspx width="80">
   2: asp:TextBox runat="Server" ID="txtCaptcha">
   3: <asp:Button runat="Server" ID="btnSubmit"
   4:            OnClick="btnSubmit_Click"
   5:            Text="Submit" />
   7: 3. On “btnSubmit_Click” place the following code
   9: if (Page.IsValid && (txtCaptcha.Text.ToString() ==
  10:      Session["RandomStr"].ToString()))
  11: {
  12:   Response.Write("Code verification Successful");
  13: }
  14: else
  15: {
  16:   Response.Write( "Please enter info correctly");
  17: }

3. Include the following code in “BuildCaptcha.aspx

   1: Bitmap objBMP = new Bitmap(60, 20);
   2: Graphics objGraphics = Graphics.FromImage(objBMP);
   3: objGraphics.Clear(Color.Wheat);
   4: objGraphics.TextRenderingHint = TextRenderingHint.AntiAlias;
   7: //' Configure font to use for text
   8: Font objFont = new Font("Arial", 8, FontStyle.Italic);
   9: string randomStr = "";
  10: char[] myArray = new char[5];
  11: int x;
  13: //That is to create the random # and add it to our string
  14: Random autoRand = new Random();
  15: for (x = 0; x < 5; x++)
  16: {
  17:   myArray[x] = System.Convert.ToChar(autoRand.Next(65,90));
  18:   randomStr += (myArray[x].ToString());
  19: }
  21: //This is to add the string to session, to be compared later
  22: Session.Add("RandomStr", randomStr);
  24: //' Write out the text
  25: objGraphics.DrawString(randomStr, objFont, Brushes.Red, 3, 3);
  27: //' Set the content type and return the image
  28: Response.ContentType = "image/GIF";
  29: objBMP.Save(Response.OutputStream, ImageFormat.Gif);
  30: objFont.Dispose();
  31: objGraphics.Dispose();
  32: objBMP.Dispose();

4. There you go you can test the page with captcha. Happy Programming!

Posted in Uncategorized | Leave a Comment »

What Is the Service Factory?

Posted by Tony on September 1, 2008

Generally speaking, software factories represent a collection of guidance that helps architects and developers build a specific kind of application. Therefore, the Service Factory helps developers and architects build Web service applications. Web service applications are more than just the technologies that send and receive SOAP messages and expose WSDL contracts—they also include the functionality that is needed to fulfill the service’s behavior. Figure 1 illustrates the parts of the application, and their relationship with one another, the Service Factory will help you build.

Figure 1. Structure of a service built with the Service Factory

If you are already building services using WCF, the Service Factory also helps you build and secure those services.

The Service Factory provides the following benefits:

· Increased quality. It provides tested and accepted reusable assets, guidance, and examples that address common scenarios and challenges. It is based on patterns derived from proven industry and Microsoft practices.

· Increased predictability. The patterns & practices team works closely with the development teams responsible for building current and future generations of service and data access technologies. All services built with the Service Factory will be built in a predictable way, arrive at a predictable result, and will enable a predictable migration path to future technologies.

· Increased productivity. It includes automated code and configuration file generation for Visual Studio 2005. With this automation, developers can easily apply guidance in consistent and repeatable ways. Developers can also effectively use the .NET Framework without having to devote significant time to learning the necessary APIs.

· Increased flexibility.

The Service Factory is carefully designed according to proven practices, but it is also open and highly customizable. Architects and development leads can customize the factory to include the conventions, policies, and practices specific to a team or organization.

Posted in Uncategorized | Leave a Comment »