Funkcja usuwa użytkownika bazy MS-SQL, zwraca true/false w przypadku powodzenia/porażki.
function BOOL DB_DropUser(sUserToDrop, sServerName, sDBName, sDriver, bTrustedConn,
sUserName, sUserPwd, bLog)
OBJECT objConn, objRST;
STRING sConnString;
STRING szADOConnObjID, sSQL;
BOOL bResult;
begin
bResult = FALSE;
if (sDriver == "") then
sConnString = "Provider=sqloledb;";
else
sConnString = "Driver={" + sDriver + "};";
endif;
if (bTrustedConn) then
sConnString = sConnString + "server=" + sServerName + ";";
sConnString = sConnString + "database=" + sDBName + ";";
sConnString = sConnString + "Trusted_connection=Yes";
else
sConnString = sConnString + "server=" + sServerName + ";";
sConnString = sConnString + "uid=" + sUserName + ";";
sConnString = sConnString + "pwd=" + sUserPwd + ";";
sConnString = sConnString + "database=" + sDBName;
endif;
try
szADOConnObjID = "ADODB.Connection";
set objConn = CreateObject(szADOConnObjID);
if (IsObject(objConn)) then
objConn.ConnectionString = sConnString;
objConn.Open;
sSQL = "IF EXISTS (SELECT * FROM sysusers WHERE name='"+sUserToDrop+"')
BEGIN EXEC dbo.sp_revokedbaccess N'"+sUserToDrop+"' END;";
try
set objRST = objConn.Execute(sSQL);
bResult = TRUE; //Wykonano
catch
bResult = FALSE; //Błąd wykonania
if (bLog) then WriteLog(1," - błąd usuwania loginu \""+sUserToDrop+"\"
z bazy \""+sDBName+"\""); endif;
endcatch;
objConn.Close;
endif;
set objConn = NOTHING;
set objRST = NOTHING;
catch
if (bLog) then WriteLog(1," - Nie można uzyskać połączenia z bazą
na użytkownika \""+sUserName+"\""); endif;
endcatch;
return bResult;
end;
Brak komentarzy:
Prześlij komentarz