The ArcPad Team Blog

Unofficial stuff from the team behind the World's leading mobile GIS platform

Thursday, November 18, 2010

Using ADODB in VBScript to open AXFs

There may come a time when you need to read and update AXFs outside of ArcPad and ArcGIS. For such scenarios consider using ADODB and Windows Script Host (WScript.exe and CScript.exe). This makes use of the fact that the AXFs are SQL Server Compact databases.

Save the following to a script called ListPoles.vbs.

Dim con
Set con = CreateObject("ADODB.Connection")
con.Provider = "Microsoft.SQLSERVER.MOBILE.OLEDB.3.0"
con.Open "C:\Users\Public\Documents\ArcPad\Samples\Riverside\Riverside_mdb.axf"

Dim rs
Set rs = con.Execute("SELECT COUNT(*) FROM POLES")
WScript.Echo rs.Fields(0).Value
This script determines the number of Pole records in the Riverside AXF. Running it should show 73 in a Windows dialog box.

In fact, there are several ways you can run this script. If you're using 32-bit versions of Windows (XP, Vista, Windows 7, ...) then the easiest way to run it is via double clicking on the ListPoles.vbs from File Explorer and the result would appear in a Windows dialog box.

If you're using 64-bit versions of Windows you have to use WOW64 redirection by opening a Command Prompt window and running C:\Windows\SysWOW64\WScript.exe ListPoles.vbs (i.e. instead of C:\Windows\System32\WScript.exe ListPoles.vbs).

If you want the WScript.Echo to show it's results to the Command Prompt window instead of a Windows dialog box then you should use CScript.exe instead of WScript.exe.

Using this ADODB technique to manage your AXFs means you can build a library of maintenance, reporting or data conversion scripts which all can run without the need of loading either ArcPad or ArcGIS. This may be a valuable option when building custom solutions.