title: ADO application compiled in Windows 7 runs in Windows 7 does not run in Windows XP, msado15.dll
body: <p>I have a program that uses the msado15.dll to connect to a database. The program runs just fine on my Windows 7 machine, but most (if not all) of the end users are running Windows XP, where it does not work. I have determined that the error is in opening the database, but there seems to be no error message, so I'm not sure what is going wrong. Here is the code I that have written, as well as the call to open the database:</p>
  
  <p>Database.h:</p>
  
  <pre><code>#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
  rename("EOF","adoEOF")
  
  typedef ADODB::_RecordsetPtr RecPtr;
  typedef ADODB::_ConnectionPtr CnnPtr;
  
  struct Database {
      CnnPtr m_Cnn;
      Database();
      ~Database();
      bool Open(const char* CnnStr, const char* UserName, const char* Pwd);
      RecPtr Execute(const char* CmdStr);
      bool Close();
  };
  </code></pre>
  
  <p>Database.cpp:</p>
  
  <pre><code>#include "stdafx.h"
  #include "Database.h"
  #include "ErrorDlg.h"
  
  using namespace ADODB;
  
  Database::Database()
  {
      m_Cnn = NULL;
  }
  
  bool Database::Open(const char *CnnStr, const char *UserName, const char *Pwd)
  {
      ::CoInitialize(NULL);
      HRESULT hr;
      try {
          hr = m_Cnn.CreateInstance(__uuidof(Connection));
          m_Cnn-&gt;Open(CnnStr, UserName, Pwd, adConnectUnspecified);
      }
      catch (_com_error &amp;e) {
          CErrorDlg dlg; // makes a window that shows info aobut an error
          // the following pops up on XP when you start the .exe file and attempt to connect
          dlg.DoError(_T("Error opening database.")); //dlg.DoError(e.ErrorMessage()) gives me a blank message
          return 0;
      }
      return 1;
  }
  
  RecPtr Database::Execute(const char *CmdStr)
  {
      try {
          if (m_Cnn == NULL)
              return NULL;
          return m_Cnn-&gt;Execute(CmdStr, NULL, 1);
      }
      catch (_com_error &amp;e) {
          CErrorDlg dlg;
  
          dlg.DoError(_T("Error executing database command."));
          return NULL;
      }
  }
  
  bool Database::Close()
  {
      if (m_Cnn == NULL)
          return 0;
  
      try {
          m_Cnn-&gt;Close();
          m_Cnn = NULL;
      }
      catch (_com_error &amp;e) {
          CErrorDlg dlg;
  
          dlg.DoError(_T("Error closing database"));
          return 0;
      }
      return 1;
  }
  
  Database::~Database()
  {
      try {
          if (m_Cnn) {
              m_Cnn-&gt;Close();
              m_Cnn = NULL;
          }
      }
      catch (_com_error &amp;e) {
          CErrorDlg dlg;
  
          dlg.DoError(_T("Error deconstructing database"));
      }
  }
  </code></pre>
  
  <p>Database is opened like this: </p>
  
  <pre><code>m_db.Open("driver={SQL Server};server=myServer;database=myDatabase","myUser","myPwd")
  </code></pre>
  
  <p>where <code>m_db</code> is a <code>Database</code>. I have also tried <code>""</code> for both user and pwd above, and that gives me the same result: works on 7, but not XP.</p>
  
  <p>Why would this work properly on Windows 7, but not Windows XP? And what should I do to correct this?</p>