Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Firebird e Interbase (https://www.clubdelphi.com/foros/forumdisplay.php?f=19)
-   -   Problemas al crear un usuario en Firebird (https://www.clubdelphi.com/foros/showthread.php?t=27359)

Jesús Pena 18-11-2005 11:28:31

Problemas al crear un usuario en Firebird
 
Utilizo Delphi 2005 y Firebird 1.5 y al intentar dar de alta un usuario a la base de datos me aparece el siguiente mensaje de error

Project xxxxxxxxxxxxxxxx.exe raised exception class EibInterbaseError with message 'attempt to store duplicate value (visible to active transactions) in
unique index "USER_NAME_INDEX"' (donde xxxxxxxxxxxxxxxx.exe es mi projecto).

Utilizo los Servicios de Interbase (AddUser).

El problema me surge en un proceso de mantenimiento de usuarios y permisos de acceso a ciertas partes del proyecto. Creo un usuario, lo elimino y lo vuelvo a crear y es cuando salta el error en cuestión.

Espero que alguno de vosotros me pueda ayudar con el tema

Al González 21-11-2005 02:11:08

¡Hola a todos!

Tal parece que el usuario que mencionas no está siendo eliminado. Por lo tanto, al intentar crearlo de nuevo, se genera el error indicado.

¿Podrías detallarnos el proceso de eliminación que utilizas?

Un abrazo único.

Al González. :)

Jesús Pena 21-11-2005 10:13:57

Las Rutinas que utilizo son las siguientes
 
{------------------------ Creación-Modificación --------------------------------
Creación: 29/07/2005 Por: Jesús Pena Iglesias
Modificada:
------------------------------- Parámetros ------------------------------------
Entrada:
Salida:
--------------------------------Propósito---------------------------------------
* Aceptamos los datos
-------------------------------------------------------------------------------}
Código Delphi [-]
procedure TfrmUsuarios.bbAceptarClick(Sender: TObject);
begin
inherited;
if dsPrincipal.State = dsEdit then
begin
with dmUsuarios.IBSecurityService1 do
begin
FirstName := DBENombre.Text;
LastName := DBeApellido2.text;
MiddleName := DBEApellido1.Text;
UserName := dbeUsuario.Text;
Password := DBEPassword.Text;
Protocol := Local;
If RadioGroup1.ItemIndex = 1 then
begin
Protocol := TCP;
ServerName := eServidor.Text;
end;
try
Active := True;
ModifyUser;
Active := False;
except
on E: EIBInterbaseError do
raise Exception.Create('Error Modificando el Usuario de la base de datos del Sistema'+#13+'Error ');
end;
end;
dmUsuarios.EstablecerPermisos(dbeUsuario.Text);
// DataSetPost2.Execute;
end;
if dsPrincipal.State = dsInsert then
begin
with dmUsuarios.IBSecurityService1 do
begin
FirstName := DBENombre.Text;
LastName := DBeApellido2.text;
MiddleName := DBEApellido1.Text;
UserName := dbeUsuario.Text;
Password := DBEPassword.text;
Protocol := Local;
If RadioGroup1.ItemIndex = 1 then
begin
Protocol := TCP;
ServerName := eServidor.Text;
end;
try
Active := True;
AddUser;
Active := False;
except
on E: EIBInterbaseError do
raise Exception.Create('Error Creando el Usuario de la base de datos del Sistema'+#13+'Error ');
end;
end;
dmUsuarios.EstablecerPermisos(dbeUsuario.Text);
end;
DataSetPost2.Execute;
end;
{------------------------ Creación-Modificación --------------------------------
Creación: 29/07/2005 Por: Jesús Pena Iglesias
Modificada:
------------------------------- Parámetros ------------------------------------
Entrada:
Salida:
--------------------------------Propósito---------------------------------------
* Realizamos los procesos vinculados al borrado de un usuario
-------------------------------------------------------------------------------}
procedure TfrmUsuarios.tbBorrarClick(Sender: TObject);
begin
with dmUsuarios.IBSecurityService1 do
begin
FirstName := dmUsuarios.IBTUsuarios.FieldByName('Nombre').AsString;
LastName := dmUsuarios.IBTUsuarios.FieldbyName('APELLIDO2').AsString;
MiddleName := dmUsuarios.IBTUsuarios.FieldByName('APELLIDO1').AsString;
UserName := dmUsuarios.IBTUsuarios.FieldByName('USUARIO').AsString;;
Password := password;
If RadioGroup1.ItemIndex = 0 then
Protocol := Local
else
begin
Protocol := TCP;
ServerName := eServidor.Text;
end;
try
Active := True;
DeleteUser;
Active := False;
dmUsuarios.QuitarTodosPermisos(dmUsuarios.IBSecurityService1.UserName);
except
MessageBox(0, 'Error Borrando el Usuario de la base de datos del Sistema', 'Error', MB_ICONERROR or MB_OK);
end;
end;
inherited;
 
end;
 
Las rutinas EstablecerPermisos y QuitarTodosPermisos 
procedure TdmUsuarios.EstablecerPermisos(pUsuario: String);
var
i:Integer;
begin
with IBQPermisos do
begin
Sql.Clear;
sql.Add('GRANT xxxx TO ' + pUsuario); {Establecer permisos del Roll al usuario}
Prepare;
ExecSQL;
end;
with IBQDBOjects do
begin
If Active then Close;
Open;
First;
while not eof do
begin
with IBQPermisos do
begin
with Sql do
begin
Clear;
Add('GRANT ALL ON ' + IBQDBOjects.FieldByName('OBJETO').AsString + ' TO '+ pUsuario + ' WITH GRANT OPTION');
Prepare;
ExecSQL;
end;
end;
Next;
end;
If IBTUsuarios.FieldByName('VIAJES').AsInteger <> 1 then
begin
Sql.Clear;
sql.Add('REVOKE INSERT, UPDATE, DELETE ON DESTINOS FROM ' + pUsuario);
Prepare;
ExecSQL;
end;{If IBTUsuarios.FieldByName('VIAJES').AsInteger <> 1 then}
If IBTUsuarios.FieldByName('RUTAS').AsInteger <> 1 then
begin
Sql.Clear;
sql.Add('REVOKE INSERT, UPDATE, DELETE ON DESTINOS_VIAJES FROM ' + pUsuario);
Prepare;
ExecSQL;
Sql.Clear;
sql.Add('REVOKE INSERT, UPDATE, DELETE ON DESTINOS_VIAJES_PROGRAM FROM ' + pUsuario);
Prepare;
ExecSQL;
end; {If IBTUsuarios.FieldByName('RUTAS').AsInteger <> 1 then}
If iBTUsuarios.FieldByName('ZONAS').AsInteger <> 1 then
begin
Sql.Clear;
sql.Add('REVOKE INSERT, UPDATE, DELETE ON ZONAS FROM ' + pUsuario);
Prepare;
ExecSQL;
end;{If iBTUsuarios.FieldByName('ZONAS').AsInteger <> 1 then}
end;
end;
procedure TdmUsuarios.QuitarTodosPermisos(pUsuario: String);
begin
with IBQDBOjects do
begin
If Active then Close;
Open;
First;
while not eof do
begin
with IBQPermisos do
begin
with Sql do
begin
Clear;
Add('REVOKE ALL ON ' + IBQDBOjects.FieldByName('OBJETO').AsString + ' FROM '+ pUsuario + ' WITH GRANT OPTION');
Prepare;
ExecSQL;
end;
end;
Next;
end;
with IBQPermisos do
begin
Sql.Clear;
sql.Add('REVOKE xxxx FROM ' + pUsuario);{Eliminar los permisos del Roll al usuario}
Prepare;
ExecSQL;
end;
end;
end;


La franja horaria es GMT +2. Ahora son las 00:33:49.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi