Connection Pool Control in .NET 2.0

As known, connection pooling is an inbuilt feature of ADO.NET that internally caches open database connections to serve for later requests. While the need to manually clear the connections in the pool may not really arise, .NET 2.0 gives you a knob to do so. Meet these two methods:

System.Data.SqlClient.SqlConnection.ClearPool();

System.Data.SqlClient.SqlConnection.ClearAllPools();

However, these methods do not clear/close the connections in the pool immediately. Rather, the methods “mark” any existing connections in the pool for close so that they are not used to fulfill database connection requests – this forces to create a new connection and return it to the caller. The actual closing of connections will happen at a later point of time.

SetFocusOnError in ASP.NET 1.x

One of the cool features in ASP.NET 2.0 is the ability to set focus to the input control having invalid input. This is accomplished by setting the SetFocusOnError property of the associated validator control(s) to true. However, the same feature can be achieved in ASP.NET 1.x using the documented and undocumented client-side API of the ASP.NET validation framework. Here is how:


 


Plug in the following script block in the .aspx file

<script language=”javascript” type=”text/javascript”>


function setFocus()


{


  var refCtl = null;



 


  Page_ClientValidate();


  for (var i=0; i<Page_Validators.length; i++)


  {


    if (!Page_Validators[i].isvalid)


    {


      refCtl = document.getElementById(Page_Validators[i].getAttribute(“controltovalidate”));


      if (refCtl != null)


      {


        refCtl.focus();


      }


      break;


    }


  }


}

</script>


In the code-behind, have this one liner in the page’s load event:


<submit button>.Attributes.Add(“onclick”, “setFocus();”);


 


This code has been tested for ASP.NET 1.x with Internet Explorer 6+.

Tablet PC App Development

I was recently tasked with developing a utility for Tablet PC – this utility will let users sign using pen/ink and store the signature as an image file. Trust me, I have not even touched a tablet PC before (shameful!) and thinking about writing a utility, be it .NET or non-.NET looked as a big task.


Anyway, I decided to get my hands dirty and started searching MSDN to see what I need to do tablet PC development using .NET. Apparently what I all needed was just a 15MB file – Microsoft Windows XP Tablet PC Edition Development Kit (ver 1.7), thats it -I don’t even need a tablet PC (mouse can be substituted for the pen!).


After running through few articles through some googling and the SDK documentation, things became not at all complicated. All it took to accomplish the task – giving a ink surface to let the user sign using the pen and saving it as a file – was just less than 10 lines of code!


using Microsoft.Ink;
//…
InkOverlay InkOverlay1 = new InkOverlay(Panel1.Handle, true);
InkOverlay1.Enabled = true;
byte[] signData = InkOverlay1.Ink.Save(PersistenceFormat.Gif, CompressionMode.Maximum);
FileStream signFileStream = new FileStream(@”C:\SignImage.gif”, FileMode.Create);
signFileStream.Write(signData, 0, signData.Length);
signFileStream.Close();


I’ve attached the utility screenshot and the saved file. Power and productivity of of .NET!!