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. Database & SysAdmin
  3. Database
  4. ado

ado

Scheduled Pinned Locked Moved Database
questionc++
13 Posts 2 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.
  • R Offline
    R Offline
    ranjjj
    wrote on last edited by
    #1

    In my c++ code ..i use ADO commands..and to get the permissions..for userss for each and every databse.. i use the following commands.. sprintf(str1,"SELECT PERMISSIONS(OBJECT_ID('TABLE1'))"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); the abopve function returns an integer value.. how do i read the value?? ranjani

    H 1 Reply Last reply
    0
    • R ranjjj

      In my c++ code ..i use ADO commands..and to get the permissions..for userss for each and every databse.. i use the following commands.. sprintf(str1,"SELECT PERMISSIONS(OBJECT_ID('TABLE1'))"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); the abopve function returns an integer value.. how do i read the value?? ranjani

      H Offline
      H Offline
      Husein
      wrote on last edited by
      #2

      Use Recordset's Field property and use integer based index (0 in this case) to retrieve the value.

      R 1 Reply Last reply
      0
      • H Husein

        Use Recordset's Field property and use integer based index (0 in this case) to retrieve the value.

        R Offline
        R Offline
        ranjjj
        wrote on last edited by
        #3

        do u eman to say..use pRecordset->Fields()-> .. and what is integer basd index as u have mentioned??? plz reply as soon as poss thank u in advance ranjani

        H 1 Reply Last reply
        0
        • R ranjjj

          do u eman to say..use pRecordset->Fields()-> .. and what is integer basd index as u have mentioned??? plz reply as soon as poss thank u in advance ranjani

          H Offline
          H Offline
          Husein
          wrote on last edited by
          #4

          as far as I remember with ADO you would say: _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value and this would retrieve the value. Item[] can take either integer based index (eg. Item[long(0)]->Value) or string based (eg. Item["SomeColumn"]->Value) I hope this helps. Best regards, Husein

          R 2 Replies Last reply
          0
          • H Husein

            as far as I remember with ADO you would say: _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value and this would retrieve the value. Item[] can take either integer based index (eg. Item[long(0)]->Value) or string based (eg. Item["SomeColumn"]->Value) I hope this helps. Best regards, Husein

            R Offline
            R Offline
            ranjjj
            wrote on last edited by
            #5

            The full code is enclosed herewith!! When I include the aboce said and run it..the control goes to the catch function..as there's some problem in the above mentioned stt! void main(void) { ADODB::_ConnectionPtr m_pConnection = NULL; ADODB::_CommandPtr Cmd1; ADODB::_RecordsetPtr pRecordset = NULL; VARIANT *vRecordsAffected = NULL; char ConStr[500]; char str1[50]; _bstr_t bstrProc =( L"sp_StartByteImport" ); BOOL m_bIsConnectionOpen; // Create an instance of _Connection HRESULT hr ; hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection)); cout << "Connection object created." ; _variant_t vRecsAffected(0L); try { if (SUCCEEDED(hr)) { //Open a connection where database is access database : "c:\\emailparsing\\email_details.mdb" ConStr[0] = '\0'; strcat(ConStr, "Provider=sqloledb;Server=ie10DT2KCO1473;Initial Catalog=Shree;"); strcat(ConStr,"User Id=sa;Password= ;"); /* Provider=Microsoft.Jet.OLEDB.3.51; Data Source="**/ // strcat(ConStr, "C:\\MSSQL7\\Data\\Shree_Data" ); m_pConnection->Open(ConStr, "", "", 0); //If database opened successfully then set IsConnectionOpen to TRUE if (SUCCEEDED(hr)) { m_bIsConnectionOpen = TRUE; } } sprintf(str1,"USE Shree SELECT PERMISSIONS ( OBJECT_ID('TABLE1') )"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value; printf("\n%s\n\n",vtMyVal); ConStr[0] = '\0'; strcat(ConStr, "SELECT * FROM "); strcat(ConStr,"TABLE1"); pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1); if (!pRecordset->GetEOFile()) { int i = 0; while (!pRecordset->GetEOFile()) { printf("row %d is '%s %s'\n",i, (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("id")->GetValue()), (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("product_name")->GetValue())); i++; pRecordset->MoveNext(); } } pRecordset->Close(); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); printf("%s\n%s\n%s\n",(char *) e.ErrorMessage(), (char *)e.Source(), (char *)e.Description()); } ::CoUninitialize(); } ranjani

            H 1 Reply Last reply
            0
            • H Husein

              as far as I remember with ADO you would say: _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value and this would retrieve the value. Item[] can take either integer based index (eg. Item[long(0)]->Value) or string based (eg. Item["SomeColumn"]->Value) I hope this helps. Best regards, Husein

              R Offline
              R Offline
              ranjjj
              wrote on last edited by
              #6

              The full code is enclosed herewith!! When I include the aboce said and run it..the control goes to the catch function..as there's some problem in the above mentioned stt! void main(void) { ADODB::_ConnectionPtr m_pConnection = NULL; ADODB::_CommandPtr Cmd1; ADODB::_RecordsetPtr pRecordset = NULL; VARIANT *vRecordsAffected = NULL; char ConStr[500]; char str1[50]; _bstr_t bstrProc =( L"sp_StartByteImport" ); BOOL m_bIsConnectionOpen; // Create an instance of _Connection HRESULT hr ; hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection)); cout << "Connection object created." ; _variant_t vRecsAffected(0L); try { if (SUCCEEDED(hr)) { //Open a connection where database is access database : "c:\\emailparsing\\email_details.mdb" ConStr[0] = '\0'; strcat(ConStr, "Provider=sqloledb;Server=ie10DT2KCO1473;Initial Catalog=Shree;"); strcat(ConStr,"User Id=sa;Password= ;"); /* Provider=Microsoft.Jet.OLEDB.3.51; Data Source="**/ // strcat(ConStr, "C:\\MSSQL7\\Data\\Shree_Data" ); m_pConnection->Open(ConStr, "", "", 0); //If database opened successfully then set IsConnectionOpen to TRUE if (SUCCEEDED(hr)) { m_bIsConnectionOpen = TRUE; } } sprintf(str1,"USE Shree SELECT PERMISSIONS ( OBJECT_ID('TABLE1') )"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value; printf("\n%s\n\n",vtMyVal); ConStr[0] = '\0'; strcat(ConStr, "SELECT * FROM "); strcat(ConStr,"TABLE1"); pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1); if (!pRecordset->GetEOFile()) { int i = 0; while (!pRecordset->GetEOFile()) { printf("row %d is '%s %s'\n",i, (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("id")->GetValue()), (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("product_name")->GetValue())); i++; pRecordset->MoveNext(); } } pRecordset->Close(); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); printf("%s\n%s\n%s\n",(char *) e.ErrorMessage(), (char *)e.Source(), (char *)e.Description()); } ::CoUninitialize(); } ranjani

              1 Reply Last reply
              0
              • R ranjjj

                The full code is enclosed herewith!! When I include the aboce said and run it..the control goes to the catch function..as there's some problem in the above mentioned stt! void main(void) { ADODB::_ConnectionPtr m_pConnection = NULL; ADODB::_CommandPtr Cmd1; ADODB::_RecordsetPtr pRecordset = NULL; VARIANT *vRecordsAffected = NULL; char ConStr[500]; char str1[50]; _bstr_t bstrProc =( L"sp_StartByteImport" ); BOOL m_bIsConnectionOpen; // Create an instance of _Connection HRESULT hr ; hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection)); cout << "Connection object created." ; _variant_t vRecsAffected(0L); try { if (SUCCEEDED(hr)) { //Open a connection where database is access database : "c:\\emailparsing\\email_details.mdb" ConStr[0] = '\0'; strcat(ConStr, "Provider=sqloledb;Server=ie10DT2KCO1473;Initial Catalog=Shree;"); strcat(ConStr,"User Id=sa;Password= ;"); /* Provider=Microsoft.Jet.OLEDB.3.51; Data Source="**/ // strcat(ConStr, "C:\\MSSQL7\\Data\\Shree_Data" ); m_pConnection->Open(ConStr, "", "", 0); //If database opened successfully then set IsConnectionOpen to TRUE if (SUCCEEDED(hr)) { m_bIsConnectionOpen = TRUE; } } sprintf(str1,"USE Shree SELECT PERMISSIONS ( OBJECT_ID('TABLE1') )"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->Fields->Item[long(0)]->Value; printf("\n%s\n\n",vtMyVal); ConStr[0] = '\0'; strcat(ConStr, "SELECT * FROM "); strcat(ConStr,"TABLE1"); pRecordset = m_pConnection->Execute(ConStr, vRecordsAffected, 1); if (!pRecordset->GetEOFile()) { int i = 0; while (!pRecordset->GetEOFile()) { printf("row %d is '%s %s'\n",i, (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("id")->GetValue()), (char*) ((_bstr_t) pRecordset->GetFields()->GetItem("product_name")->GetValue())); i++; pRecordset->MoveNext(); } } pRecordset->Close(); } catch (_com_error &e) { printf("Description = '%s'\n", (char*) e.Description()); printf("%s\n%s\n%s\n",(char *) e.ErrorMessage(), (char *)e.Source(), (char *)e.Description()); } ::CoUninitialize(); } ranjani

                H Offline
                H Offline
                Husein
                wrote on last edited by
                #7

                The first call in the main(void) should be ::CoInitialize(NULL) This should do the trick.

                R 2 Replies Last reply
                0
                • H Husein

                  The first call in the main(void) should be ::CoInitialize(NULL) This should do the trick.

                  R Offline
                  R Offline
                  ranjjj
                  wrote on last edited by
                  #8

                  yes i got the answer by ur answer... now..can u help me out with sql databse stuffs?? coz'' the return value..that is the integer value i get indicates some permissions assigned to teh user.. how do i check it? ranjani

                  1 Reply Last reply
                  0
                  • H Husein

                    The first call in the main(void) should be ::CoInitialize(NULL) This should do the trick.

                    R Offline
                    R Offline
                    ranjjj
                    wrote on last edited by
                    #9

                    how do i create a stored procedure in C++? my program should for any of the sql servers.. so..manually creating a stored procedure won't work.. so.. i have to create it programatically...how do i go abt doing it? ranjani

                    H 1 Reply Last reply
                    0
                    • R ranjjj

                      how do i create a stored procedure in C++? my program should for any of the sql servers.. so..manually creating a stored procedure won't work.. so.. i have to create it programatically...how do i go abt doing it? ranjani

                      H Offline
                      H Offline
                      Husein
                      wrote on last edited by
                      #10

                      Add a new _bstr_t variable and set it's value to "CREATE PROCEDURE ... " and then pass this variable as a parameter to connection's execute method. That could be one way of doing things. Best regards, Husein

                      R 2 Replies Last reply
                      0
                      • H Husein

                        Add a new _bstr_t variable and set it's value to "CREATE PROCEDURE ... " and then pass this variable as a parameter to connection's execute method. That could be one way of doing things. Best regards, Husein

                        R Offline
                        R Offline
                        ranjjj
                        wrote on last edited by
                        #11

                        AND AFTER DOING THAT.. GET THE RETURN VALUE..AS SAID ABOVE FOR PERMISSIOSN STT IS IT?? ranjani

                        1 Reply Last reply
                        0
                        • H Husein

                          Add a new _bstr_t variable and set it's value to "CREATE PROCEDURE ... " and then pass this variable as a parameter to connection's execute method. That could be one way of doing things. Best regards, Husein

                          R Offline
                          R Offline
                          ranjjj
                          wrote on last edited by
                          #12

                          iam able to create the stored procedure.. but how do i go about... rading the return value.. that is my code is now like.. _bstr_t bstrPr = "DROP PROCEDURE bali" ; pRecordset = m_pConnection->Execute(bstrPr, vRecordsAffected, 1); _bstr_t bstrp = "CREATE PROCEDURE bali @ioparm int OUTPUT AS \nIF PERMISSIONS()&2=0x2 RETURN 1 ELSE RETURN 0"; pRecordset = m_pConnection->Execute(bstrp, vRecordsAffected, 1); _bstr_t exect = "EXECUTE bali 2"; pRecordset = m_pConnection->Execute(exect,vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->GetFields()->Item[long(0)]->Value; printf("\n%d\n",(char *)(_bstr_t)vtMyVal); Iam not able tor ead the return value from this but.. what mite be the reason for this? what else shud i add to get it done?? also.. initially.. how do i cehk if a procedure name with the name specified already exists?? ranjani

                          H 1 Reply Last reply
                          0
                          • R ranjjj

                            iam able to create the stored procedure.. but how do i go about... rading the return value.. that is my code is now like.. _bstr_t bstrPr = "DROP PROCEDURE bali" ; pRecordset = m_pConnection->Execute(bstrPr, vRecordsAffected, 1); _bstr_t bstrp = "CREATE PROCEDURE bali @ioparm int OUTPUT AS \nIF PERMISSIONS()&2=0x2 RETURN 1 ELSE RETURN 0"; pRecordset = m_pConnection->Execute(bstrp, vRecordsAffected, 1); _bstr_t exect = "EXECUTE bali 2"; pRecordset = m_pConnection->Execute(exect,vRecordsAffected, 1); _variant_t vtMyVal; vtMyVal = pRecordset->GetFields()->Item[long(0)]->Value; printf("\n%d\n",(char *)(_bstr_t)vtMyVal); Iam not able tor ead the return value from this but.. what mite be the reason for this? what else shud i add to get it done?? also.. initially.. how do i cehk if a procedure name with the name specified already exists?? ranjani

                            H Offline
                            H Offline
                            Husein
                            wrote on last edited by
                            #13

                            ranjjj, how well do you know ADO programming with VC++? In order to get the RETURN_VALUE from the stored procedure, you need to execute it from the recordset and not from the connection. In you recordset object you need to set certain properties, like CommandType and CommandText. If you programmed ADO with VB, it is the same thing with VC++. regards, Husein

                            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