Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / General / Security / September 2006

Tip: Looking for answers? Try searching our database.

Login/User modification from an application?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg P. - 25 Sep 2006 21:31 GMT
I have an application and I want to add/edit/del Logins and Users in Sql
Server 2005 through the application, can I do it?  I am using windows
authentication.  Currently I call a stored proc that I try to pass a login
and it doesn't work.  For example this is my Delete.

ALTER PROCEDURE [dbo].[usp_UserRoleDelete]
    -- Add the parameters for the stored procedure here
    @LoginName nvarchar(50)
AS
BEGIN

    SET NOCOUNT ON;
    Begin
        --Drop the login which drops the user?
        Drop Login [@LoginName]

    End
END

When it runs I get you can't add a login called @LoginName.  If I take the
brackets off it will not compile.  Can i do what I'm trying to do?  I've also
tried using sp_DropLogin w/o success.  I did see somewhere in documentation
for the sp_dropLogin "sp_droplogin cannot be executed within a user-defined
transaction."  There is nothing about the in the Drop Login documentation.  
Is this the problem?

Thanks in advance,
Greg P.
Greg P. - 25 Sep 2006 21:39 GMT
Just to follow up, mainly what I'm trying to do is used passed parameters in
my add/alter/drop statements.  Is there a way to have the @LoginName
evaluated before the the whole line is evaluated?

> I have an application and I want to add/edit/del Logins and Users in Sql
> Server 2005 through the application, can I do it?  I am using windows
[quoted text clipped - 24 lines]
> Thanks in advance,
> Greg P.
Sue Hoegemeier - 25 Sep 2006 23:19 GMT
No...it's because DROP LOGIN itself doesn't accept
parameters and that's what you are asking it to do. You
would need to use dynamic SQL but you really would want to
read the following first:
http://www.sommarskog.se/dynamic_sql.html

So for the stored procedure you posted to work, one option
would be to dynamically build the statement and pass it into
an EXEC.
So instead of the line:
Drop Login [@LoginName]
you would use something like:
EXEC('DROP LOGIN ' + @LoginName)

-Sue

>I have an application and I want to add/edit/del Logins and Users in Sql
>Server 2005 through the application, can I do it?  I am using windows
[quoted text clipped - 24 lines]
>Thanks in advance,
>Greg P.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.