The Problem
The client is a small consulting company that has sales agents located throughout Australia. Agents are usually in the field and prospective clients are being added every day into a contacts public folder within Microsoft® Exchange. Sales agents must call their office to get information about a client if they did not add them to their personal contacts before leaving the office. As a rapidly growing company, they cannot afford to lose a prospective client if their information cannot be accessed instantly by a field agent.
The SolutionSynchronize the public folders with a database and provide a searchable web interface to the database. The benefits of this solution are that it is comparatively cheap and took one week to implement. The sales agents are happy and the company is happy with an affordable solution.
Let’s review how to build and implement this solution
Figure 1: Application Structure
When a user updates the "Red Pico Contacts" public folder, they need to synchronize it with the rpcontactdb database that is on the web server. To do this they launch the Synchronization tool to get data from the public folder and put it in the database. Once the data is in the database, the user can search the data from their BlackBerry smartphone using the BlackBerry® Browser. The search is performed against the full name field.
Technical Components
- Red Pico Contacts Public Folder
This is the public folder that has all of the contacts. It resides on the Microsoft Exchange Server.
- Synchronization Tool
This tool was developed using C# .NET. It gets information from the Red Pico Contacts Public Folder and puts it into a MySQL database called rpcontactdb. The synchronization tool resides on the desktop.
- rpcontactdb
This is a MySQL database which will contain all information after synchronization and is used to perform search queries from the BlackBerry smartphone.
- RPContacts Blackberry Webpage
This is the home page that serves BlackBerry smartphone users.
Please take a look at Figure 1 to find out how these components interact.
Let’s take a look at each of the individual components:
- Red Pico Contacts Public Folder
This is a Microsoft Exchange Server public folder. In this case it has contacts in it.
- Synchronization tool
This is a very simple tool. After entering the information in the public folder, run this application to delete all rows in the database and insert all records from the public folder into the database.
Figure 2: Synchronization ToolThe application uses threads to update the status field. After the button labeled "Synchronize Red Pico Contact Database" has been pressed, the application will store each public folder contact as a HashTable in an ArrayList called contactsList. It then retrieves each contact in sequence and inserts it in the database while displaying the status of the record. Some basic checks have been incorporated to ensure that the full name field is not blank while retrieving the contacts list from the Public Folder. Database transactions are also used to perform a rollback in case of an error during insertion.
private void doWork() { MySQLTransaction DBTxn = null; // create new connection called con try{ ArrayList contactsList = getContacts(); // declaring string .... MySQLCommand DBCmd = new MySQLCommand(); // Invoking thread for Status Message Invoke(new StringDelegate(Status), new object[] { "Connecting to MySQL..." }); // Open connection....... // Begin Transaction..... DBCmd.Connection = con; DBCmd.Transaction = DBTxn; //Deleting the table sqlstr = "DELETE FROM contacts"; DBCmd.CommandText = sqlstr; DBCmd.ExecuteNonQuery(); // Now retrieve items one by one and insert. int j = 1; foreach (object item in contactsList) { Invoke(new StringDelegate(Status), new object[] {"Updating " + j + " of " + contactsList.Count+" contacts in the database."}); fullname = ((Hashtable)item)["full_name"].ToString().Replace("'","''"); fname = ((Hashtable)item)["first_name"].ToString().Replace("'","''"); lname = ((Hashtable)item)["last_name"].ToString().Replace("'","''"); email = ((Hashtable)item)["email"].ToString().Replace("'","''"); company = ((Hashtable)item)["company_name"].ToString().Replace("'","''"); bus_add = ((Hashtable)item)["business_address"].ToString().Replace("'","''"); bus_ph = ((Hashtable)item)["business_phone"].ToString().Replace("'","''"); bus_fax = ((Hashtable)item)["business_fax"].ToString().Replace("'","''"); home_ph = ((Hashtable)item)["home_phone"].ToString().Replace("'","''"); mob_ph = ((Hashtable)item)["mobile_phone"].ToString().Replace("'","''"); sqlstr = "INSERT INTO contacts (full_name, first_name, last_name, email, company_name, business_address, business_phone," + "business_fax, home_phone, mobile_phone) VALUES ('" + fullname + "','" + fname + "','" + lname + "','" + email + "','"+ company + "','" + bus_add + "','" + bus_ph + "','" + bus_fax + "','" + home_ph + "','" + mob_ph + "')"; DBCmd.CommandText = sqlstr; DBCmd.ExecuteNonQuery(); j++; } DBTxn.Commit(); Invoke(new StringDelegate(Status), new object[] { "Update Successful !" }); } catch (Exception ee) { // Display error message in status.... } finally { // Close the connection con.Close(); } } - rpcontactdb
The fields in this database are full name, first name, last name, email, company, business address, business phone, business fax, home phone, and mobile phone.
- RPContacts BlackBerry Webpage
This is a simple mobile web form created using Microsoft® Visual Studio® .NET 2005.
Figure 3: Mobile Web Form
There are validation checks to ensure that at least two characters are entered. The error is displayed in the Label2 field. Once the user enters the name, the application searches the 'full name' field of the database and returns the matching text. The results appear similar to Figure 4. You can call or email by clicking on these links.
Figure 4: Search Results
Anubhav (Ash) Srivastava has been programming in .NET and Java® for 5 years working with enterprise applications. He has been a BlackBerry smartphone enthusiast since 2004. He runs his own consulting company "Red Pico Consulting Services Inc," that focuses on issues related to BlackBerry smartphones. His experience with a wide range of technologies and database environments has inspired him to help people integrate technology to simplify tasks and make businesses more efficient. His current passion is in leveraging existing infrastructures to provide enterprise applications on BlackBerry smartphones. You can email him at
Please email your comments, suggestions and editorial submissions to