Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. ADO Connection

ADO Connection

Scheduled Pinned Locked Moved C / C++ / MFC
help
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stu
    wrote on last edited by
    #1

    Hello, I am trying to establish a connection and I think I am missing something very basic. I get an "Invalid Pointer" error when the Open() is called. I am importing msado15.dll in StdAfx.h which is included in the file that contains the code below. My code: _ConnectionPtr pConn; HRESULT hr; try{ hr = pConn.CreateInstance(__uuidof(Connection)); _bstr_t bstrDSN = "DSN=test_db;UID=gstewart;PWD=gstewart"; pConn->Open(bstrDSN,"","", -1); } catch (_com_error e){ MessageBox(e.ErrorMessage()); }

    O M 2 Replies Last reply
    0
    • S Stu

      Hello, I am trying to establish a connection and I think I am missing something very basic. I get an "Invalid Pointer" error when the Open() is called. I am importing msado15.dll in StdAfx.h which is included in the file that contains the code below. My code: _ConnectionPtr pConn; HRESULT hr; try{ hr = pConn.CreateInstance(__uuidof(Connection)); _bstr_t bstrDSN = "DSN=test_db;UID=gstewart;PWD=gstewart"; pConn->Open(bstrDSN,"","", -1); } catch (_com_error e){ MessageBox(e.ErrorMessage()); }

      O Offline
      O Offline
      ORi x
      wrote on last edited by
      #2

      try catch (_com_error &e)

      S 1 Reply Last reply
      0
      • O ORi x

        try catch (_com_error &e)

        S Offline
        S Offline
        Stu
        wrote on last edited by
        #3

        The catch block shouldn't be executing in the first place. For some reason my connection pointer isn't valid after hr = pConn.CreateInstance(__uuidof(Connection)); is executed. Any ideas what I'm missing? I think I'm missing a header file or something. It comiles just fine though....????

        1 Reply Last reply
        0
        • S Stu

          Hello, I am trying to establish a connection and I think I am missing something very basic. I get an "Invalid Pointer" error when the Open() is called. I am importing msado15.dll in StdAfx.h which is included in the file that contains the code below. My code: _ConnectionPtr pConn; HRESULT hr; try{ hr = pConn.CreateInstance(__uuidof(Connection)); _bstr_t bstrDSN = "DSN=test_db;UID=gstewart;PWD=gstewart"; pConn->Open(bstrDSN,"","", -1); } catch (_com_error e){ MessageBox(e.ErrorMessage()); }

          M Offline
          M Offline
          Michael P Butler
          wrote on last edited by
          #4

          This is the code I use to create an ADO connection, the only difference I can see is that I pass cast my empty strings to _bstr_t first. Are you getting a compile error or a runtime error

          _ConnectionPtr m_pConnection
          HRESULT CAdoConnection::Connect(std::string sConnectionStr)
          {
          HRESULT hr = S_OK;
          try
          {
          hr = m_pConnection.CreateInstance(__uuidof(Connection));
          if(hr == S_OK)
          {
          hr = m_pConnection->Open(_bstr_t(sConnectionStr.data()), _bstr_t(""), _bstr_t(""), adConnectUnspecified);
          }
          }
          catch (_com_error &e)
          {
          }

          return hr;
          

          }

          Michael :-)

          S 1 Reply Last reply
          0
          • M Michael P Butler

            This is the code I use to create an ADO connection, the only difference I can see is that I pass cast my empty strings to _bstr_t first. Are you getting a compile error or a runtime error

            _ConnectionPtr m_pConnection
            HRESULT CAdoConnection::Connect(std::string sConnectionStr)
            {
            HRESULT hr = S_OK;
            try
            {
            hr = m_pConnection.CreateInstance(__uuidof(Connection));
            if(hr == S_OK)
            {
            hr = m_pConnection->Open(_bstr_t(sConnectionStr.data()), _bstr_t(""), _bstr_t(""), adConnectUnspecified);
            }
            }
            catch (_com_error &e)
            {
            }

            return hr;
            

            }

            Michael :-)

            S Offline
            S Offline
            Stu
            wrote on last edited by
            #5

            Michael, I tried the casting and also added the adConnectUnspecified argument. My error occurs at runtime on the Open(...). Thanks, Glen

            M 1 Reply Last reply
            0
            • S Stu

              Michael, I tried the casting and also added the adConnectUnspecified argument. My error occurs at runtime on the Open(...). Thanks, Glen

              M Offline
              M Offline
              Michael P Butler
              wrote on last edited by
              #6

              What error number does the try and catch get for the open? Michael :-)

              S 1 Reply Last reply
              0
              • M Michael P Butler

                What error number does the try and catch get for the open? Michael :-)

                S Offline
                S Offline
                Stu
                wrote on last edited by
                #7

                After hr = pConn.CreateInstance(__uuidof(Connection)); the value of hr is -2147221008. I can't seem to get anything more from the _com_error object that is thrown except that the errormessage says "Invalid Pointer". I wonder if there could be something wrong with my compile options? :confused:

                C 1 Reply Last reply
                0
                • S Stu

                  After hr = pConn.CreateInstance(__uuidof(Connection)); the value of hr is -2147221008. I can't seem to get anything more from the _com_error object that is thrown except that the errormessage says "Invalid Pointer". I wonder if there could be something wrong with my compile options? :confused:

                  C Offline
                  C Offline
                  Carlos Antollini
                  wrote on last edited by
                  #8

                  Did you use the CoInitialize()? Cheers!!! Carlos Antollini.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups