DEVELOPING WINDOWS MOBILE APPLICATIONS - TOM SLEE SQL ANYWHERE PRODUCT MANAGEMENT AUGUST 2009

Page created by Megan Webster
 
CONTINUE READING
DEVELOPING WINDOWS MOBILE
APPLICATIONS
TOM SLEE
SQL ANYWHERE PRODUCT MANAGEMENT

AUGUST 2009
Abstract

• Beginner‐level
  B i      l l presentation
                     t ti introduces
                            i t d    you tto developing
                                             d l i data‐d t
 driven applications for Windows Mobile devices and .NET
 programming languages.

• Topics include:
   • SQL Anywhere for Windows Mobile,

   • UltraLite database,,

   • MobiLink data synchronization,

   • Visual Studio integration.
                   integration
Agenda

•   Why Develop
    Wh   D l Windows
                  Wi d      Mobile
                            M bil Database
                                   D t b   Applications?
                                           A li ti ?
•   SQL Anywhere for Windows Mobile – Overview
•   Installation
•   Development Requirements
•   Getting Started – Demonstration
•   Server Options
              p
•   Visual Studio Development – Demonstration
•   Deploying the Database
•   Adding Synchronization with MobiLink – Demonstration
•   Security Considerations
•   Additional Resources
Why Develop Windows Mobile Database
A li i ?
Applications?
• Windows Mobile p
                 prevalent at the front lines of business
   • Some examples: sales force automation, mobile healthcare, surveying,
     logistics, hospitality, inspection
   • Lower hardware and maintenance costs than laptop
   • Specialized or ruggedized handhelds for specific needs
   • Built‐in cell phone and wireless for business needs
   • Long battery
           b        life
                    lif compared  d to consumer devices
                                                d i
Why Develop Windows Mobile Database
A li i ? (cont.)
Applications? ( )
• Benefits of mobile database applications
                               pp
   •   Offline access to data
   •   Only deploy data subsets specific to end‐user
   •   Bi directional synchronization to enterprise backends
       Bi‐directional
   •   Synchronize only changes
   •   Synchronize only when required         Reduce costs
Why Develop Windows Mobile Database
A li i ? (cont.)
Applications? ( )
• End‐users demand…
   • Powerful applications that are easy to use
   • Quick access to data at all times
   • Security for stored information and data transmission

• Developers demand…
   •   Rich functionality to implement requirements
   •   High performance for data access and manipulation
   •   Minimal database maintenance
   •   Robust data exchange capabilities
   •   End‐to‐end security (encryption)
SQL Anywhere for WM ‐ Overview

• Full SQL
        Q support
              pp ((views,, stored p procedures,, user‐defined
  functions)
• High performance out of the box (dynamic cache sizing, cost‐
  b d optimizer)
  based     ti i )
• Self‐administration features (automatic recovery, performance
  tuning,
        g, and conflict detection))
• Bi‐directional synchronization to Sybase, Oracle, SQL Server,
  DB2 and MySQL
• 128‐bit strong encryption of database and communication
  streams
Installation
• Install from Windows desktop (Deployment Wizard)
    •   Full install is 20 MB, typical is 10 MB – small footprint
    •   Install in main memory or storage card
    •   Supports up to Windows Mobile 6 (all editions)
    •   Saves CAB file for future deployments
• Localization
    • Software: 5 languages
                     g g ((en/fr/de/jp/zh)
                               / / /jp/ )
    • Deployment: 9 additional languages
• Available interfaces: ADO.NET, ODBC, Embedded SQL
• Additional components:
    • MobiLink and SQL Remote synchronization
    • QAnywhere messaging
Development Requirements

• Sybase
   y     Central and Interactive SQL
                                  Q Admin Tools
   •   Create new databases, add schema, add data
   •   Perform ad‐hoc queries
   •   Create synchronization models for existing schemas
   •   Debug stored procedures and functions
   •   Application profiling
• Programming Environment
   • Visual Studio 2005 or 2008 (.NET CF 2.0 and higher)
   • PocketBuilder
   • JDBC (?)
Getting Started

• Create Windows Mobile database
     • New (empty) database
     • New database with schema, but no data (for synchronization)
•   Deploy
    D   l database
            d t b    t WM
                     to
•   Start database on WM
•   Connect from desktop via ODBC
•   Start developing using Visual Studio or PocketBuilder

• Debug and test
• Deploy application
Getting Started ‐ Demo

• Creatingg and deploying
                  p y g a database to Windows Mobile
   • Create Database Wizard
   • Deploy Synchronization Model Wizard
SQL Anywhere
      y      for Windows Mobile Server
Options
• Start db server by launching dbsrv11.exe
                               dbsrv11 exe
    – Complete server startup options
    – When connecting from desktop, use TCP/IP
• Auto‐start db from within your application
    – Use a file data source
• Considerations
    – Database encryption using AES_FIPS
                                   AES FIPS and AES256_FIPS
                                                AES256 FIPS
      algorithms
    – No personal db server, just network db server
    – Cannot run two db servers at the same time, but can
      run multiple
              l i l dbs
                    db in
                        i the
                           h same server
    – No support for db mirroring, external stored
      procedures, Java in the db, remote data access
    – By default, no ICU library is installed
SQL Anywhere for Windows Mobile Server
O i
Options ((cont.))
• File data source example
                       p
   • Use the DSN or the FILEDSN keyword is your connection string
   • WM searches for the data source files in the root directory of the
     device (e.g.
            (e g \filename.dsn)
                  \filename dsn)
   • Create file dsn on desktop, then transfer to Windows Mobile

         [ODBC]
         uid=dba
         pwd=sql
         enginename=demo
         databasename=demo
         databasefile=\My Documents\demo.db
         start=\Program Files\SQLAny11\dbsrv11.exe
Visual Studio Development

• Leadingg IDE for Windows Mobile
• Create Smart Device project
• Deploy to WM emulator (test) vs. device (production)

• If using emulator…
   • C
     Connect to ActiveSync
                 A i S     via
                             i D
                               Device
                                  i EEmulator
                                        l     ((cradle)
                                                   dl ) to obtain
                                                            b i networkk
     connection (TCP/IP)
   • Install SQL Anywhere – same procedure as actual device
Programming Interfaces

• .NET Compact
          p Framework ((ADO.NET))
   • Versions 2.0 and 3.5
   • Develop using C#, VB.NET or C/C++
   • SQL Anywhere .NET
                    NET data provider (iAnywhere
                                      (iAnywhere.Data.SQLAnywhere.dll)
                                                 Data SQLAnywhere dll)

• Other
   • ODBC
   • Embedded SQL
                        Samples available with SA installation
SQL Anywhere .NET Data Provider
Connecting to a Database

• Make sure to add a reference to the SA ((CE)) assemblyy
   •   C:\Program Files\SQL Anywhere 11\CE\Assembly\V2\iAnywhere.Data.SQLAnywhere.dll

       using
         i   iA
             iAnywhere.Data.SQLAnywhere;
                  h    D t SQLA    h

       SAConnection conn;

       try
       {
             conn = new SAConnection(
                 "Data Source=SQL Anywhere 11 Demo;UID=DBA;PWD=sql");
             conn.Open();
       }
       catch (SAException ex)
       {
           // Error handling
       }

       conn.Close();
Accessing Records: SACommand

• Recommended method to access data
• Used with SADataReader (retrieves one row at a time)

  SACommand cmd = new SACommand("SELECT Surname FROM Employees", conn);

  SADataReader reader = cmd.ExecuteReader();

  // Populate list control
  listEmployees.BeginUpdate();
  while (reader.Read())
  {
      listEmployees.Items.Add(reader.GetString(0));
  }
  listEmployees.EndUpdate();

  reader.Close();
     d   Cl   ()
Accessing Records: SADataAdapter

• Retrieves entire result set in a DataSet
• DataSet is disconnected

  DataSet ds = new DataSet();

  SADataAdapter da = new SADataAdapter(
      "SELECT Surname FROM Employees", conn);
  da.Fill(ds, "Results");

  dataGrid1.DataSource = ds.Tables["Results"];
Using Stored Procedures

• ExecuteReader,, ExecuteNonQuery,
                            Q y, ExecuteScalar

SACommand cmd = new SACommand("ShowProductInfo", conn);
cmd.CommandType = CommandType.StoredProcedure;

// SACommand cmd = new SACommand("call ShowProductInfo(?)", conn);
// cmd.CommandType = CommandType.Text;

SAParameter param = cmd.CreateParameter();
param.SADbType = SADbType.Int32;
param.Direction = ParameterDirection.Input;
param.Value = 301;
cmd.Parameters.Add(param);

SADataReader reader = cmd.ExecuteReader();
reader.Read();
int ID = reader.GetInt32(0);
string name = reader.GetString(1);
string
 t i   d
       descrip
            i = reader.GetString(2);
                    d   G tSt i (2)
decimal price = reader.GetDecimal(6);

// SACommand cmd = new SACommand("call ShowProductInfo( 301 )", conn);
Changing Data

// Inserting
           g rows
SACommand insertCmd = new SACommand(
    "INSERT INTO Departments( DepartmentID, DepartmentName ) VALUES( ?, ? )", conn );

SAParameter parm = new SAParameter();
parm.SADbType = SADbType.Integer;
i
insertCmd.Parameters.Add(parm);
      C d             dd(    )
parm = new SAParameter();
parm.SADbType = SADbType.Char;
insertCmd.Parameters.Add(parm);

insertCmd.Parameters[0].Value
insertCmd Parameters[0] Value = 600;
insertCmd.Parameters[1].Value = "Eastern Sales";
int recordsAffected = insertCmd.ExecuteNonQuery();
insertCmd.Parameters[0].Value = 700;
insertCmd.Parameters[1].Value = "Western Sales";
recordsAffected = insertCmd.ExecuteNonQuery();

// Updating rows
SACommand updateCmd = new SACommand(
    "UPDATE Departments SET DepartmentName = 'Engineering' WHERE DepartmentID=100", conn );
int recordsAffected = updateCmd.ExecuteNonQuery();

// Deleting rows
SACommand deleteCmd = new SACommand(
    "DELETE FROM Departments WHERE ( DepartmentID > 500 )", conn);
int recordsAffected = deleteCmd.ExecuteNonQuery();
Visual Studio Application ‐ Demo
Deploying the Database

•   Database server binaries
•   SQL Anywhere .NET Data Provider
•   ODBC driver                              Depending on
•   Embedded SQL client files                client interface
•   File data source
•   Database file
•   Script files – optional
•   Encryption and TLS binaries – optional
Adding Synchronization with MobiLink

• Create Synchronization
          y              Model Wizard
   • Connect to backend and visually define synchronization logic
   • No need to write synchronization scripts
• Deploy
  D l Synchronization
         S h i ti Model
                      M d l Wi
                            Wizard
                                 d
   • Automatically deploy sync logic to backend
   • Automatically create new “sync‐ready” mobile database
• MobiLink synchronization server to handle sync requests
• MobiLink client invoked from Windows Mobile to trigger
  synchronization
      h i i
• Server‐initiated synchronization and messaging
MobiLink Synchronization – Demo

 Windows
  Mobile
Security Considerations

• Device theft or loss
   • 128‐bit encryption of the database
   • No difference whether db is stored in main memory or external
     storage card
• Interception of data transmission
   • 128‐bit encryption of client/server and MobiLink communication
• Unauthorized access to mobile device
   • Ensure only relevant data is downloaded to device
   • Provide log in access via user name and password
• Device provisioning
   • Use systems management software such as Afaria
Additional Resources

• Sybase.com/iAnywhere
   y        / y
   • Free SQL Anywhere Developer Edition
   • Whitepapers and sample code
   • Developer blogs
• Other TechWave sessions
   •   Developing Applications for SQL Anywhere using Visual Studio
   •   Synchronizing SQL Anywhere Databases in a .NET Environment
   •   Mobilizing ASE, Oracle and SQL Server Databases
   •   Afaria track
Questions?

             Thank you!
You can also read