Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to add user to sql server 2005 express programatically


How to add user to sql server 2005 express programatically

Author
Message
niteshrajgopal
niteshrajgopal
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 336
Hi again,

I've added the followinbg to my script

USE [master]

IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE [name] = 'Reality')
BEGIN
-- Create user for SQL Authentication
CREATE LOGIN Reality WITH PASSWORD = 'Games12er' ,DEFAULT_DATABASE = [Games]

-- Add User to first database

USE Games;

CREATE USER Reality FOR LOGIN Reality;

EXEC sp_addrolemember 'db_datareader', 'Reality'

EXEC sp_addrolemember 'db_datawriter', 'Reality'

END



I figured it is easier to use sql authentication. Please advise me if this is correct. it seems to have worked on my pc. still have to test on a users pc
Sudeepta
Sudeepta
SSC-Enthusiastic
SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)SSC-Enthusiastic (188 reputation)

Group: General Forum Members
Points: 188 Visits: 189
It is correct.

Thanks & Regards,
Sudeepta.
http://twitter.com/skganguly
niteshrajgopal
niteshrajgopal
Valued Member
Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)Valued Member (55 reputation)

Group: General Forum Members
Points: 55 Visits: 336
thanks for all your help. I've learnt alot from you;-)
phil 78969
phil 78969
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 3
(edit)sorry posted reply to wrong thread.
developer 34412
developer 34412
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 2
Hey thanks for that, have been trawling for ages to find this code. Very useful. :-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search