Read APPX data from Visual Basic with ODBC

On Windows, configure an APPX ODBC data source that matches the bitness of the Visual Basic application. Query the published APPX table through that data source. The SQL Server Compact example is for an older handheld application.

APPX/ODBC cookbooks in the Library

To read APPX data from Excel, Access or Crystal Reports, choose your APPX release and match the driver to the Windows application opening the connection.

Choose by release and client bitness

  1. Test the data source with the same account used by the application. Confirm the published table and column names.
  2. Open the ODBC connection and use ExecuteReader to read the rows. Keep the destination connection separate from the APPX connection.
  3. Bind the vendor number and name as command parameters when copying rows. A name such as O'Brien must be stored intact.

The Appx ODBC client allows you to access APPXIO data from external applications such as Excel, Crystal Reports, and other ODBC compliant applications. These applications will format the appropriate SQL command and the selected data will be returned. Products such as Visual Basic do not all have a clear user interface for the user to build the necessary command. The following code is provided by Ed Griffith as an example of using VB coding to execute a SQL command from VB to access APPXIO data. This is just a model and will have to be modified to fit your own needs. The example below copies new vendors from APPX to an existing SQL Server Compact file. In Windows ODBC Data Sources, test the APPX DSN with the same driver bitness as the Visual Basic program. Provide the configured DSN name, the APPX user name and its password to CopyVendors when the user runs the program. For example, use the DSN AppxODBC and an existing C:\Reports\Vendors.sdf file with a VENDOR table. For a read-only report, open just the ODBC connection and run the SELECT.

Imports System.Data.Odbc
Imports System.Data.SqlServerCe

Module VendorImport
    Public Sub CopyVendors(dsn As String, userName As String,
                           password As String, destinationFile As String)
        Dim settings As New OdbcConnectionStringBuilder()
        settings("DSN") = dsn
        settings("UID") = userName
        settings("PWD") = password
        Dim localSettings As New SqlCeConnectionStringBuilder()
        localSettings.DataSource = destinationFile
        Using source As New OdbcConnection(settings.ConnectionString),
              destination As New SqlCeConnection(localSettings.ConnectionString)
            source.Open()
            destination.Open()
            CopyNewVendors(source, destination)
        End Using
    End Sub

    Public Sub CopyNewVendors(source As OdbcConnection,
                              destination As SqlCeConnection)
        Dim query = "SELECT VENDOR_NO, NAME FROM C01_MAP_VENDOR"
        Using selectCommand As New OdbcCommand(query, source)
            Using rows As OdbcDataReader = selectCommand.ExecuteReader()
                While rows.Read()
                    Dim vendorId = rows("VENDOR_NO")
                    Dim vendorName = rows("NAME")
                    Dim findSql = "SELECT COUNT(*) FROM VENDOR WHERE VENDORID = @id"
                    Using find As New SqlCeCommand(findSql, destination)
                        find.Parameters.AddWithValue("@id", vendorId)
                        If Convert.ToInt32(find.ExecuteScalar()) = 0 Then
                            Dim addSql = "INSERT INTO VENDOR (VENDORID, VENDORNAME) " &
                                         "VALUES (@id, @name)"
                            Using add As New SqlCeCommand(addSql, destination)
                                add.Parameters.AddWithValue("@id", vendorId)
                                add.Parameters.AddWithValue("@name", vendorName)
                                add.ExecuteNonQuery()
                            End Using
                        End If
                    End Using
                End While
            End Using
        End Using
    End Sub
End Module

Use the published APPX table name for your database and application. Run one copy job at a time for this example and keep a unique key on the destination vendor ID.

Comments:

Read what other users have said about this page or add your own comments.


 

-- GaryRogers - 2010-12-30
Topic revision: r9 - 03 Dec 2026, AdminUser - This page was cached on 03 Dec 2026 - 19:41.

Powered by Foswiki. Wiki content belongs to its contributing authors.