Wednesday, November 11, 2009

Firebird -902 error localhost refused connection

Seems too obvious but you will get this error if you try to Connect after you Stop or Pause your Firebird Server service. More common causes are amply documented on the web - Firewall blocking and Incorrect port # (default is 3050)

Thursday, September 17, 2009

Launching CHM help file from a Java application on Windows

Seems like an obvious need but could not find an example for how to launch a compiled HTML help file from inside a Java JAR application on a Windows machine, so here's one:

String myHelpfile = path + "help.chm";
String[] command = { "hh.exe", myHelpfile };
try {
Process proc = Runtime.getRuntime().exec(command);
} catch (IOException e) {
e.printStackTrace();
}

Friday, August 28, 2009

Removing requirement for NET Framework 3.5 from setup projects

A new setup and deployment project in Visual Basic 2008 will by default require .NET Framework 3.5 on the target machine

If your application targets .NET Framework 2.0 this is a waste of time

To change the requirement right-click on your setup project, select View, Launch Conditions, go to properties of the ".NET Framework" item under the Launch Conditions node and change the Version property to 2.0.50727

Friday, August 14, 2009

How to find the control that generated a postback

Had a little trouble finding a good example of how to identify the control that generated a postback within the page_load

There's a nice article for C#, after a bit of tinkering here's a VB implementation:

Public Function GetPostBackControl(ByVal curPage As Page) As Control

 Dim foundControl As Control
 Dim controlName As String = curPage.Request.Params.Get("__EVENTTARGET")

 If (Not controlName Is Nothing And controlName <> "") Then
  foundControl = curPage.FindControl(controlName)
 Else
  ' control causing postback must be a Button or imageButton
  For Each controlName In curPage.Request.Form.AllKeys

   ' image buttons have a ".x" or ".y" appended to name string
   If (controlName.EndsWith(".x") Or controlName.EndsWith(".y")) then
    controlName = controlName.Substring(0, controlName.Length - 2)
   End If

   Dim c As Control = curPage.FindControl(controlName)

   If (TypeOf c Is Button Or TypeOf c Is ImageButton) Then
    'first button we find is the one that caused the postback
    foundControl = c
    Exit For
   End If
  Next
 End If

 GetPostBackControl = foundControl

End Function

Friday, July 10, 2009

IIS hyperlinks fail - cannot open an anonymous level security token

Recently upgraded a test machine to Internet Explorer 8. While testing a new deployment today found that hyperlinks created in my web application stopped working. The error icon on the bottom left of the screen said: "Cannot open an anonymous level security token"

The solution from a microsoft community site was to reset DCOM default properties to "Connect/Identify".

After rebooting and reopening the site in IE8 the links now work.

We tinker with DCOM on this test machine quite often and I found it with default properties of "None/Impersonate" - maybe impersonate causes a problem for anon access but I don't remember these problems with IE7. Hopefully this is not a sign the IE8 is going to "UAC" all over the system like Vista did.

Getting version number from a visual basic 2008 web application

Dim versionInfo As String = System.Reflection.Assembly.GetExecutingAssembly().GetName() .Version.ToString()

Obvious in hindsight, but took me a little while to find it

Tuesday, July 7, 2009

Changing the background color of a checkbox at runtime

I wanted to show 3 values in a checkbox ("full", "partial", and "empty") by changing background color of the selected checkbox when state is "partial"

I thought we could simply set the background color property, but that had no effect for me at runtime. It took a while to find how to programatically change background color of a checkbox on a VB web form, finally this post and this post got me close enough.

How to change the color at runtime:

(1) Add CSS style declarations to your form's design view (.aspx page), for example:

.full {
background-color: #fff;
}
.partial {
background-color: #ccc;


(2) in the form load method add some code like this:

curControl = CType(Page.FindControl(sID), CheckBox)

if (ispartial) then
curControl.Checked = True
curControl.CssClass = "partial"
else if (isfull) then
curControl.Checked = True
curControl.CssClass = "full"
etc.