Fixed a bug where the DBName parameter wasn't being used.  Added a few debugging messages.
Updated the primary key to include devices.
Added a database name parameter.