Monthly Archives: May 2012

Starforce sucks. DRM must die

This is why piracy will always be here. This is why legitimate paid software will never take hold. Main reason being – greed of the publishers and inability to look beyond immediate profit.

I’ve purchased an adventure game “Moment of Silence” (“Момент Истины“, a Russian localisation by company called Akella). The game is perfectly compatible with all versions of Windows from Windows95 till Windows 7 64bit and beyond. BUT its copy protection system made by StarForce isn’t. Attempt to run game displays a cheery message in lines that “Copy-protection works only in Windows 95/NT/98/ME/XP“. Just how dumb is it?

I am running Windows 7. And no, running the game in compatibility mode doesn’t help. And I am not going to install “XP Mode”, which is basically a resource-hogging VM. So I had to go and find a pirated copy of that game with cracked “NO-DVD” executable included. I downloaded it – guess I am a pirate (or at least a user) now. But Akella can go screw itself, I do have a legid copy, it’s just not worth squad.

Regenerate JavaScript function code in ASP.NET partial postback after initial load

ASP.NET has a handy way of generating client side JavaScript code, but using it can be sometimes unpredictable. For example your client-side script needs to call function MyAlert, but the function itself is generated server-side on page load:

ClientScript.RegisterStartupScript(Me.GetType, "JSCode", _
                  "function MyAlert() {alert('This is the FIRST call')}", True)

Function is generated, and in due time, when needed is called by the client and the message “This is the FIRST call” is displayed. All is well.

Now, your page also has an UpdatePanel, and during a partial postback you need to modify that client-side function:

ScriptManager.RegisterStartupScript(Me, Me.GetType, "JSCode", _
                  "function MyAlert() {alert('This is the SECOND call')}", True)

In due time, when again needed by client code, function MyAlert is called and the message (wait for it, you’re in for a surprise) “This is the FIRST call” is displayed again. Originally generated function is called and second generation is ignored. Continue reading →

TSQL: Mix column names and ordinals in ORDER BY

It might be a weird scenario from a parallel universe, but in infinite dimensions it is bound to happen to someone else besides me. If you’re getting results from a query where you know some columns by name and others only by their ordinal position (e.g. if SQL is built dynamically and can change based on different condition) – you add sorting to that query by both ordinal position of a column and column name and even throw an expression into the mix. Allow me to illustrate:

Let’s get back to basics, namely Northwind database. If I ran a query like this:

SELECT * FROM Customers

I will get a result, similar to this:

Unsorted SELECT

Now to the weird part. Let’s say I need to sort this query by by Contact’s title and Contact’s last name. I don’t know what the column name for the Contact’s title will be, but I know if will always be a static 4th column. I don’t know where in the resultset Contact’s full name be located (it could be 3rd, or 8th or whatever column) but I do know it will always be called ContactName. Continue reading →

UltraWebGridExcelExporter: Export more than 65536 rows

When exporting data from Infragistics UltraWebGrid into Excel using UltraWebGridExcelExporter ordinary a very basic code similar to this is used:

'
' define Exporter "xMyExporter"
' define UltraWebGrid "xMyGrid" and load grid with data, then:
'
xMyExporter.ExportMode = UltraWebGrid.ExcelExport.ExportMode.Download
xMyExporter.Export(xMyGrid)

That’s it. But, if your data exceed 65536 rows you will get an error:

System.InvalidOperationException: The maximum number of rows in an excel worksheet with the current format is: 65536

This is not Excel Exporter limitation. Continue reading →

(Possible) solution for MSChart ArgumentException The image is not found error

If you’re using Microsoft’s .NET charting control on your ASP.NET pages you may receive an annoying error

[ArgumentException]: The image is not found. at
System.Web.UI.DataVisualization.Charting.ChartHttpHandler.ProcessSavedChartImage(HttpContext context) at
System.Web.UI.DataVisualization.Charting.ChartHttpHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

I could be intermittent, sometimes happen, sometimes not. In your web.config you already set your temp images to be stored as files and not deleted after serving:

<add key="ChartImageHandler" value="storage=file;timeout=20;url=~/temp/;deleteAfterServicing=false" />

as well as trying other remedies and nothing helps.

One possible solution is, while still using file temp storage, instead of indicating relative path via url property set it to absolute path via dir property:

<add key="ChartImageHandler" value="storage=file;timeout=20;dir=C:\TEMP;deleteAfterServicing=false" />

In the example above C:\TEMP is an absolute path to the temp folder on the Web Server. In your case it could be different; in multi-server (WebFarm) environment it should be a network share, accessible by all servers.

Select Distinct DataRows from ADO.NET DataTable using LINQ

If you’re trying to retrieve distinct rows from your ADO.NET data table using code like

From oRow As DataRow In dtTable.Rows Select oRow Distinct

or

(From oRow As DataRow In dtTable.Rows Select oRow).Distinct()

You may find that rows that are being return are not unique. That’s because by default LINQ compares table rows by reference. If you need to compare by actual values – use DataRowComparer in Distinct method call:

(From oRow As DataRow In dtTable.Rows Select oRow).Distinct(DataRowComparer.Default)

‘this.Column.Band’ is null or not an object error in UltraWebGrid filtering

When you filter Infragistics UltraWebGrid by clicking Filter icon in the column header – dropdown with filter values appears. Normally if you click elsewhere on the page – dropdown disappears. But sometimes it doesn’t, for example if you click an element that invokes a JavaScript function. Filter dropdown stays open and this could cause problems – when grid refreshes (and possibly other actions are performed) error is thrown:

‘this.Column.Band’ is null or not an object

The solution to this is to close filter dropdown ourselves. Put these lines into your client-side code whenever clicking outside the filter doesn’t close it:

var aGridCols = igtbl_getGridById('xMyGrid').Bands[0].Columns
   for (var I = 0; I < aGridCols.length; I++)
      aGridCols[I].showFilterDropDown(false);

Here we’re looping thru grids column collection (This example assumes grid is in Flat or OutlookGroupBy mode, if your grid is hierarchical, you will have to loop thru band collection as well). For every column we pass False to showFilterDropDown method which (probably showing Infragistics cute sense of humor) hides filter dropdown if it is open. If dropdown is hidden for the column already – nothing happens.

As a result opened filter dropdown is now always closed prior to previously offending action and the error doesn’t happen.

Speed up UltraWebGrid rendering on rebind

If you’re using Infragistics UltraWebGrid with it’s property Browser="Xml", you may find yourself living in a shotgun shack in a strange situation: When grid is rebinding – it takes (comparatively) short time to do server-side processing and then a very long time to render grid in the browser.

In my case it was most felt when grid (which had ViewType="OutlookGroupBy") was initially grouped with a lot of data in each group and then ungrouped back into flat view when user dragged last group column out. Using IE9 built-in developer tools I ran JavaScript profiler I found that culprit was Infragistics JS function “disposeNode” which was called numerous times and had worst both inclusive and exclusive execution time. Continue reading →