Category Archives: Code

VB Garbage collection

This article claims it’s pointless to Set objects to Nothing in VB when you’re finished with them, except in particular cases. Maybe it’s those particular cases I’ve come up against, but I don’t believe that, myself. I’ve observed time and time again IIS apps that call VB6 DLLs grabbing more and more memory for DLLHost, and eventually choking until an iisreset has been done.

Going through the code (both the ASP VB Script and the underlying DLL VB) with a fine tooth comb and ensuring EVERY object got set to Nothing afterwards cleared these issues. Though I’m embarassed to admit that on one early project I worked on, a bunch of people looked through the code trying to find the leak, couldn’t find it, and someone eventually wrote a nightly iisreset batch job.

Reading that article, it occurs to me that maybe there was a case of destroying objects that referred to each other in the wrong order. The code is long sinced vanished, so I don’t know, and don’t care to find out.

As far as I’m concerned, it’s not only better for performance to destroy your objects, and a helluva lot easier to do all the time than just some of the time. It’s also tidier in the code. I’ll keep on doing it.

.Net, of course, is a different kettle of fish altogether.

MSXML HTTP Post: Access Denied error

In MSXML 4 SP2 (and later, I assume in advance) if you try to send Post data using the ServerXMLHTTP40 object to a site that’s in the Internet Zone, you get an Access Denied error.

This is another of those things that had me banging my head in frustration until I eventually solved the problem. Contrary to what you may first think, it’s not a bug.

It’s actually upgraded security in this release: it uses the IE settings, and if you try to send unencrypted Post data by HTTP to Internet zone sites, you run into trouble. Details are at the end of the readme for the SP2 release and in KB 820882, but the workaround given does not work in Windows 2000 because the MMC Snapin referred to is only in Windows XP.

Apparently now there’s a Windows 2000 hotfix you can get, but as with all hotfixes, it involves mucking about ringing up Microsoft PSS to get it. (And when it says “Applies to Microsoft Windows 2000 Standard Edition”… what is that, exactly? Maybe they mean Professional?)

You can also get into IE and change the zone settings, but it has to be the same user that runs your process. If the process is some kind of robot, it’s not always possible to do this.

Eventually I dug around in some MSKB articles and eventually found article 182569 that talked about how to change the relevant settings via the registry.

To tell Windows to ignore user-specific settings, and always use the zone setting you are about to define, create or edit the following Registry key:

HKEY_LOCAL_MACHINE; Software; Policies; Microsoft; Windows; CurrentVersion; Internet Settings; Security_HKLM_only (DWord value) = 1

The alternative would be to change the following setting for each user that will try and do the HTTP post, eg in HKCU/HKU instead of HKLM.

Okay, so to tell it to allow unencrypted HTTP Post data into the Internet zone:

HKEY_LOCAL_MACHINE; Software; Microsoft; Windows; CurrentVersion; Internet Settings; Zones; 3; 1601 (DWord value) = 0

See MSKB 182569 for more details.

Snippets

Hax0r gameshow contestant wagers $1337 on Jeopardy. (via Rick)

Gary Schare, Director of Windows Product Management at Microsoft, talks about the future of IE, its features and security. (Via Cameron Reilly)

Speaking of ADO (which I was yesterday), trying to figure out the black magic that is an OLEDB connection string? Try here.

Feel like writing a little C++ or Java applet for your phone? Here’s tech specs for Nokia phones. For me that’s the kind of project I’d love to do, but it will have to happen after I invent a time machine so I’ve got the time to do it in.

Empty recordset from MDB queries via ADO

Every so often I’ll find the solution to an obscure issue, and wonder “why isn’t this in the MSKB? Why has nobody written an explanation I could find in Google?” Well through this site, now I can do something about that.

If you call an Access (Jet 4.0) query via ADO/MDAC, you may get empty recordsets back if the query uses parameters. There’s a bug that Microsoft reckons applies to RDO calls, but also appears to affect ADO/MDAC 2.7 in the same way.

To fix it you need to define the parameter size to an arbitrary amount before you set the parameter. Here’s some hopefully useful (to somebody, somewhere, some day) sample code…

(This is VB6. Dim everything beforehand of course, ‘cos everybody loves early-binding. What, you want to play with fire by using late-binding and no Option Explicit? Silly you.)

Set oCommand = New ADODB.Command
oCommand.ActiveConnection = gcDatabase.Connection
oCommand.CommandText = "select * from MyQuery"

Set oParam = New ADODB.Parameter
oParam.Size = 255 'Take this out and you get an empty recordset back, but no error. Wacky.
oParam.value = "your value"
oParam.Name = "your parameter name"
oParam.Type = adYourFieldType
oCommand.Parameters.Append oParam

Set oRS = New ADODB.Recordset
oRS.Open oCommand, adOpenForwardOnly, adLockReadOnly

(and close and destroy everything when you’re done, natch. You know what VB6’s garbage collection is like.)

Excel to HTML

I can’t believe how stupid Excel (2002/XP) was with the table of browsers the other day.

The plan was to get the numbers into Excel, copy/paste into a Frontpage table to strip back the formatting, then paste into WordPress.

Nup, bloody monstrous Excel tags right the way through it, which Frontpage couldn’t override, and evidently no easy way to strip. No combination of Paste Special would work. So for example, instead of <td></td> we got:

<td align="right" x:num="1.15E-2" style="color: windowtext; font-size: 10.0pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Arial; text-align: general; vertical-align: bottom; white-space: nowrap; border: medium none; padding-left: 1px; padding-right: 1px; padding-top: 1px"></td>

I kid you not. Now, I know about round-trip HTML, though I have my doubts that anybody uses it — firstly because it looks like crap in a web browser, and secondly because if you’ll want to edit it later, you’ll just keep an XLS copy. Besides, it’s badly implemented. The cell above was using the “Normal” style. It shouldn’t have had all the formatting crap embedded in it.

Word XP actually has a Save As Filtered HTML option to strip out all this crap. Excel XP doesn’t. (I haven’t checked Excel 2003 yet).

Plan 2 was to save it as HTML, load it into FrontPage and crop the HTML to paste into WordPress. Nup, trying to re-open it in FrontPage just threw it back to Excel. WTF?! Opening in UltraEdit (my preferred text editor) just revealed the same tags as above.

How can two Microsoft products that are part of the same suite, same version, operate so disastrously badly with one another, for something as simple as copying a table?

Plan 3? Oh bugger it, it’s only a few lines, just write it by hand.

If it were more I’d go install and run that clear The Useless Crap Out Of The HTML filter thing (oh look, they could do with clearing the crap out of their URLs too), but it refuses to install unless you have Office 2000. Wonderful.

Next time (after swearing a bit) I’ll probably save to CSV and then do a global replace from commas to table tags.

Surely there must be an easier way?

Another MySQL GUI

A while ago I downloaded a cross platform DB manager, DB Tools Manager Professional. It works great for local databases but was painfully slow accessing remote MySQL installs. Daniel came across MySQL Administrator, a smooth Windows GUI for MySQL from the very same people that release MySQL. It seems to be as fast with remote access as it is with local and so far I’m impressed.

Sitepoint Anomaly

I’ve been meaning to buy a couple of books from sitepoint for a while now. I’ve borrowed a copy of their HTML Utopia: Designing Without Tables Using CSS, a fantastic guide to CSS and their Build Your Own Database Driven Website Using PHP & MySQL looks great so when they emailed me an offer of 20% off this book I thought why not.

That is until I saw the site. Ifyou spend over USD$70 (effectively two books) you get free postage anywhere in the world. Hmmm. Take the offer and save $7 off one book or reject the offer (which takes me below $70), pay full price and save $15?

Regardless, they’re great books.

My MySQL

I’ve recently moved my web site development from Windows/ASP to Linux/PHP/MySQL. I’m a child of the GUI generation so I went looking for a cheap GUI for MySQL. I found better than cheap – I found free.

DBMananger allows you to manage MySQL, PostgreSQL, Interbase/Firebird, SQLite, Xbase, MSAccess, MSSQL Server, Sybase and Oracle. I’ve used it once to get the database for www.criticalconf.com up and running and so far it’s doing all I asked for. It uses your standard SQL manager layout so there’s little, if any, learning curve and as a newcomer to MySQL that’s a bonus for me.

I’m about to launch in to a much more ambitious project so I’ll be able to give a fuller review once that’s done.