[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sp_grantlogin Error Hanlde When NT username not valid

Posted on 2004-11-27
1
Medium Priority
?
454 Views
Last Modified: 2008-02-01
Hi,
If I'm creating (sp) that Adding NT user to the Data base I should do like this:

exec sp_grantlogin 'Servername\username'

But suppose the user name is not inside the NT security names then the following error will be displayed :

MSG 15401 : Windows NT user or group 'Servername\username' not found check the name again.

How I can handle this error when The User name is not found in the NT security users , I mean if I do like this :

exec sp_grantlogin 'Servername\username'
if @@error <> 0
 do...
else
 do...

I did it like this but it didn't works , any body can help me how to handle it?
Thanks
0
Comment
Question by:mubama0n
1 Comment
 
LVL 16

Accepted Solution

by:
muzzy2003 earned 1000 total points
ID: 12685762
sp_grantlogin returns 0 for success or 1 for failure. You could try this:

DECLARE @rc int

EXEC @rc = sp_grantlogin 'Servername\username'
IF @rc = 0 -- success
  do...
ELSE -- failure
  do...
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question