ADO plus sql database
-
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
-
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
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 of1881108543
. 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 -
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 of1881108543
. 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, HuseinAND 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
-
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
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 includeCREATE DATABASE
(master db only),CREATE TABLE
, etc. Their permissions are like this: Bit Statement0x1 CREATE DATABASE 0x2 CREATE TABLE
etc etc If you specifyPERMISSIONS(objectid)
, then you want to know if the user can perform certain operation on the object, likeSELECT, 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 -
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 includeCREATE DATABASE
(master db only),CREATE TABLE
, etc. Their permissions are like this: Bit Statement0x1 CREATE DATABASE 0x2 CREATE TABLE
etc etc If you specifyPERMISSIONS(objectid)
, then you want to know if the user can perform certain operation on the object, likeSELECT, 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