Tuesday, May 27, 2008

LinqDataSource error on Update or Insert

Here is a reminder for myself about a problem that happens, and I always end up having to search to remember the solution. When performing an update or insert on a LinqDataSource, say from a GridView you get the error "Could not find a row that matches the given keys in the original values stored in ViewState. Ensure that the 'keys' dictionary contains unique key values that correspond to a row returned from the previous Select operation."... Sounds complicated.

Well it isn't. Check that you have set the DataKeyNames property on the GridView with the column name of the primary key(s) of the LinqDataSource table. But that doesn't make sense, you say.

It does if you have a look at the stack trace. For example,
System.Web.UI.WebControls.LinqDataSourceView.GetOriginalValues(IDictionary keys) +926 System.Web.UI.WebControls.LinqDataSourceView.BuildUpdateDataObjects(Object table, IDictionary keys, IDictionary values, IDictionary oldValues) +102 System.Web.UI.WebControls.LinqDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +87 System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +78

The LinqDataSource is just like the old SqlDataSource - it needs to know how to lookup the row in the database table to work out what you have changed. If you don't tell it the keys to lookup in the table, how will it ever know which row you were editing? Once the DataKeyNames are specified those columns are used to find the original row in the database, compare and merge your update changes and commit them back to the row. Simple. Now I just have to remember "Set the DataKeyNames property"...

kick it on DotNetKicks.com Shout it

Tuesday, May 20, 2008

Windows Workflow still immature

I have been spending the last couple of weeks looking at how to integrate Microsoft Windows Workflows into my ASP.Net website. It is a basic usage of workflow - implement a state machine, do some processing on state initialisation, maybe fire an email or reminder here and there. It all sounds great on the surface and it basically works. But there are a few things that will just mean that it isn't workable in my site.

You see I have long running workflows, let's say longer than a week. They might hang around waiting for user input, a client to phone back, fill in a web form or something of that nature. However I am taking an agile approach to this particular development - releasing little functionality increments for the client. The problem is that workflows are tied to assembly versions, and my assembly versions are changing all the time. Not to mention that the workflow structure is also changing all the time.

So what do I do? Something like Ruurd Boeke suggests could pass, but hell that is a lot of work, considering I'll be doing this every two weeks or so. I don't have a good solution, so for the moment it is shelved. I'll just implement a basic state flag on my object and then provide a generic mechanism for faking the state flow. If things are designed right then I should be able to reuse any code in workflow activities once it all gets running. I'll try to use workflows for some of the short tasks that are required, just to make sure I am still getting my feet wet with the technology.

This seems like a typical trend for Microsoft to release something that is really, really beta (nay, alpha?) to gauge public opinion and then develop it a production standard later on. Windows workflows seem to me like they are nowhere near ready for production systems.

Do you have an opinion??

kick it on DotNetKicks.com Shout it

Wednesday, April 23, 2008

ASP.Net Event Validation

OdeToCode.com has a great post from K. Scott Allen about the ASP.Net event validation. He describes the mechanism that the ASP.Net controls use to validate that the values being submitted from the controls are valid. The second part of the post gives a couple of workarounds. I hate the suggestion of disabling event validation across my whole site. What a cop out!

Of course it doesn't help with my current problem of the event validation on the AJAX controls, but it is a good bit of background for understanding the problem.

kick it on DotNetKicks.com Shout it

Saturday, March 08, 2008

Google and Outlook Calendar Sync

Google moves its users one step closer to total integration with the release of Google Calendar Sync. Synchronize to-from and back to Outlook and Google Calendar. Access it anywhere. Just make sure you are running the Calendar Sync program.

Google-Oulook-Google Calendar sync

kick it on DotNetKicks.com Shout it

Friday, March 07, 2008

WCF client says 'No Corresponding Start Element Open'

Once again I'll just make a comment about this error. When using Dataset across a WCF service the service call may fail with the error "No Corresponding Start Element Open". The error makes perfect sense once you know the answer, but to the uninitiated it might be perplexing.

The problem is that the return value of the service call is a Dataset. If you return null from the service call then the client will see this error. The answer, well it depends on what you want to achieve. But probably just return an empty dataset and then test the contents on the client (which should be done anyway for good coding practice).

Instant Development: Frustrating Error: No Corresponding Start Element Open

kick it on DotNetKicks.com Shout it

Thursday, March 06, 2008

Internet Explorer 8 introduces Web Activities

Microsoft has released a beta version of its popular web browser Internet Explorer. Internet Explorer 8 touts its offering of more CSS compatibility, better developer debugging integration, Web Activities, WebSlice. It will be interesting to see how these new IE extensions, such as Activities and Slices will be accepted by a community that is seeing increasing browser share for Mozilla Firefox.

A decade on from previous browser compatibility wars between Netscape and Internet Explorer, web developers might be a little more weary of developing web pages that are for exclusive, or optimised use in Internet Explorer. At least I hope so. Standards are standards for a reason and I personally don't want to develop for the four main browsers (IE6, IE7, IE8, Firefox) instead of three. Hopefully the much talked about standard compliance mode won't be watered down too much in subsequent releases.

Article: IE 8 Beta 1 Released
Download IE8: http://www.microsoft.com/windows/products/winfamily/ie/ie8/readiness/Install.htm

kick it on DotNetKicks.com Shout it