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. Connecting to a datasource

Connecting to a datasource

Scheduled Pinned Locked Moved C / C++ / MFC
help
7 Posts 3 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
    si_69
    wrote on last edited by
    #1

    hello all im connecting to a ODBC datasource and im using hr = cpDbCMIS->Open("DSN=CP_CMIS_CON;UID=STUD_ADMIN;PWD=STUD_ADMIN","","",-1); to connect to it, this works fine when i already know the user name and password but i need to connect to different databases, with different user names and passwords which would be provided by the users, and then stored in CString variables i want to use something like CString CnnStr="DSN=CP_CMIS_CON;UID="+username+";PWD="+password+""; hr = cpDbCMIS->Open(CnnStr,"","",-1); but i cant get that to work :confused: can ne1 help at all thanks simon

    G D 2 Replies Last reply
    0
    • S si_69

      hello all im connecting to a ODBC datasource and im using hr = cpDbCMIS->Open("DSN=CP_CMIS_CON;UID=STUD_ADMIN;PWD=STUD_ADMIN","","",-1); to connect to it, this works fine when i already know the user name and password but i need to connect to different databases, with different user names and passwords which would be provided by the users, and then stored in CString variables i want to use something like CString CnnStr="DSN=CP_CMIS_CON;UID="+username+";PWD="+password+""; hr = cpDbCMIS->Open(CnnStr,"","",-1); but i cant get that to work :confused: can ne1 help at all thanks simon

      G Offline
      G Offline
      GermanGeorge
      wrote on last edited by
      #2

      try CString tmp="DSN=EOP;UID="+name+";PWD="+pw; m_pDatabase->OpenEx(tmp, CDatabase::noOdbcDialog );

      S 1 Reply Last reply
      0
      • G GermanGeorge

        try CString tmp="DSN=EOP;UID="+name+";PWD="+pw; m_pDatabase->OpenEx(tmp, CDatabase::noOdbcDialog );

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

        thanks but that doesnt work either i dont use OpenEx it is an ado connection if that helps simon

        1 Reply Last reply
        0
        • S si_69

          hello all im connecting to a ODBC datasource and im using hr = cpDbCMIS->Open("DSN=CP_CMIS_CON;UID=STUD_ADMIN;PWD=STUD_ADMIN","","",-1); to connect to it, this works fine when i already know the user name and password but i need to connect to different databases, with different user names and passwords which would be provided by the users, and then stored in CString variables i want to use something like CString CnnStr="DSN=CP_CMIS_CON;UID="+username+";PWD="+password+""; hr = cpDbCMIS->Open(CnnStr,"","",-1); but i cant get that to work :confused: can ne1 help at all thanks simon

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          si_69 wrote: but i cant get that to work Why? What is the value of CnnStr after the assignment? It should be the same as the first value you've shown being passed to Open().


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          S 1 Reply Last reply
          0
          • D David Crow

            si_69 wrote: but i cant get that to work Why? What is the value of CnnStr after the assignment? It should be the same as the first value you've shown being passed to Open().


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

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

            im a bit crap a c++ but if i use CString CnnStr="DSN=CP_CMIS_CON;UID="+simon11+";PWD="+simon12+""; hr = cpDbCMIS->Open(CnnStr,"","",-1); then i get a complier error error C2664: 'Connection15::Open' : cannot convert parameter 1 from 'CString' to '_bstr_t' if i use GermanGeorge's example CString tmp="DSN=CP_CMIS_CON;UID="+simon11+";PWD="+simon12; cpDbCMIS->OpenEx(tmp, CDatabase::noOdbcDialog ); then i get the compiler error error C2039: 'OpenEx' : is not a member of '_Connection'

            D 1 Reply Last reply
            0
            • S si_69

              im a bit crap a c++ but if i use CString CnnStr="DSN=CP_CMIS_CON;UID="+simon11+";PWD="+simon12+""; hr = cpDbCMIS->Open(CnnStr,"","",-1); then i get a complier error error C2664: 'Connection15::Open' : cannot convert parameter 1 from 'CString' to '_bstr_t' if i use GermanGeorge's example CString tmp="DSN=CP_CMIS_CON;UID="+simon11+";PWD="+simon12; cpDbCMIS->OpenEx(tmp, CDatabase::noOdbcDialog ); then i get the compiler error error C2039: 'OpenEx' : is not a member of '_Connection'

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              How about:

              hr = cpDbCMIS->Open(_bstr_t((LPCTSTR) CnnStr), "", "", -1);


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              S 1 Reply Last reply
              0
              • D David Crow

                How about:

                hr = cpDbCMIS->Open(_bstr_t((LPCTSTR) CnnStr), "", "", -1);


                "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

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

                superb, thanks :-D

                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