OdeToCode IC Logo

I Didn’t Expect These Features

Monday, October 25, 2004 by scott

What do MARS and the new Edit and Continue features have in common?

  • Both were technically difficult to implement
  • I never expected either to show up.

Whenever discussions cropped up about these features the pushback always seemed to indicate both required major disruptions to the lowest level code you can imagine, and possibly changing the gravitational constant. Now these features are here in beta.

Edit and continue (E&C) allows a developer to edit code in a running application and continue running the updated application without having to stop, compile, and launch the debugger again. It’s amazing the range of responses this feature generates. Jonathon Goodyear proclaimed it would be a colossal mistake for Microsoft to not ship this feature in 2005. Sam Gentile (who is a C# MVP, just in case he didn’t tell you), feels E&C will ruin software development.

In the end these discussions always collapse into some sort of three way language war between people who use semicolons, people who don’t use semicolons, and people who use Smalltalk. It’s odd how that happens. I wonder what happens inside the meeting rooms around Redmond when this feature came up for discussion?

I don’t see myself ever using E&C, except maybe once every two years when some weird bug crops up in a windows service with a long setup time. Given it has taken 4 or more years to work this hot potato into the runtime, I’m sure I would have picked other features I could use in day to day work and never miss E&C.

At least with E&C you can take it or leave it. MARS, on the other hand, seems to be sneaking in with an impact on anyone using the native .NET SQL Server client.

Multiple Active Result Sets (MARS) lets a client have more than one pending request on a given connection. What does this mean in code? Consider the following snippet:

SqlConnection connection = new SqlConnection("[connection string]");
connection.Open();
SqlCommand command = new SqlCommand("[query 1]", connection);
SqlDataReader reader = command.ExecuteReader();
SqlCommand command2 = new SqlCommand("[query 2]", connection);
SqlDataReader reader2 = command2.ExecuteReader();

I just ran this with the October CTP of Whidbey and SQL Server. The application runs without error. In .NET 1.1, however, we would see an exception:

Unhandled Exception: System.InvalidOperationException: There is already an open
DataReader associated with this Connection which must be closed first.

The Technet document introducing MARS gives explanations and use cases for where this behavior is useful, and it also mentions: “In conclusion, we can say that MARS is all about getting rid of "Connection Busy", a significant improvement to the programming model.”. It does sound attractive on the surface, but…

You can ask anyone in the ASP.NET or ADO.NET newsgroups (like Bill, for instance), and they can tell you the aforementioned exception shows up time and time again in questions. The exception is usually the first clue a new developer has that they are not closing database connections. Oh well, you say, they will just have to learn the hard way, what impact is in it for me?

For starters, make sure to read the sections on “Performance and Cost Considerations” and “MARS Deadlocks” as food for thought. Even more interesting is the MARS FAQ on Angel Saenz-Badillos blog. Suddenly, creating a SqlCommand isn’t going to be quick and relatively free (and the OleDb provider has all sorts of caveats to watch for). MARS is on by default, and there really is no way to disable the feature to recover the cost or avoid the worst case scenarios for the feature.

ADO.NET seems to be replanting new pitfalls over the old ones we left behind in ADO. Surely, there must be some driving reason for this complexity in ADO.NET.

Could it be something required to build ObjectSpaces?

SetReportParameters

Friday, October 22, 2004 by scott

Question came in today about the SetReportParameters web service method of Reporting Services.

The name SetReportParameters is a bit misleading, and the documentation isn’t extremely clear. The method does not pass parameters to a report for rendering. Instead, the method has the same effect as modifying the parameter properties in the report designer. You can programmatically set valid values and prompt strings, etc. SetReportParameters is more of a “design time” method.

When SSRS goes to render a report, the parameter values come from one of three sources.

First, there could be a default parameter value specified in the report definition. If a default value exists SSRS will use the value, but you can override the default by passing a new parameter value using one of the techniques in the second source of parameter values.

The second source of a parameter value depends on how you access the Report Server. With URL access, you can pass a parameter value in the query string (&ParamName=Europe). If you are using the web service, then the ReportingService.Render web method accepts an array of type ParameterValue. The documentation online includes an example of how to pass the parameter values.

Finally, if there is a parameter left that does not have a default value, and you did not specify a value in the query string or in the web service call, SSRS has no choice but to prompt the user to enter a value. If you have hidden the parameter input area or the toolbar, the Report Server will throw an exception, otherwise you’ll see the TextBox and DropDownList controls appear for the user to select values.

Hope this helps…

The Lies I Tell At Work

Thursday, October 21, 2004 by scott

I’m glad you are here, gentle reader. I hope you’ve arrived in an understanding mood, because I feel compelled to unburden myself at your expense. For the last four months, I’ve practiced the art of deception at work.

You see, every few weeks our CEO brings up the topic of BizTalk Server 2004. We talk vaguely about how BizTalk might help us deploy solutions for our clients. A discussion ensues about XML and healthcare schemas. Eventually, someone will ask me if I’d had a chance to investigate the technology more thoroughly.

“Well”, I say, “the Canadian project we picked up has required more of my attention then I originally thought. I have not had a chance to dig into BizTalk yet”.

Not exactly true.

Other times I say: “I’ve been working with the statistician on algorithms for severity adjustment of patient diagnoses, but I’ll try to squeeze BizTalk into the schedule real soon”.

A little fib.

My dear reader, I’m about to give you the truth of the matter. Here is the real reason I have not devoted my research time to this marvelous product known as BizTalk Server.

I CAN’T GET THE @##@*^% PIECE OF @^*% TO INSTALL AND I’VE TRIED FIFTEEN #&#*^% TIMES AND I’M AFRAID THE BOSS WILL THINK I’M SOME SORT OF #&#**^% DIMWIT.

There. It’s off my chest. It’s in the open.

Ok, technically, it “installs”, but I’m impotent when it comes to running the configuration wizard. I’ve tried on multiple machines. I’ve tried with fewer features. Not once have I made it through ConfigFramework.exe without a severe error. BizTalk hates me, but I have a plan.

One week from today, on October 27th, will bring a full moon. I know where I can buy some chickens, and I found a 1-900 hotline with virgins who say they will do anything. In the evening of October 27th - I will try once again to install BizTalk Server 2004.

I’m feeling better now, having admitted my hideous ruse to you, dear reader. I hope you don’t think any less of me than you already did.

October 27th.

Stay tuned for details.

Evaluating The DataBinder

Wednesday, October 20, 2004 by scott

I was trying to put together a quick piece of code as an example over the weekend and remembered how much I dislike using DataBinder in ASP.NET.

Let’s say a web service call gives back an array of simple objects (the sort of objects you’d see imported by a web reference):

class Parameter
{  
 public string Name;
 public string Value;
}

I wanted to dump the Parameter array to a web page as easily as possible. The following will not work.

<asp:Repeater id="Repeater1" runat="server">
   <ItemTemplate>
      <tr>
         <td>
            <%# DataBinder.Eval(Container.DataItem, "Name") %>
         </td>
         <td>
            <%# DataBinder.Eval(Container.DataItem, "Value") %>
         </td>
      </tr>
   </ItemTemplate>
</asp:Repeater>

The DataBinder, besides looking awkward, only finds public properties - it doesn’t find public fields. The quick hack to get around this is to replace the language agnostic DataBinder syntax with C# code:

<asp:Repeater id="Repeater1" runat="server">
    <ItemTemplate>
        <tr>
            <td>
                <%# ((Parameter)(Container.DataItem)).Name %>
            </td>
            <td>
                <%# ((Parameter)(Container.DataItem)).Value %>
            </td>
        </tr>
    </ItemTemplate>
</asp:Repeater>

Disadvantages:
There is a huge disadvantage in that if the Parameter class fields ever change, the code in the ASPX won’t generate an error until runtime. It’s also a problem if the ASPX moved from a C# project to a VB.NET project.

Advantages:
To me the second example looks cleaner – I can see an object and a property even through the parentheses of a cast. It’s also blazingly faster - two order of magnitude faster. In fact, in my tests the following:

<%# DataBindParameterName(Container.DataItem) %>
// in the code behind of the class:
protected string DataBindParameterName(object o)
{
    return ((Parameter)o).Name;
}

is still 300x faster than the reflection machinations DataBinder.Eval uses. Food for thought in perf critical scenarios.

Three Things I Learned In Boston

Wednesday, October 20, 2004 by scott
  1. Navigating Boston with the aid of a speech enabled GPS device is about as useful as navigating Boston with the aid of a chatty 3 year old. “TURN LEFT”, the device says. Ok. Would that be the street 30° to the left or the street 60° degrees to the left? This happened more than once. Note to self: write down street names on next trip.
  2. I need to install Windows SharePoint Services and find out what all the hoopla is about. After hearing about SPS in the hallways and seeing it in a presentation, I want to learn more.
  3. It is possible to live on pizza, sushi, and diet coke for three days.

Slides and Code From The Camping Trip

Tuesday, October 19, 2004 by scott
Codecamp2.zip contains the slides and code from my presentation on integrating SQL Server Reporting Services with ASP.NET.

The code includes one web project to demonstrate:

  • URL access to the report server
  • A simple demo of the ReportViewer component
  • Building a TreeView of report items with a web service call (ListChildren)
  • Examining report parameters – their valid values, type, dependencies, and state with multiple web service calls to GetReportParameters

The second project delivers a report to a second ASP.NET application (a .Text blog) via a web service call. For more information on this project, see my post: The Blog Delivery Extension.

Kudos to Thom Robbins, the other MS folks, and all of the speakers for a great weekend.

Code Camp II

Friday, October 15, 2004 by scott

If you are coming to Code Camp 2 this weekend, I hope to see you at my talk Saturday afternoon on integrating SQL Server Reporting Services and ASP.NET. This session is not about designing reports, it’s all about integration: URL access, web services, and delivery extensions. These topics are useful for SSRS integration with any type of application, actually, but the session does focus in on particular points of pain in an ASP.NET environment. I’ve been through the pain, and I can pass along tips to make it easier for others.

At some point next week I’ll get the code examples and slide deck onto OdeToCode.com.

I can’t wait to attend the other presentations and chalk talks, they look great. There are a boat load of bloggers coming:  DonXML, Scott Watermasysk, Kent Tegels, Chris Pels, Carl Franklin, Jason Bock, Robert Hurlbut, Chris Bowen, and Sam Gentile. Who did I miss? There is and even a book swap. Like any camping trip, I'll probably need two days to recover and return to normal life. Not that life is entirely normal all the time.