Moving an Access Application to the Web with Alpha Five
- General strategies
- What's different about Alpha?
- Grid Linker
- Navigation System
- Tabbed GridLinker
- Step 0: Check your database schema in Access
- Step 1: Migrate your Access database to your SQL database
- Import and Export using Alpha Five
- Access-to-SQL Server specific migration
- The Access SQL Server upsizing wizard
- Step 2: Create an Alpha Five project
- Step 3: Create a connection to your SQL database
- Step 4: Define a grid
- Step 5: Define a Web page
- Step 6: Add your grid to your Web page
- Step 7: Continue defining components and pages
- Step 8: Add code where needed
- For more information
In this white paper, you will learn how to move a Microsoft Access desktop application to the Web with Alpha Five. You'll see how easy it can be, and when you're done you'll understand the process well enough to undertake it yourself.
There's good news and bad news about this. First, the bad news: this is not a completely automatic process, and you will have to give it some thought. While in many cases you should be able to convert your database schema and migrate your data automatically, you will have to manually re-implement your forms, reports, and business logic. The good news is that it isn't very hard to do any of this in Alpha Five, and the better news is that it should only take a small fraction of the time that it took to implement the application originally. The best news of all is that your converted application will shine on the Web.
Think about the assets in an Access application: besides the database schema and the data, you have forms, charts, queries, reports, macros, and VBA programs. Alpha Five can provide rough equivalents to all of these assets except for charts; several third-party developers, including Imagio and InfoSoft, provide chart controls that are compatible with Alpha Five. Let's start with the big picture.
There are several considerations to bear in mind when you are moving an Access desktop database to the Web. First of all, a Web application can potentially have a very large number of total users, and a moderately large number of simultaneous users. This means that record locking and overall scalability are very important for Web applications. Second, a Web application incurs a delay every time there is a round trip between the browser and the Web server. This means that performance can be improved by minimizing the amount of page refresh using Ajax techniques, and that user frustration can be mitigated by displaying progress indicators for operations that can take more than a second. Third, a Web application incurs a delay when executing database queries and downloading the result sets. This means that techniques such as lazy loading, data pre-fetch, data paging and data caching can make a big difference in the performance of the application. This also reinforces the need to display progress indicators. You may have heard of people using Access databases directly from Web applications. We don't recommend this, because Access databases don't support high numbers of simultaneous users or tables with large numbers of rows very gracefully, but it can be done from Alpha Five Web applications. We don't recommend using Alpha's native DBF format database for Web applications, either, primarily for scalability reasons. Instead, we recommend using a SQL database.
Alpha Five supports most SQL databases through ODBC drivers, including Cache, DB2, Microsoft SQL Server, MySQL, Oracle, PostgreSQL, Sybase SQL Anywhere, and Sybase SQL Server. Microsoft SQL Server is the database most frequently offered by hosting providers on Windows-based Web server accounts, so that's what we'll use for our example. Other SQL databases can work just as well. If you are on a budget, hosting your own database, and don't need database support, consider Microsoft SQL Server Express Edition, MySQL, and PostgreSQL, all of which are free. Our general plan is to migrate the schema and data first. Then, we'll build new Web forms with Alpha, using the seven Alpha Web components and HTML, based loosely on your existing Access forms. Since Alpha has Builders to help you to configure components quickly, it won't take nearly as long to recreate your forms in Alpha as it did to create them originally in Access. You can use Alpha Anywhere's own HTML Designer to add saved components to a Web page easily.
There are many technologies used to program Web server pages. You may be familiar with PHP, ASP, ASP.NET, or JSP. Alpha Five A5W pages are similar to these: they allow you to intermix HTML and Xbasic code on the server to process queries and forms, operate on a database, and display formatted data. Alpha Five provides 7 high-level components that you can configure and use on an A5W page along with HTML controls and Ajax widgets. There are seven types of embeddable Web components in Alpha Five. They are:
The Dialog component is a form that allows you to read and write variable data and execute Xbasic scripts. It is not intended for supporting read and write transactions with tables.
The Grid component displays multiple fields from multiple records in a table format. The data can come from one or multiple tables (as long as the tables are linked one-to-one). The Grid component can be either read only or editable. When the Grid component is read only, there is an option to have an additional Detail View form that allows you to edit the fields of any selected record.
The GridLinker component contains and displays multiple Grid Components, allowing you to display data from tables linked one-to-many (or parent-child) relationships.
The login component provides user ID and password security for web applications.
The Maintenance component will pack and re-index Alpha Five tables and sets. (This is only useful when you use Alpha Five tables, and is irrelevant if all your tables are in a SQL database.)
The Navigation System component allows you to create horizontal toolbars with drop-down menus, or vertical menus with fly-out menus. The menus can control navigation to the various pages of your web site.
The Tabbed GridLinker component organizes its grids in a tabbed structure that displays only one grid per level, but allows you to switch to any other grid in any level with a click of the mouse.
Before you go to the work of moving the database from Access, you should review the schema. In Access 2007, you can see a database diagram by selecting Relationships from the Database Tools ribbon:
You can view the details for any table on the diagram by right-clicking on the table and selecting Table Design:
What you're trying to determine at this point is whether the database schema will make sense for the Web application. There may be tables that you don't want to import at all: it would be helpful to know that before you go to the effort of importing them. There may be missing relationships, or badly normalized tables, or missing primary keys. One Access tool you can use at this point is the Analyze Table wizard on the Database Tools ribbon, which will detect some common problems.
If there are problems, you have two basic choices about fixing the schema: get it right in Access now, or get it right in the SQL database later, with the help of Alpha Five and any other tools you have for the SQL database. You can also combine the two. If you attempt to fix the schema in Access, make sure that you preserve a copy of your original Access database somewhere safe. We don't recommend fixing everything in Access, but you should probably fix any serious normalization problems if you can, and make sure that the data you migrate has relational integrity.
It's very important for SQL databases to be properly normalized; to have unique primary keys for all tables; to have foreign key constraints for all relationships; and to have indexes on all fields used as foreign keys. If none of this makes sense, you may want to refer to the Johansen book listed in the For more information section of this paper for advice on database design.
If you're still unsure about the schema, consider bringing Alpha Consulting Services in for a brief database design review. You can produce a great database application in Alpha Five even if you're not a great database designer, as long as you get help on the design. Database design is typically the hardest part of the application development lifecycle, and also the most critical to a successful application: don't feel that you have to do that part yourself. If you determine in Step 0 that you need to start over with a better database design, then Step 1 outlined here will not apply. Instead, you'll want to design the new schema, and then import data selectively from the Access database tables to your new SQL database design. Once this is complete, you can proceed with Step 2.
Before you can start working with Alpha to build a Web application, you need to import your database schema and your data to the database engine you're planning to use from the Web. We're targeting Microsoft SQL Server 2008 for this example. We'll start by discussing the generic process, which will also work for other SQL databases.
For purposes of this example, we're using the venerable Access 2003 version of the Northwind sample database, which ships with Alpha Five. Start Alpha Five, and from the Select Database dialog's Database & Tasks tab pick Create a database from imported data. In the drop-down box for Access, navigate to the northwind.mdb file installed by default in My Documents\Alpha Five V9\MDBFiles\.
Click the OK button, and then select a location and name for your new Alpha database. These choices are relatively unimportant; we'll throw away the Alpha database once we've exported it to SQL Server.
Select all the tables to import, and none of the other assets:
When the import operation is complete, you'll see a status screen:
This database import had no errors. If you encounter an error, you can go back to the Access database and fix the problem, delete the partially imported Alpha database, and try the import again. If you don't understand the error message, you might want to ask about it on the Alpha Forums. When you're done, you'll see your imported tables on the Tables/Sets tab of the Alpha Five control panel:
You can view the imported data in the tables using Alpha Five's default browse:
Now, we can export the tables and data to SQL Server:
At this point, we're defining the SQL database connection and the tables to export. We'll be connecting to the SQL database via AlphaDAO:
If your SQL database isn't already running, start it now. You'll have to drill down a few levels to get to the Create SQL Connection String dialog, where you can select the correct type of database, select the actual server, select or create the database, and test the connection:
It's useful at this point to save the connection string from the Connection String dialog. We used the name nwtest. With that done, you can open the Alpha database and the target database simultaneously in the AlphaDAO Export Genie, and select all the tables for export:
When you close the Genie, you'll have the opportunity to save the export operation configuration: we called it nwtest:
Now we can run the export operation, and see the results:
Using the Alpha Five SQL Explorer, we can now view the tables in the SQL database through the nwtest connection:
From the context menu that pops up on a right mouse click, we can choose to show the data in the SQL table:
That data, thankfully, looks just like it did in the original Access database and the intermediate Alpha database:
This is a success as far as it has gone:
What's wrong with this SQL Server Management Studio database diagram? The tables are present in SQL Server, and the rows, but there are no primary keys, no foreign keys, no relations, and no indexes. If you know what you're doing, it's a matter of a few minutes to add all of these from the diagram view; if not, it might be time to ask for help from someone with SQL Server experience.
The main advantage of the data migration method that we just demonstrated is that it will work with any SQL database supported by Alpha Five, not just Microsoft SQL Server. However, there are two methods available from Microsoft that may capture more of the database assets for the specific case of an Access database moving to SQL Server: the Access SQL Server upsizing wizard and SSMA for Access.
We'll walk through the Access SQL Server upsizing wizard very briefly. In Access 2007, open the Northwind 2007 sample, and go to the Database Tools ribbon. In the Move Data group, click on SQL Server. The upsizing wizard will open: accept the default option, Create new database, and click on Next. The next screen is where it may start to get hairy. The SQL Server instance you use must have SQL Server authentication mode enabled, and you must have a login that has CREATE DATABASE privilege. If you try to use an instance of SQL Server 2008, once you log in successfully you may get the baffling error message:
This appears to be a bug in Access 2007, as of 12/2008. It may be fixed in SP2. If you use an instance of SQL Server numbered between 6.5 and 2005 and have the correct privileges, it works fairly well, and you wind up with a database that has all the tables, data, relations, primary keys, and indexes:
You don't want to change the Access application:
As you can see in this diagram, the SQL Server database can be ready to go immediately after the Upsizing Wizard completes:
SQL Server Migration Assistant for Access (SSMA for Access) The SQL Server team at Microsoft also produces an upsizing wizard of its own, called SQL Server Migration Assistant for Access (SSMA for Access). There are multiple versions of SSMA listed at http://www.microsoft.com/sqlserver/2005/en/us/migration-access.aspx. Since this page includes copious instructions, readmes, FAQs, white papers, and case studies, we won't belabor the process here. It's certainly worth trying, assuming that your Access database is in good shape.
If you find that you need to make significant changes to your database schema, you might want to consider using SQL Server Integration Services (SSIS). This powerful ETL tool replaced Microsoft Data Transformation Services (DTS) starting with SQL Server 2005. This tool is launched when you select import/export data from the database menu in SQL Server Enterprise Manager. You can connect to a variety of data sources, including Access:
You have the option of creating your tables prior to input, or letting SSIS create new tables based on the existing Access table definitions:
Additionally, there are several transformation and mapping options:
This is just a brief example of how you can migrate your data using this method. SSIS provides well-written wizards to walk you through the process, and there are numerous sources for help online.
Once you have your database set, you're ready to create your Alpha Five Web application. Open Alpha Five, and create a new, empty database. We created 'web demo.adb' in 'My Documents\Alpha Five V9\web demo', but the location is not important.
Select the Tools|External Databases|Database explorer menu item, and click on the '+' at the top of the window. Specify a connection string for your SQL database, using the Build button.
Save the connection string under a name. We'll call it 'nw':
You should now see the SQL database in the Explorer under its name:
Open the Web Projects control panel and create a new Web component:
Make it a Grid:
The Grid Builder will appear when you press OK. Pick AlphaDAO and the named connection nw. You can do a lot by configuring the Grid with the Grid Builder. Play with it yourself and try different options. We came up with this Grid based on the Northwind Customers table in the SQL Server database, and saved it as custgrid1:
In the Web Projects control panel, create a new A5W page. The HTML designer will open. Switch to the WYSIWYG tab, and save the current page as page1.a5w.
Select Insert Component from the top tool bar. Pick the custgrid1 Grid component we just saved:
The page will look a little strange in the WYSIWYG view:
Add a title to the page by typing above the Grid Component, style it as you wish, save the page, and preview the page in your browser by clicking on the lightning bolt icon on the top tool bar:
This page is completely live. Go ahead and sort rows, search for items (try Bl*, for example), and jump to different pages.
In our example, we haven't made any of the fields on the Grid editable, we haven't turned on the detail view, and we haven't set any validation properties. You can go back to the Grid Builder at any time and change your settings using the Edit button at the top of the Web Projects control panel. You can publish your site at any time using the Publish button at the top of the Web Projects control panel. You can add defined components to multiple pages. You can use your existing Access forms as guides to what you might want to do in your Alpha Five Web application. You may also want to redesign the application to work better on the Web, or to take better advantage of the capabilities of Alpha Five. As you've seen, Alpha Five development goes quickly, so feel free to experiment with the application until it does what you want. Think about using the Alpha Five Navigation component where you would have had menus. Think about using a Grid Linker for parent-child tables, such as customers and orders. Think about using a Tabbed Grid Linker for more deeply nested relationships. Think about using the Alpha Login Component to provide role-based security for your application.
As an Access developer, you're probably looking for the code. It's there, but in most cases you don't need to write it yourself. If you edit your grid component and look at the Xbasic tab, you'll see hundreds of lines of code that have been generated for you based on your graphical selections. Near the top, for example, you'll see your SQL query: tmpl.CS.SQL = "SELECT CustomerID,CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers" Alpha Xbasic is similar to but not identical to Access Visual Basic for Applications (VBA). Alpha Action Scripting is similar to Access Macros. Alpha Genies allow you to build code quickly, as you've already seen. You'll eventually find yourself writing a little Xbasic code, but you won't need much, and using Genies and Action Scripting will get you started gently.