NEWBIE - Checking for existance of a SQL user

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Jerbear
Posts: 13
Joined: Sun 02 Nov 2008 10:33
Location: Ireland

NEWBIE - Checking for existance of a SQL user

Post by Jerbear » Wed 06 Jul 2016 08:38

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;

ViktorV
Devart Team
Posts: 2299
Joined: Wed 30 Jul 2014 07:16

Re: NEWBIE - Checking for existance of a SQL user

Post by ViktorV » Wed 06 Jul 2016 11:48

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;

Jerbear
Posts: 13
Joined: Sun 02 Nov 2008 10:33
Location: Ireland

Re: NEWBIE - Checking for existance of a SQL user

Post by Jerbear » Wed 06 Jul 2016 12:24

Many thanks ViktorV.
Wasn't expecting such a quick response....

ViktorV
Devart Team
Posts: 2299
Joined: Wed 30 Jul 2014 07:16

Re: NEWBIE - Checking for existance of a SQL user

Post by ViktorV » Wed 06 Jul 2016 12:55

Thank you for your interest to our products.
If you have any other questions, feel free to contact us.

Post Reply