Click here to Skip to main content
15,070,974 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,i want using linq in c# and use Create_New_User(my username,my password)
to add new login
when i running following code creat new login by @NewUserName and 123 password.
i want create login by my input parameters.
how do this?
SQL
ALTER PROCEDURE [dbo].[Create_New_User]
(
@NewUserName VARCHAR(32),
@NewPassword NVARCHAR(8)
)

AS

SET NOCOUNT ON
CREATE LOGIN [@NewUserName] WITH PASSWORD ='123',
DEFAULT_DATABASE=[Kansar],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=OFF
Posted
Updated 2-Aug-12 21:12pm
v2

You call the proc and pass in the parameters you want. Change the proc to USE the new password you pass in instead of 123, of course.

You're doing this in SQL Server or in code ?
   
Comments
Hekmat90 3-Aug-12 3:26am
   
in Code
Hekmat90 3-Aug-12 3:30am
   
When i use CREATE LOGIN [@NewUserName] WITH PASSWORD = @NewPassword,
Incorrect syntax near '@NewPassword'
appear
Christian Graus 3-Aug-12 3:36am
   
Perhaps you can't do it. Perhaps you have to string mash SQL and call Exec on it.
SQL
declare @userid varchar(50)='santhosh'
declare @password varchar(50)='kumartest123'

exec sp_addlogin @loginame = @userid,
		@passwd = @password,
		@defdb = 'Santhosh',
		@deflanguage = [British],
		@sid = null,		
		@encryptopt= null
   
SQL
Alter procedure sp_CreateLogin
      @name varchar(256),
      @password varchar(128)
as
   declare @sqlcmd varchar(2000);

   begin tran;
 

   set @sqlcmd = 'create login ' + quotename(@name) + '  with password = ' + quotename(@password, ''',check_policy=OFF');
   exec (@sqlcmd);
   if @@error <> 0
   begin
      rollback tran;
      print 'Cannot create login'
      return;
   end  
  
   commit tran;
go

exec sp_CreateLogin 'santhosh','kumar1222'
   
Comments
Hekmat90 3-Aug-12 3:39am
   
Thank you Very Very Very Much!
Santhosh Kumar Jayaraman 3-Aug-12 4:31am
   
welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900