﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server Express  / How to add user to sql server 2005 express programatically / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 05:10:23 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>Hey thanks for that, have been trawling for ages to find this code. Very useful. :-)</description><pubDate>Sat, 02 Mar 2013 18:22:13 GMT</pubDate><dc:creator>developer 34412</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>(edit)sorry posted reply to wrong thread.</description><pubDate>Wed, 18 Aug 2010 06:47:18 GMT</pubDate><dc:creator>phil 78969</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>thanks for all your help. I've learnt alot from you;-)</description><pubDate>Thu, 05 Aug 2010 07:55:34 GMT</pubDate><dc:creator>niteshrajgopal</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>It is correct.</description><pubDate>Thu, 05 Aug 2010 07:47:14 GMT</pubDate><dc:creator>Sudeepta</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>Hi again,I've added the followinbg to my script[code="sql"]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[/code]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</description><pubDate>Thu, 05 Aug 2010 07:13:42 GMT</pubDate><dc:creator>niteshrajgopal</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>[quote]Is there anyway to get the account info of the user logged into windows in sql server?[/quote]You can not logged in to SQL Server, until you have a vaild login for the SQL Server instance. An user logged in to the Windows machine(using his Windows Login account), needs to have his windows login added to the SQL server before he can access the SQL instance. Is that what you are asking.Sorry, if I didn't understand your requirement.</description><pubDate>Thu, 05 Aug 2010 05:32:12 GMT</pubDate><dc:creator>Sudeepta</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>sorry but i'm a bit lost. Is there anyway to get the account info of the user logged into windows in sql server?Maybe I should tackle this differently. What do you think is an easire way to get around my problem</description><pubDate>Thu, 05 Aug 2010 05:20:30 GMT</pubDate><dc:creator>niteshrajgopal</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>If the Windows account is already exist on your system, then you can use the above script to add it to SQL Server, and assign the required permissions.</description><pubDate>Thu, 05 Aug 2010 04:52:27 GMT</pubDate><dc:creator>Sudeepta</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>Hi again,if I remember correctly there is a check box that asks if you want to add the user to logins as they are not added by default.Thing is i'm using a vb.net class to do the install so I have to set the login in my script.</description><pubDate>Thu, 05 Aug 2010 04:45:03 GMT</pubDate><dc:creator>niteshrajgopal</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>[quote][b]niteshrajgopal (8/5/2010)[/b][hr]say my PC Name is NITESH-PC. When I installed sql express it added NITESH-PC\NITESH to the logins. [/quote]It means you logged on to your PC with the user account NITESH. during the installation, you have added this account to the SQL Server Login.[quote]so if I was installing on a PC called TEST-PC with user TEST I would want to create a login in sql server as TEST-PC\TEST. is this possible?[/quote] Yes, you can add the account with the above script. However, if I remember correctly, the account using which you are installing the SQL Server 2005 Express edition, should be added as a login for the SQL instance.</description><pubDate>Thu, 05 Aug 2010 04:29:43 GMT</pubDate><dc:creator>Sudeepta</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>say my PC Name is NITESH-PC. When I installed sql express it added NITESH-PC\NITESH to the logins.I need to create a login for the user that is installing sql server. so if I was installing on a PC called TEST-PC with user TEST I would want to create a login in sql server as TEST-PC\TEST. is this possible?</description><pubDate>Thu, 05 Aug 2010 04:18:59 GMT</pubDate><dc:creator>niteshrajgopal</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>You can not create a Windows Login account using the above script. You need to create the Windows Account using Computer Management (Start --&amp;gt; Run --&amp;gt; Compmgmt.msc). Expand Users &amp; Computers, Clilck on User, Right click and create User, say you created a user named 'User1'.Then you can execute the above script, by replacing the login and user name as [test-pc\User1]Hope, this may help.</description><pubDate>Thu, 05 Aug 2010 03:59:10 GMT</pubDate><dc:creator>Sudeepta</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>thanks alot. That's exactly what I was looking for;-). How can I get the Windows User Name for example I want the user to be created like this:SQL Server Name\User Name.if I run that script you gave me will it solve my issue?</description><pubDate>Thu, 05 Aug 2010 02:33:51 GMT</pubDate><dc:creator>niteshrajgopal</dc:creator></item><item><title>RE: How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>You actually need two credentials, one to connect to the SQL Server instance (Login) and one to connect to the database (User).If you are using Windows Authentication to connect to the instance, then you can use the following command:[code="sql"]USE [master]GOCREATE LOGIN [test-pc\TestUser] FROM WINDOWS;GOUSE [TestDB]GOCREATE USER [test-pc\TestUser] FOR LOGIN [test-pc\TestUser] GO-- The following command will grant db-owner rights for the above userEXEC sp_addrolemember 'db_owner', [test-pc\TestUser] ;GO[/code]Hope, this may help.</description><pubDate>Thu, 05 Aug 2010 02:02:11 GMT</pubDate><dc:creator>Sudeepta</dc:creator></item><item><title>How to add user to sql server 2005 express programatically</title><link>http://www.sqlservercentral.com/Forums/Topic964028-324-1.aspx</link><description>Hi Guys,I have a class that checks if sql server express 2005 is installed on a pc and if not it installs it. In my class I specify stuff like sa password etc for the install.When a user installed the software the database was created but he can't login as he gets a meesage saying:[quote]unhandled exception has occurred in your application. Cannot open database "Games" requested by the login. The login failed.[/quote]How can I create a user for my database programmatically. Or even I run a sql script that creates the database. How can I do this in the script.I'm just installing on a single pc, no networking required, so in my connectionstring I use .\SQLExpress as the server. please help</description><pubDate>Thu, 05 Aug 2010 01:25:37 GMT</pubDate><dc:creator>niteshrajgopal</dc:creator></item></channel></rss>