19 June, 2010

I bricked my Android Desire phone (lost USB connection)!

Damn – finally I “managed” to brick my new Android (HTC Desire) phone!
After many successful attempts with rooting and applying a new ROM to the phone, it finally backfired today.

Thank God for the XDA-developer forum and other relevant sites, that can help you when this happens.
The concrete symptoms was these in my case:

- Unable to connect your phone using USB when booted into Android.
- Unable to connect your phone using USB in Custom/Pushed Recovery

So what to do?
I found this procedure to work:
1) Power down the phone
2) Start again by holding down Power + Volume Down
3) Connect the USB-cable from PC to phone
4) Select FastBoot (USB) mode
5) Open a CMD-prompt on the PC
6) Enter this: 'fastboot oem enableqxdm 0' in the command prompt (this will enable the SD-card again)
7) Tranfer this file (update.zip) to the SD-card (via what ever is possible, I did it via email as an attachment!)
8) Turn off the phone
9) Restart again by holding down Power + Volume Down
10) When the screen with the big red exclamation mark appears, hold Volume-Up + press Power and select apply sdcard:update.zip.
11) Let it run and reboot
12) You are back to having SD-card access and USB connection to the PC

Links of interest:
http://android.modaco.com/content/htc-desire-desire-modaco-com/307365/14-jun-r6-riskfreeroot-htc-desire-rooting-guide-now-with-hboot-0-80-and-os-to-1-21-support/

http://forum.xda-developers.com/showthread.php?t=691187&highlight=lost+USB+connection

03 June, 2010

How to insert multiple rows in a SQL CE database

Doing some mobile application development (win CE) I was recently faced with a task, that immediately would seem trivial. Come on – how hard can it be to insert more than one row in a database? Well – when the database you are dealing with is a SQL Compact Edition (v. 3.5); you are in for a surprise (or at least I was ;-)).

The default access to the database is a table adapter, which is a very downscaled version compared to the Entity Framework you are used to and take for granted by now. The table adapter unfortunately only allows for single row inserts; which means you are to call this multiple times by default. That does not work well, if you are having more than say 10 rows you want inserted! I was attempting this model at first with approx. 47.000 rows and ended up with a duration of 2.5 hours! So – what do do?

Well – an alternative route exists that brought the duration dramatically down (2.5h –> 6 sec!) for the same number of rows.

By using the below code, you are utilizing a direct access to the SQL CE table and gain a significant performance boost compared to the default table adapter. Do note that when using this route, you do no longer have the luxury of fieldnames, but are limited to using their ordinal places in the table. Note that the ordinal value is the same value you will find in a create table statement for the table you are targeting (in the below example: ‘OnlineProducts’).

Note also in the below code, that the same SqlCeUpdatableRecord (variable: ‘rec’) is used over and over again in the foreach loop. This means no memory optimization is performed by the CLR, which is intentional; before the method is exited.

/// <summary>
///
Inserts/updates rows.
/// </summary>
/// <param name="newRows">
The new rows.</param>
public void InsertRows(ProductDataSet.OnlineProductRow[] newRows)
{
//insert using direct sql
var cnn = new SqlCeConnection(GetSDFConnection());
var cmd = cnn.CreateCommand();

try
{
cnn.Open();
cmd.CommandType = CommandType.TableDirect;
cmd.CommandText = "OnlineProducts"; //tablename!

var rs = cmd.ExecuteResultSet(ResultSetOptions.Updatable);
var rec = rs.CreateRecord();

//update records (use same row)
foreach (var row in newRows)
{
try
{
rec.SetString(0, row.ProductName);
rec.SetString(1, row.ProductUnit);
rec.SetFloat(2, row.StandardPrice);
rec.SetDateTime(3, row.Updated);
rec.SetString(4, row.ProductNr);
rec.SetString(5, row.ProductNameLong ?? "");
rec.SetValue(6, row.Image);
rec.SetString(7, row.AlternativeProduct ?? string.Empty);
rec.SetString(8, row.EAN);
//rec.SetInt32(9, row.OnlineProductID);
rec.SetDouble(10, row.SalesMultiplier);

rs.Insert(rec);
}
catch (Exception ex)
{
CELogger.LogException(ex);
}
}

rs.Close();
rs.Dispose();
}
finally
{
cmd.Dispose();
cnn.Close();
cnn.Dispose();
}
}
Update: You might want to initialize the fields of the record before doing the inserts. Otherwise you end up "inheriting" the old values from last iteration :-)

02 June, 2010

Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created.

SQL server is sometimes source of irritation! If you are not careful – you might run into this obstacle I just had today. Trying to edit a table definition directly in SQL Server Management Studio, I got the error message:

“Saving changes is not permitted. The changes that you have made require the following tables to be dropped and re-created. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.”

In itself – it is an okay error as we do not want to delete data (sometimes!). But where do you change this behavior when you actually do want to change a table definition and don’t care about the data inside the table. Well – uncheck this setting and you are good to go!

prevent

iPhone/XCode - not all cases are equal!

This bit me! Having made some changes to an iPhone application (Obj-C); everything worked fine in the simulator. But, when deploying the s...