Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

How to add user to sql server 2005 express programatically Expand / Collapse
Author
Message
Posted Thursday, August 5, 2010 7:13 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, August 2, 2012 12:36 AM
Points: 54, Visits: 327
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
Post #964231
Posted Thursday, August 5, 2010 7:47 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, November 27, 2013 12:34 AM
Points: 188, Visits: 189
It is correct.

Thanks & Regards,
Sudeepta.
http://twitter.com/skganguly
Post #964268
Posted Thursday, August 5, 2010 7:55 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, August 2, 2012 12:36 AM
Points: 54, Visits: 327
thanks for all your help. I've learnt alot from you
Post #964275
Posted Wednesday, August 18, 2010 6:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, August 20, 2010 4:07 AM
Points: 3, Visits: 3
(edit)sorry posted reply to wrong thread.
Post #971082
Posted Saturday, March 2, 2013 6:22 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, March 2, 2013 10:21 PM
Points: 1, Visits: 2
Hey thanks for that, have been trawling for ages to find this code. Very useful.
Post #1425909
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse