Index: trunk/psModules/src/detrend/pmDetrendDB.c
===================================================================
--- trunk/psModules/src/detrend/pmDetrendDB.c	(revision 11108)
+++ trunk/psModules/src/detrend/pmDetrendDB.c	(revision 11421)
@@ -6,4 +6,5 @@
 #include <string.h>
 #include <pslib.h>
+#include "pmConfig.h"
 #include "pmFPA.h"
 #include "pmFPALevel.h"
@@ -93,6 +94,33 @@
 // detselect -camera (camera) -time (time) -type (type) [others]
 // returns: (type) (class) (exp_flag) DONE
-pmDetrendSelectResults *pmDetrendSelect (const pmDetrendSelectOptions *options)
-{
+pmDetrendSelectResults *pmDetrendSelect (const pmDetrendSelectOptions *options,
+        const pmConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(options, NULL);
+    PS_ASSERT_PTR_NON_NULL(config, NULL);
+    PS_ASSERT_PTR_NON_NULL(config->site, NULL);
+
+    bool mdok;                          // Status of MD lookup
+    const char *dbserver = psMetadataLookupStr(&mdok, config->site, "DBSERVER"); // Database server
+    if (!mdok || strlen(dbserver) == 0) {
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBSERVER in site configuration.\n");
+        return NULL;
+    }
+    const char *dbname = psMetadataLookupStr(&mdok, config->site, "DBNAME"); // Database name
+    if (!mdok || strlen(dbname) == 0) {
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBNAME in site configuration.\n");
+        return NULL;
+    }
+    const char *dbuser = psMetadataLookupStr(&mdok, config->site, "DBUSER"); // Database user
+    if (!mdok || strlen(dbuser) == 0) {
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBUSER in site configuration.\n");
+        return NULL;
+    }
+    const char *dbpassword = psMetadataLookupStr(&mdok, config->site, "DBPASSWORD"); // Database password
+    if (!mdok || strlen(dbpassword) == 0) {
+        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find DBPASSWORD in site configuration.\n");
+        return NULL;
+    }
+
     int status, exit_status;
     char *line = NULL;
@@ -101,9 +129,8 @@
     unsigned int nFail;
 
-    // XXXXX ***** MAJOR HACK ***** Josh dropped INST from detrun, so I am using 'object' for
-    // now in dettool ('object' is not relevant to detrun!!!)
-
     pmDetrendSelectResults *results = pmDetrendSelectResultsAlloc();
-    psStringAppend (&line, "detselect -search -inst %s -det_type %s -time %s", options->camera, type, time);
+    psStringAppend (&line, "detselect -search -inst %s -det_type %s -time %s "
+                    "-dbserver %s -dbname %s -dbuser %s -dbpassword %s",
+                    options->camera, type, time, dbserver, dbname, dbuser, dbpassword);
 
     if (options->filter) {
