Page 1 of 1

NEWBIE - Checking for existance of a SQL user

Posted: Wed 06 Jul 2016 08:38
by Jerbear
Hi Guys.
Now go easy on me...I'm new to all this...hope I'm explaining this right....
I want my Delphi App to check for a user, if not found add that user complete with security dbRoles.

I want my Delphi App to check SQL Server Security DB for the existance of a user which I can do, however, how do i get this info back into Delphi so that I can act on it.

var NoUserExists : boolean;
Query.SQL.Clear;
Query.SQL.Add('IF SUSER_ID('''+thisuser+''') IS NULL) ; // can't do anything else here until executed...
RoleQuery.Execute;

Re: NEWBIE - Checking for existance of a SQL user

Posted: Wed 06 Jul 2016 11:48
by ViktorV
To resolve the task, you can use the following code:

Code: Select all

var NoUserExists: boolean;
...
  Query.SQL.Clear;
  Query.SQL.Text('IF SUSER_ID(''' + thisuser + ''') IS NULL SELECT ''True'' ELSE SELECT ''False''') ;
  Query.Open;
  NoUserExists := Query.Fields[0].AsBoolean;
  if NoUserExists then
    RoleQuery.Execute;

Re: NEWBIE - Checking for existance of a SQL user

Posted: Wed 06 Jul 2016 12:24
by Jerbear
Many thanks ViktorV.
Wasn't expecting such a quick response....

Re: NEWBIE - Checking for existance of a SQL user

Posted: Wed 06 Jul 2016 12:55
by ViktorV
Thank you for your interest to our products.
If you have any other questions, feel free to contact us.