[English version available further below] Voici une démonstration de connexion de Flash avec une base de données Access ou SQL-Server. Cette démonstration montre la lecture et l'écriture dans une base de données (Access ou SQL-Server) à partir de Flash en utilisant la technique des updataPacket. Un 'updatePacket' permet d'écrire dans la base de données les modifications (et seulement les modifications) qui ont été effectuées par l'utilisateur sur le modèle de données. (changement de valeur, effacement d'un enregistrement, création d'un enregistrement). Cet exemple permet aussi la sauvegarde et la restauration des données sur le poste client avec les SharedObject. Pre-requis =========== - serveur IIS - Access ou SQL-Server - Recommandé : Installer MSXML 4.0 SP2 Release Notes voir http://msdn.microsoft.com/xml Installer la version française Liste des fichiers ================== connexion.inc : paramétrage de la connexion à la BD getdata.asp : lecture de la BD et génération du fichier XML pour les données savedata.asp : écriture dans la BD à partir d'un fichier XML updatePacket et génération du fichier XML de résultat contact.mdb : la base de données ACCESS MainForm.as : les actions en ActionScript Installation avec Access ======================== Recommandé ---------- - Dézipper le tout dans un répertoire - Créer un répertoire virtuel avec IIS de nom 'contactasp' pointant vers le répertoire contactasp de la livraison - Vérifier le fichier connection.inc (si vous avez modifié le nom du DSN) - Lancer l'application Attention, si vous installez le tout dans C:\Inetpub\wwwroot vous risquez d'avoir des problèmes d'écriture dans la base de données. Le plus propre est d'installer la base de données dans un répertoire, de créer un DSN pointant vers la base de données Access, de modifier le fichier connection.inc (en utilisant votre DSN) et de créer un répertoire virtuel dans IIS de nom contactasp. Installation avec SQL-Server ============================ - Transférer la base Access dans SQL-Server . Lancer Access avec la base contact.mdb . Choisir Outils > Utilitaires de base de données > Assistant de migration SQL-Server . Choisir : Créer une nouvelle base de données et cliquez sur Suivant . Dans "Donner un nom à votre nouvelle base de données", choisissez un nom ou laisser le nom par défaut : contactSQL . Dans "Quelles tables souhaitez-vous exporter", cliquez sur contact et le bouton ">" . Dans la page suivante, champ "Quelles données souhaitez-vous inclure" choisissez "Non, jamais" pour l'option "Ajoutez des champs d'horodatage aux tables" et l'option "Créer seulement la structure de la table" ne doit pas être cochée. . Dans la page suivante, choississez "Pas de modifications pour l'application" . cliquez sur "Terminer" - Lancer "Entreprise Manager" pour SQL-Server . Vérifier que la base de données "contactSQL" existe et que la table contient bien des enregistrements . Ajouter l'utilisateur IUSR_machine dans Utilisateurs (pour IIS) . IMPORTANT: Cliquez sur le nouvel utilisateur YYY\IUSR_machine puis Propriétés et sélectionnez db_datareader et db_datawriter pour "Membre du rôle de base de données" (Nous vous recommandons de prendre contact avec votre administrateur SQL-Server pour une meilleure installation de la base) - Créer un lien ODBC de nom "contactSQL" avec un DSN Système (Source de données système) de type SQL-Server pointant sur la base contactSQL (dans l'option "changer la base de données par défaut") - Dézipper l'archive dans un répertoire - Créer un répertoire virtuel avec IIS de nom 'contactasp' pointant vers le répertoire contactasp de la livraison - Vérifier le fichier connection.inc Il doit y avoir : <% Dim DB_connection ' -- example with DSN -- DB_connection = "dsn=contactSQL" %> - Lancer l'application Lancement de l'application ========================== Lancer Microsoft Internet Explorer et entrer comme URL: http://localhost/contactasp/contact.html Techniques pour le debug ======================= Le debug d'une application avec connexion avec une base de données sur un serveur est un sport de haut-niveau ;-) Debug dans l'environnement Flash -------------------------------- - pour réaliser du debug dans Flash, il est conseillé de modifier les URL des XMLConnector. XMLConnector contact_con : - mettre comme URL : http://localhost/contactasp/getdata.asp (au lieu de getdata.asp) XMLConnector save_con - mettre comme URL : http://localhost/contactasp/savedata.asp Vous pouvez tester votre application dans l'environnement Flash. Debug de la lecture de la BD et de la génération dufichier XML -------------------------------------------------------------- Il suffit de lancer http://localhost/contactasp/getdata.asp Vous pouvez visualiser le fichier XML généré avec Internet Explorer Test de l'écriture dans la BD à partir du fichier XML updatePacket ------------------------------------------------------------------ Il faut tester en deux étapes : 1- Modifier le fichier savedata.asp en modifiant la ligne suivante : saveUpdatePacket = True Lancer l'application Flash avec une écriture dans la BD Lorque l'application Flash écrit dans la BD, le fichier XML généré par Flash est sauvé localement dans le fichier updatePacket.xml 2- Tester l'écriture dans la BD par : http://localhost/contactasp/savedata.asp?debug=1 Vous lancer l'écriture dans la BD avec le fichier local updatePacket.xml Si des erreurs ASP se produisent, il n'y a plus qu'à les corriger. Bons tests... PhilFlash http://philflash.inway.fr philflash@inway.fr ===================================================================== ===================================================================== Here is a demonstration of how Flash can be connected to a database Access or SQL-Server. The example shows how to read and write in a database (Access or SQL-Server) from Flash using the updatePacket technique. An 'updatePacket' can write modifications - and only modifications - to a database which were done by the user on the data model (changing a value, deleting a record, creating a record). This example illustrates also how data can be saved and restored on the client side with SharedObject. Requirements =========== - Server IIS. - Access or SQL-Server. - Recommended: Install MSXML 4.0 SP2 Release Notes see http://msdn.microsoft.com/xml. Files ===== connexion.inc : DB connection parameters getdata.asp : reading of the DB and generation of an XML file for the data. savedata.asp : writing to the DB (with decoding of an updatePacket XML file) and generation of an XML file for the result. contact.mdb : Access database. MainForm.as : actions in ActionScript. Installation with Access ======================== Recommended ----------- - Unzip the whole package into a separate directory. - Create a virtual directory with IIS named 'contactasp' pointing to 'contactasp' in the delivery directory. - Check the file 'connnction.inc' (if you have changed the name of the DSN). - Run the application. Note that if you install everything in C:\Inetpub\wwwroot, you have problems writing in the database. For a cleaner solution, install the database in a directory, create a DSN pointing to the Access database, modify 'connection.inc' (use your DSN) and create a virtual directory in IIS named 'contactasp'. Installation with SQL-Server ============================ - Transfer the Access database to SQL-Server (for more information, see http://support.microsoft.com/support/kb/articles/Q237/9/80.ASP HOW TO: Convert an Access Database to SQL Server) French commands translated here: . Run Access with contact.mdb. . Choose Tools > Database Utilities > SQL-server Migration Wizard. . Choose Create a new DB and press Next. . In Name your new DB, choose a name or keep the default name: contactSQL. . In Which tables do you wish to export", click on contact then >. . On the next page, field What data do you wish to include, choose No, never for the option Add time fields to tables and make sure the option Create only the table structure is checked off. . On the next page, choose No modifications for the application. . Push Finish. - Run the Enterprise Manager for SQL-Server: . Check that the DB "contactSQL" exists and that the table is filled with records. . Add the user IUSR_machine in Users (for IIS). . IMPORTANT: Click on the new user YYY\IUSR_machine then click on Properties and select db_datareader and db_datawriter for DB role member. (You should get in touch with your SQL-Server administrator for a better installation). - Create an ODBC link named "contactSQL" with DSN System (System Data Source) of type SQL-Server pointing to the DB conctactSQL (in the option Change the default DB). - Unzip the whole package into a separate directory. - Create a virtual directory with IIS named 'contactasp' pointing to 'contactasp' in the delivery directory. - Edit the file 'connection.inc'. It must contain: <% Dim DB_connection ' -- example with DSN -- DB_connection = "dsn=contactSQL" %> - Run the application. Running the application ======================= - Run a browser and enter the following URL: http://localhost/contactasp/contact.html Debugging techniques ==================== Debugging an application with a connection to a database server is top-level sports ;-). Debugging within the Flash environment -------------------------------------- - To make debugging from Flash easier, it's better to modify the XMLConnector URLs. XMLConnector contact_con: - Use the URL http://localhost/contactasp/getdata.asp (instead of getdata.asp). XMLConnector save_con: - Use the URL http://localhost/contactasp/savedata.asp. Now you can test your application in the Flash environment. Debugging reading the DB and generating the XML file ---------------------------------------------------- Simply run http://localhost/contactasp/getdata.asp. You can display the XML file which is generated with a browser. Testing writing in the DB with an XML updatePacket file ------------------------------------------------------- It takes two steps: 1- Edit the file 'savedata.asp' and set saveUpdatePacket to True: saveUpdatePacket = True Run the Flash application which writes to the DB. When the Flash application writes to the DB, the XML file generated by Flash is saved locally in the file 'updatePacket.xml'. 2- Test writing to the DB: http://localhost/contactasp/savedata.asp?debug=1 Start writing to the DB with the local file 'updatePacket.xml'. If you encounter an error, just correct it. Bons tests... PhilFlash http://philflash.inway.fr philflash@inway.fr