Open a file as ADO stream with read-only permissions

From: Dave Purrington (dpurrington-n0sp4m_at_yahoo.com)
Date: 05/20/04


Date: Thu, 20 May 2004 16:48:32 -0400

I'm trying to use an ADO stream to open a file on the filesystem. I only
have readonly access. The sample code from MSFT looks like this:

      _StreamPtr pStm(__uuidof(Stream));
      _variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
      try {
            pStm->raw_Open(varOptional, adModeUnknown,
adOpenStreamUnspecified,NULL,NULL);
            pStm->LoadFromFile(path);
      }
      catch(_com_error e)
      {
            throw e;
      }

This works fine if I have write access. But I can't open the stream if I
have only read access. I tried changing the second parameter of the Open
method to use adModeUnknown but I get a 0x800a0bb9 error, which indicates
parameters are not in agreement. I've also tried adModeDenyNone, and that
gets the same result. I've tried using a file reference to the file in the
varOptional object, but then it tells me "DB_NOT_FOUND" on the open. But I
know the URL is good because I can use check it out in the debugger and use
it in my browser.

Any ideas here? I can't even tell what the variant in the example above is
trying to do. All I know is it doesn't work for read-only access.

Thanks.

Dave P.
(n0sp4mdpurrington@yahoo.com)