29 July, 2010

Get to know your Android real close!

Just found the “key” to open the inner details of my Android phone. It is quite a detailed overview you gain when following the below recipe:

1) Enter the phone-application
2) Enter this number: *#*#4636#*#*
3) Voila – you are in debugger mode

Be prepared for a lot of info!

21 July, 2010

SQL Database Wizard: where is it…?

I was today faced with the task of moving a development database (SQL2008) to a remote server located at a Client. Now – the remote database server is setup as a “database cluster”, hence I could not just detach/re-attach a single database file. I needed some sort of scripting option that could generate the needed sql-scripts for this job.

I remembered that there was a “wizard” of some kind what one could download as well as a dedicated Visual Studio version (database version) but it just seemed to much trouble to install a complete VS-version just for that purpose! So Googling Binging the matter, made me find a download of some tool from MS that could handle this job (see below). It just turned out, that this separate download is only valid for SQL 2005 databases. The 2008 version is part of VS 2008 Service Pack 1!

When you install this service pack, you gain this context menu inside Visual Studio’s server explorer (which will launch the wizard):
image  image

Download links:
SQL 2005 publishing wizard
SQL 2008 Service Pack 1 (includes the 2008 version of SQL Publishing Wizard)

20 July, 2010

HandScent SMS: I receive 2 notifications when I receive a message?

I’ve been using HandScent SMS 3.0.4 for Android for a while now and am really liking this application. I just makes your Android resemble iPhone’s great SMS application. iPhone is ahead there still and Android has to learn. But, that’s where HandScent SMS comes to the rescue. In addition to the iPhone resemblance – it gives you the ability to specify a default signature as well as quick texts (pretty nefty when you are not all that “handy” on a smart-phone keyboard!).

One thing that has annoyed me though, is that you receive 2 notifications when an SMS message is received. One from HandScent and one from the native SMS-application in Android ? So what to do?

It is quite easy to remove this notification though.

1) Go into the native SMS application (called “Messaging”)
2)  Enter Settings
3) Scroll down and disable “Notifications”

You are done! And only 1 notification is shown in the notification area on the phone now.

19 July, 2010

LINQPad: How to add/update using LINQPad

I’ve been using LINQPad for an (extended) while now, and am really liking it.
It is a really useful tool for making quick lookups and ad-hoc queries. But, it seems to be missing out when it comes to inserting/updating a database?

I set out today to find out how to use LINQPAD for this, and it turns out to be quite easy; but not that intuitive after all.

You seem to be missing the <datacontext>.SubmitChanges() method when in the UI of LINQPad? But, it turns out that the missing <datacontext> actually is implied by the active dataconnection. Hence, you just call SubmitChanges() as a simple method call. That is all!

See code below (SubmitChanges() in the last section)…

    void Main()
byte[] bytes = null;
//load file
var fileInfo = new FileInfo(@"D:\files\DBFileStream.exe");
using (var fs = fileInfo.OpenRead())
//load into memory stream
bytes = new byte[fs.Length];
int read = fs.Read(bytes, 0, bytes.Length);

Debug.WriteLine(string.Format("Bytes read: '{0}'", read));


//insert file info database
var p = Plugins.Where(x => x.PluginIdentity == "DBStream.exe").FirstOrDefault();
Debug.WriteLine(string.Format("Plugin: '{0}'", p.PluginIdentity));

//file exists?
var f = Files.Where(fi => fi.PluginId == p.PluginId).FirstOrDefault();
Debug.WriteLine(string.Format("File found in Files table: '{0}'", f != null));

if (f != null)
f.FileData = new Binary(bytes);
f.Updated = DateTime.Now;
f.FileName = fileInfo.Name;
f.Version = "";
f = new Files();
f.Updated = f.Created = DateTime.Now;
f.FileName = fileInfo.Name;
//f.FileLength = fileInfo.Length; (Calculated field!)
f.PluginId = p.PluginId;
f.Version = "";

//TODO: Insert into files table

//Just submit here - you ARE the context yourself by means of the active DB-connection!

15 July, 2010

Auto Update Agent on Windows CE (interprocess comm.)

I today needed to create an autoupdate solution for an application on a device (Win CE, Windows Mobile 6.5 Professionel). The application is to support auto update, to allow the device to always be running the latest bits. Now, this can seem a pretty trivial task, but again – you are quite limited when it comes to support on the CE-device.

The issue is not so much how to download the new files from a remote server. The issue is more how do I shutdown an application in a nice way to be allowed to update parts of this application and next restart the application (in the illustration: how does ProcessB kill ProcessA?). Of course you could enumerate the processlist and invoke KILL on a process, but that would be like “pulling away the carpet” under the feet of the application. Not the best solution. I want to be allowed to inform the application that it should shutdown in it’s own pace.

The options I could come up with were these:
1) WCF
2) Interprocess Communication (named pipe)
3) Interprocess (tcp-sockets)
4) ClickOnce


1) WCF
Well – this was quite a short adventure. It is not supported on CE-devices to host a WCF-service that one could call to shut down the Process (A). So, so much for that.

2) Interprocess Comm. (named pipe)
Again a pretty short adventure. Named pipes are not supported in any CE-framework.

3) Interprocess Comm. (tcp-sockets)
Now we are getting somewhere. This is supported by CE and is a viable route for this purpose.

4) ClickOnce
Again – this would have been the best solution of them all. But, ClickOnce is not supported on a CE-device.

So we are left with option (3): Socket communication. As a POC, I made a system with 2 applications (Client to shutdown a Server). The 2 applications are seen here.

ClientCE       serverce

Server (to be shutdown, called “Process A” in above illustration):
This application does nothing (in this POC), but listening for an incoming message from the Client. Once this message is received and it contains the word “KILL”; it will gracefully shutdown after having freed resources.

Note: In a real life scenario – you would most likely want the listening part to run on a background thread. In the POC, this is run on the UI-thread hence it is pretty non-responsive when it comes to the UI of the application (as this thread is now blocked by the TcpListener!)


private void btnStart_Click(object sender, EventArgs e)

var ip = IPAddress.Loopback;
var listener = new TcpListener(ip, 9090);

lblStatus.Text = listener.LocalEndpoint.ToString();
var client = listener.AcceptTcpClient(); //block and wait...

//if here - received data
byte[] buffer = new byte[1024]; //should be enough for now.
var ns = client.GetStream();
int index = 0;
while (true)
int readData = ns.Read(buffer, index, 1); //read one at the time (CHANGE)
index += readData;

if (readData == 0)

//write out buffer
string rcv = Encoding.ASCII.GetString(buffer, 0, buffer.Length);
tbxData.Text = rcv;

bool doKill = (rcv == "KILL");

lblStatus.Text = "Stopped";
buffer = null;

if (doKill)
CleanUpResources(); //clean up stuff before shutting down

Client (to shutdown server, called “ProcessB” in the above illustration):
This application can ask the Server to shut down. It basically just establishes a socket connection to the Server, and tells this to shutdown. The “Command” sent is only a simple string at this time; but it could be an object that was serialized by the Client and then de-serialized on the Server side. This could carry more meaningful information.


private void btnKill_Click(object sender, EventArgs e)
var ip = IPAddress.Loopback;
var ipEp = new IPEndPoint(ip,9090);
var cl = new TcpClient();

byte[] data = Encoding.ASCII.GetBytes("KILL");

cl.GetStream().Write(data, 0, data.Length);


13 July, 2010

Cut/Paste in Windows Mobile Phone?

Having used an iPhone and currently an Android device, I’m really liking the fact that I can copy/paste a text from an application to use that in an email or something else on the device afterwards. But having downloaded the latest bits (beta) from the Windows Mobile 7 website today; I’m really starting to fear that they (Microsoft) are serious about not allowing copy/paste between applications on the device (globally)? After a quick browse of the assemblies and their namespaces/methods; nothing suggests otherwise! I was kind of hoping it was something they just forgot? In such case – they still forgot to put that in.

Come on Microsoft!
In all your wisdom; are we supposed to use an “old trick”/workaround like storing strings in a text-file on disk and then retrieve that in the new application? I’m really worried about the future of this platform. Or we should roll our own global cache (hmm….)

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...