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 plus sql database

ADO plus sql database

Scheduled Pinned Locked Moved Database
databasequestionsysadminhelp
5 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

    I have to get the user's acces permission for a specified database! For that I use the command...PERMISSIONS() I use ADO for establishing a connection to the database..my code is something like this now.. void main(void) { ADODB::_ConnectionPtr m_pConnection = NULL; ADODB::_RecordsetPtr pRecordset = NULL; VARIANT *vRecordsAffected = NULL; char ConStr[500]; char str1[50]; BOOL m_bIsConnectionOpen; // Create an instance of _Connection HRESULT hr ; hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection)); try { if (SUCCEEDED(hr)) { //Open a connectionConStr[0] = '\0'; strcat(ConStr, "Provider=sqloledb;Server=ie10DT2KCO1473;Initial Catalog=Shree;"); strcat(ConStr,"User Id=sa;Password= ;"); m_pConnection->Open(ConStr, "", "", 0); //If database opened successfully then set IsConnectionOpen to TRUE if (SUCCEEDED(hr)) m_bIsConnectionOpen = TRUE; } /* sprintf(str1,"PERMISSIONS ( OBJECT_ID('TABLE1') )"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); } .. and then the catch function ! Now.. How do i display the return value of the PERMISSIONS function?? kindly help me in this regard!! ranjani

    H 1 Reply Last reply
    0
    • R ranjjj

      I have to get the user's acces permission for a specified database! For that I use the command...PERMISSIONS() I use ADO for establishing a connection to the database..my code is something like this now.. void main(void) { ADODB::_ConnectionPtr m_pConnection = NULL; ADODB::_RecordsetPtr pRecordset = NULL; VARIANT *vRecordsAffected = NULL; char ConStr[500]; char str1[50]; BOOL m_bIsConnectionOpen; // Create an instance of _Connection HRESULT hr ; hr = m_pConnection.CreateInstance(__uuidof(ADODB::Connection)); try { if (SUCCEEDED(hr)) { //Open a connectionConStr[0] = '\0'; strcat(ConStr, "Provider=sqloledb;Server=ie10DT2KCO1473;Initial Catalog=Shree;"); strcat(ConStr,"User Id=sa;Password= ;"); m_pConnection->Open(ConStr, "", "", 0); //If database opened successfully then set IsConnectionOpen to TRUE if (SUCCEEDED(hr)) m_bIsConnectionOpen = TRUE; } /* sprintf(str1,"PERMISSIONS ( OBJECT_ID('TABLE1') )"); pRecordset = m_pConnection->Execute(str1, vRecordsAffected, 1); } .. and then the catch function ! Now.. How do i display the return value of the PERMISSIONS function?? kindly help me in this regard!! ranjani

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

      I was playing with this right now and in SQL Query Analyzer I had to use it like this (This is from Northwind): USE Northwind GO SELECT PERMISSIONS(OBJECT_ID('Customers')) This would return a value of 1881108543. This means that in your code you forgot to add SELECT before PERMISSIONS funtion in order to get the result back. Now you have to AND this value with certain other values in order to get the appropriate permission level. For this and the AND values, check the PERMISSIONS function in SQL Books On-Line. Regards, Husein

      R 1 Reply Last reply
      0
      • H Husein

        I was playing with this right now and in SQL Query Analyzer I had to use it like this (This is from Northwind): USE Northwind GO SELECT PERMISSIONS(OBJECT_ID('Customers')) This would return a value of 1881108543. This means that in your code you forgot to add SELECT before PERMISSIONS funtion in order to get the result back. Now you have to AND this value with certain other values in order to get the appropriate permission level. For this and the AND values, check the PERMISSIONS function in SQL Books On-Line. Regards, Husein

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

        AND which value with what. my question is... how do i get the integer value from it... when i run the folllowing in query analyzer i get the proper result..i have to do the same in..c++ ,,how do i do it? USE pubs IF PERMISSIONS()&2=0x2 PRINT 'The current user can create a table.' ELSE PRINT 'The current user cannot create a table.' thanxxxx ranjani

        H 1 Reply Last reply
        0
        • R ranjjj

          AND which value with what. my question is... how do i get the integer value from it... when i run the folllowing in query analyzer i get the proper result..i have to do the same in..c++ ,,how do i do it? USE pubs IF PERMISSIONS()&2=0x2 PRINT 'The current user can create a table.' ELSE PRINT 'The current user cannot create a table.' thanxxxx ranjani

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

          PERMISSIONS function takes two optional parameters. PERMISSIONS ( [ objectid [ , 'column' ] ] ) If you specify PERMISSIONS, as in the sample you provided in the previous message, you want to know if the user has certain statement permission. These include CREATE DATABASE (master db only), CREATE TABLE, etc. Their permissions are like this: Bit Statement 0x1 CREATE DATABASE 0x2 CREATE TABLEetc etc If you specify PERMISSIONS(objectid), then you want to know if the user can perform certain operation on the object, like SELECT, INSERT, DELETE, UPDATE, etc. Again the bits are the same as above 0x1 for SELECT ALL, 0x2 UPDTE ALL, etc. If you also specify column name with objectid, you are checking if the user can SELECT, UPDATE or reference a certain column. You should first figure out what is it that you want to check. That is, first determine what kind of permission you want to check for your user. After that build the query in the SQL Query Analyser, and if everything works fine, create a stored procedure that does the calculation and returns a scalar value. I hope this solves your problem. For more information, check Books On-Line to see the list of the bits used with PERMISSIONS function. Have fun, Husein

          R 1 Reply Last reply
          0
          • H Husein

            PERMISSIONS function takes two optional parameters. PERMISSIONS ( [ objectid [ , 'column' ] ] ) If you specify PERMISSIONS, as in the sample you provided in the previous message, you want to know if the user has certain statement permission. These include CREATE DATABASE (master db only), CREATE TABLE, etc. Their permissions are like this: Bit Statement 0x1 CREATE DATABASE 0x2 CREATE TABLEetc etc If you specify PERMISSIONS(objectid), then you want to know if the user can perform certain operation on the object, like SELECT, INSERT, DELETE, UPDATE, etc. Again the bits are the same as above 0x1 for SELECT ALL, 0x2 UPDTE ALL, etc. If you also specify column name with objectid, you are checking if the user can SELECT, UPDATE or reference a certain column. You should first figure out what is it that you want to check. That is, first determine what kind of permission you want to check for your user. After that build the query in the SQL Query Analyser, and if everything works fine, create a stored procedure that does the calculation and returns a scalar value. I hope this solves your problem. For more information, check Books On-Line to see the list of the bits used with PERMISSIONS function. Have fun, Husein

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

            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

            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