Galin Iliev's blog

Software Architecture & Development

Visual Studio Codename "Orcas" timetable

Visual Studio Codename "Orcas" timetable was released on MSDN2.

Here is it:

Visual Studio code name "Orcas"

In addition to developer productivity improvements and new supported platforms and technologies in Visual Studio, Visual Studio code-named “Orcas” release will include the following new scenarios, features and improvements to Visual Studio Team System.

Projected Availability:

  • Beta 1 - 2nd Quarter, CY 2007
  • Beta 2 - Mid-year CY 2007
  • RTM - TBA

It seems we will have more stable releases soon :)

C# architect Anders Hejlsberg does ... VB on MVP summit

I came across Jim Wooley's blog where C# architect Anders Hejlsberg does demo with VB. :)

I find this very interesting and I decided to share with you :)

I have nothing against VB (except a few thigs :) ) and I do VB from time to time because of specific tasks. The biggest VB advantage against C# is optional parameters. To do this in C# you will have to declare buch of methods overloads.

I don't want to turn this into discussion which one is better. I just find interesting Wooley's post Anders does VB!

Protect your ASP.NET website from DoS attack

DoS is not Disk Operating System :). This stands for Denial of Service attack and briefly described is when to many calls are made to your service so it stops responding to intented users/customers. for more info see Wikipedia.

MS MVP Omar AL Zabir wrote good blog entry about how to prevent DoS attacks on ASP.NET sites and expecially web services.

When you make good ASP.NET application and clear most of the bugs (yep nobody is perfect) it is time to adjust it to be high available and fast respondible Prevent Denial of Service (DOS) attacks in your web application is good start to protect your creation from so called hackers attacks :)

 

Enable RibbonX intellisense in Visual Studio

I had interesting experince with customizing Ribbon within VS 2005.

At first place I was able to get very helpful intellisence in VS IDE. After some time I had to edit .xml fiel but... no intellisense. well ... what to do?!

I intalled VSTO - I didn;t have it after last reinstall. and bingo - I've got it again... until today...

What happened?! Why?!  I just don't know - (probably most of us hears customer, friends and relatives that phone us with strange PC question and says - Yesterday it worked and I haven't touched anything! :)  ) Same thing here :)

But I know how to enable that intellisense again. And this is how:

  1. You need customUI.xsd and Visual Studio 2005 :)
  2. place customUI.xsd in %programfiles%\Microsoft Visual Studio 8\Xml\Schemas  and this is it. You must have it.

There are some other ways to enable intellisence for xml in VS 2005. You can find them on Aaron Stebner's blog post.

Connection pooling and application domains

Yesterday I wrote about my Connection pooling tests and I had good comment from Marto Kulov about application domains.

It was easy so I wrote the following code to create new application domain and execute two forms from different assemblies in order to test if they share same connection pool

 

   1:  AppDomain domain = AppDomain.CreateDomain("myNewDomain");
   2:   
   3:  Form frm1 = domain.CreateInstanceFromAndUnwrap("WindowsApplication1.exe", "WindowsApplication1.Form1") as Form;
   4:  Form frm2 = domain.CreateInstanceFromAndUnwrap("WindowsApplication2.exe", "WindowsApplication2.Form1") as Form;
   5:   
   6:  frm1.Show();
   7:  frm2.Show();

And the answer is Yes, They share same connection pool. Both forms executed same for loop and opened 10 connections each to the MS SQL Server. And on the SQL Server side was only one connection alive.

So this is the way to share a connection pool between two processes - put them in one process and in one application domain.

 

 

Connection pooling

Two days ago I decided to dive into connection pooling secrets. What a coincidence with Sahil Malik as he wrote blog article about his research same day J.

In addtition to his article I can describe what I tested. As I have job to do I will miss screenshotsL.

We were considering option to pass data to SQL SPs usign connection string and we wanted to know how this affects connection pooling. So I created simple winform application with a button with the following.

   1:  string connString = @"data source=.\SQLExpress;
   2:                      user id=gu; password= 123; 
   3:                      Initial catalog = master;
   4:                      Workstation ID=test_host{0};
   5:                      Pooling=true;
   6:                      Connect Timeout = 60";
   7:   
   8:  for (int i = 0; i < 10; i++)
   9:  {
  10:      SqlDataReader dr = null;
  11:      string cmdText = "SELECT date=getdate()";
  12:      SqlConnection cn = new SqlConnection(string.Format(connString, 1));
  13:      SqlCommand cmd = new SqlCommand(cmdText, cn);
  14:      try
  15:      {
  16:          cn.Open();
  17:          dr = cmd.ExecuteReader();
  18:          if (dr != null)
  19:          {
  20:              while (dr.Read())
  21:              {
  22:                  Console.WriteLine(dr["date"].ToString());
  23:              }
  24:          }
  25:      }
  26:      finally
  27:      {
  28:          if (dr != null) dr.Close();
  29:          cn.Close();
  30:      }
  31:  }

I used same SQL statement as Sahil to determine number of physical connection to database.

After executed the following code I got only one connection opened. Note that connection string is always same as I pass 1 as parameter in string.Format(connString, 1) on line 12.

Let’s change this to string.Format(connString, i). As expected I ended with 10 opened connections as connection string is different for every SqlConnection object.

Let’s undo change and use connection pooling again. We have for loop with 10 connection objects opened but only one physical connection is opened on SQL side.

Let’s start two instances of our test application and check what happens by clicking on buttons. We executed for loop once in each instance. By executing Sahil’s SQL statement we see two connections  although all 20 connection has same connection string.

I opened Activity Monitor from SQL Management Studio and I was able to see the connections – everything was same except Net Address. According the documentation:

Net Address

Assigned unique identifier for the network interface card on each user's workstation. When the user logs in, this identifier is inserted in the Network Address column.

Strang… both instances are on same machine…

So as conclusion the statement from Wikipedia’s Connection Pooling page – “A Connection Pool is a cache of database connections maintained in the database's memory so that the connections can be reused when the database receives future requests for data.

Is wrong… the pool is only on client side

As I missed the screenshots I will add another example in case I lost you somewhere above J

Connection pooling is pool of connection within instance of application! If you have two instances of same application that creates one connection to SQL  Server you will have 2 conenction to the server.

If these 2 instances created 20 connections each (with same connection string within the instance) there will be 2 connections on the server because connection pooling.

If these 2 instances created 20 connections each (different connection string each) there will be 2x20=40 connections on the server because connection pooling is done only on same connection string. 

C# 3.0 Partial Method Definitions

While I dug into Orcas March CTP Documentation I found another new C# feature (at least for me). It is called Partial Method Definitions and allows you to separate method definition and method implementation in partial classes.

//Definition

partial void partial void onNameChanged();

 

//Implementation

partial void onNameChanged()

{

  //method body

}

 

As I have C++ background this sounds familiar to me and reminded me times when I had to declare methods in .h (header) files and put implementation in .c/.cpp files.

To be honest I am not able to find the advantages of this new feature but I suppose there will be more blog post soon that will discuss this.

As I emphasize above you can separate method definition from implementation only in partial classes. There are number of restrictions stated in Orcas documentation:

  • Partial method declarations must begin with the contextual keyword partial and the method must return void.
  • Partial methods can have ref but not out parameters.
  • Partial methods are implicitly private, and therefore they cannot be virtual.
  • Partial methods cannot be extern, because the presence of the body determines whether they are defining or implementing.
  • Partial methods can have static and unsafe modifiers.
  • Partial methods can be generic. Constraints are placed on the defining partial method declaration, and may optionally be repeated on the implementing one. Parameter and type parameter names do not have to be the same in the implementing declaration as in the defining one.
  • You can not make a delegate to a partial method.

 

JScript IntelliSense in Visual Studio "Orcas"

JavaScript IntelliSense in Visual Studio "Orcas" March CTP - WOW That's awesome!!!

The guys from VS Web tools team did a great job and employ xml comments to make JS Intellisense possible.

Take a look at the screenshots below

ASP.NET AJAX Concepts in Completion List

IntelliSense from Script Libraries for ASPX Pages

There are much more...

Did I get your interest? See the full post at Web Development Tools Team blog.

Prevent multiple clicks on Submit button in ASP.NET

Recently I had to solve very common problem: When users what to submit the page by clicking on Submit button very often they become inpatient and click the button again which results in another button OnClick event firing (and if you save db record) duplicating records in database.

The most obvious solution is to use JavaScript to disable submit button. Unfortunately this easy solution is not the best because of number of reasons - see Andy Smit's blog entry you don't want to disable buttons after they are clicked here for more details.

So I decided to use another approach : I won't disable button with I will hide it and I show div element with text that would calm user down :). Thus buttons are visisble according ASP.NET but parent HTML element hides them :)

this is the aspx code that declares buttons


<div id="divButtons" style="display:inline;">
   <asp:Button ID="btnSubmit" runat="server" Text="Submit" CssClass="buttons" OnClientClick="SubmitButtonClicked();return true;" OnClick="btnSubmit_Click" style="padding-left: 10; padding-right: 10;"></asp:Button>

                   

   <input type="button" value="Cancel" onclick="javascript:top.hidePopWin(false);" style="padding-left: 10; padding-right: 10;"/>

</div>

 

<div id="divWait" style="display:none;">Note is being saved. Please wait respond from server...</div>                    

               


thus asp:Buttons controls fires SubmitButtonClicked(); javascript function before post the form.

Here is the js code:



function SubmitButtonClicked()

{

    if (typeof(ValidatorOnSubmit) == "function"){

        if (Page_ClientValidate() == false) {

            return false; }}

   

    $get("divButtons").style.display = "none";

    $get("divWait").style.display = "";

}


UPDATE: The function above is edited according the link below and all validators works as expected. :) Thanks John!

Although the bug I think it is good starting point.

You can see here for alternative solution - http://aspzone.com/blogs/john/articles/207.aspx