Re: Finding out if a login exists

From: alien2_51 (dan.billow"at"n.o.s.p.a.m.monacocoach.commercialversion)
Date: 09/22/04


Date: Wed, 22 Sep 2004 11:05:00 -0700

if not exists (select * from master.dbo.syslogins where loginname =
N'AppLinkUser')
BEGIN
 declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb =
N'Intergy', @loginlang = N'us_english'
 if @logindb is null or not exists (select * from master.dbo.sysdatabases
where name = @logindb)
  select @logindb = N'master'
 if @loginlang is null or (not exists (select * from master.dbo.syslanguages
where name = @loginlang) and @loginlang <> N'us_english')
  select @loginlang = @@language
 exec sp_addlogin N'AppLinkUser', null, @logindb, @loginlang
END
GO

You can generate this code from All Tasks>Generate SQL option option in EM,
look at options and select script logins...

"Carlos Galavis" <cgalavis> wrote in message
news:uOE1RtMoEHA.3488@TK2MSFTNGP12.phx.gbl...
> Hi,
> I need to write a SQL script to create a login in SQLServer and assigned
> some permissions to certain tables. I am using then "sp_grantlogin" stored
> procedure to create the login, but if the login happens to exist, the
script
> fails with an error. I need to be able to determine if the login already
> exists and call this stored procedure only in the cases in which it
doesn't.
>
> Thanks,
>
> -Carlos
>
>



Relevant Pages

  • Re: Permission question - another one
    ... If I add an Sql Login it does add the TRAVAC\ in front of the names, ... seems to be users that were setup to use SQL Server Authentication. ... RAPTOR is the Server that has SQL Server running on it. ... > " I could think I am taking permissions away from someone, ...
    (microsoft.public.sqlserver.programming)
  • Re: Renamed Windows login not found in SQL Server 2000
    ... It's almost like SQL tuck some knowledge away in an area ... of memory that only gets released on Windows stop. ... > I am running SQL Server 2000 SP2 with Windows ... > login gets corrupted) I am unable to add the new login to ...
    (microsoft.public.sqlserver.security)
  • Re: SQL Server on XP Home Network
    ... The sa account is the system administrator "God" account witihin SQL ... This account is a SQL-Server login. ... You might be able to use Enterprise Manager to go in and create a new SQL ... Select the "SQL Server Authentication" ...
    (microsoft.public.sqlserver.setup)
  • RE: Getting Challenged when using SQL connection on .aspx page
    ... What would happen if i removed integrated security=sspi from the connection ... Just want the login token to be passed, ... Have webpage with following connection in the ... I have account to the database on the SQL server. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Logging in irrespective of database access
    ... My problem is that in the Login section of Enterprise Manger I have to ... like there used to be in SQL 6.5. ... What's the point in having the Database Access section if the System Admin ... SQL Server MVP ...
    (microsoft.public.sqlserver.programming)