Database Snapshots: Make Data Integration a Snap

Data can be integrated into mobile, web, or desktop applications using Alpha Anywhere. Built on a model that uses a low-code approach, connecting to a database and importing data into an app for viewing or editing is easily accomplished. Reporting, charts and graphs, mapping, and other visual aids can also be created using data from back-end databases in Alpha Anywhere applications.

In addition to data integration, Alpha Anywhere includes features for creating snapshots of databases. With snapshots, you can easily do the following:

  • Assemble a sample database for use in demos or examples.
  • Create a test database that can be rolled back to its original state.
  • Build an initial database that is shipped with the app.

Creating and Storing Snapshots

Creating snapshots in Alpha Anywhere can be accomplished using xbasic. The SQL::DatabaseSnapshot is used to create an in-memory database. Using Alpha Anywhere’s AlphaDAO connection strings, data can be loaded from and stored in any database system for which an AlphaDAO connection string can be built. This means data loaded from a data source such as MS Access can be stored in other database system – SQL Server, MySQL, Postgress, etc.

For example, the following script creates a snapshot of a database accessed using the “::Name::SourceDatabase” connection string and stores the snapshot a target database defined by the “::Name::TargetDatabase” connection string.

dim cn as SQL::Connection
dim sn as SQL::DatabaseSnapshot

' Open the source database
cn.open("::Name::SourceDatabase")

' Load the snapshot of the source database
sn.load(cn)

Dim cn2 as SQL::Connection

' Open the target database
cn2.open("::Name::TargetDatabase")

' Save the snapshot in the target database
sn.store(cn2)

cn.close()
cn2.close()

This is a simple example. It is important to note that snapshots are stored as in-memory databases. If your database is larger than Alpha Anywhere can store in memory, you will not be able to load the entire database. For the standard use case of creating initial, sample, and test databases, this limitation should not be an issue for most developers.

Creating Samples: Snapshotting a Table

Sharing components is a common practice among Alpha Anywhere developers. Often, when asking for help on the Alpha Forum, users will ask to see a component that demonstrates the issue. If the component relies on data in SQL database, a sample of the tables used by the component needs to be provided with the component, otherwise the component can’t be tested.

Using snapshots, a sample table can be created that can be included with a shared component. We have put together a How To article that discusses how this could be done using snapshots and SQLLocalDB – a trimmed down version of SQL Server that now ships with Alpha Anywhere.

To learn more, visit the how to article here: How to Create a Database Snapshot and Store it in a SQLLocalDB Database

Additional Resources

For more information about Database Snapshots, visit our documentation. We have several guides in addition to the How To article linked above. We also have full API documentation for the SQL::DatabaseSnapshot, SQL::TableSnapshot, and related xbasic classes and functions used for creating and loading snapshots with Alpha Anywhere.