all groups > sql server msde > december 2005 >
You're in the

sql server msde

group:

Creating a user in SQLExpress with SQL Server Management Studio Express



Creating a user in SQLExpress with SQL Server Management Studio Express Andrew Chalk
12/13/2005 11:49:50 PM
sql server msde: I have created a user in SQL Server Management Studio Express. However,
whenever my ASP.NET application tries to connect I get the error
Cannot open database "ABC" requested by the login. The login failed. Login
failed for user 'Fred'.

If I change my login string to Integrated Security=SSPI it works. Also, I
was able to add a user successfully in SQL 2000 but SQLExpress is differnt.

Can anyone tell me how to add a user and give him permissions for a
particular database? Or refer me to a URL that does.

Many thanks.

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrea Montanari
12/14/2005 12:07:15 PM
hi Andrew,
[quoted text, click to view]

please verify your SQLExpress instance accepts standard SQL Server logins,
enabling mixed security.. your connection string changed to ....Integrated
Security=SSPI implies a trusted connection...

SQL Server uses a so called "2 phases" authentication policy:
first an SQL Server Login or a Windows login must be created of granted
access to the SQL Server instance... at the server level a login can be made
member of none, 1 or all of the fixed server roles, which include "sysadmin"
role and so on...

you can choose between 2 authentication modes:
WinNT (trusted) connections or SQL Server authenticated connections... the
latter always requires full user's credential such as "User
Id=sa;Password=pwd", the password can be NULL so it must not be specified,
but I strongly advise you always to ensure strong passwords are present....
WindowsNT authentication, on the contrary, does not requires user's
credential becouse it's directly provided by Windows via the logins'ID
(sid), which authenticate user's login at the windows login step... SQL
Server only needs to verify that the corresponding login and/or group is
granted to log on the instance...

the second authentication phase is at database level, where each login will
be granted database access mapping to a database user... here access
permissions are set, as granting user/role SELECT/DELETE/EXECUTE (and so on)
privileges at an object level (or column level for tables and views)..
so, the second phase regards a database security implementation... in order
to access a specified database the simple login existance does not provide
database access, but a (database) user must be mapped to the corresponding
login.. and is about verifying that at each object level (including
database, tables, views, columns, procedures and so on) the Login/User
association is permitted access to...

CREATE LOGIN http://msdn2.microsoft.com/en-us/library/ms189751.aspx
CREATE USER http://msdn2.microsoft.com/en-us/library/ms173463.aspx
GRANT {database permission}
http://msdn2.microsoft.com/en-us/library/ms178569.aspx
GRANT {permission} http://msdn2.microsoft.com/en-us/library/ms187965.aspx
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.16.0 - DbaMgr ver 0.61.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrew Chalk
12/14/2005 5:46:34 PM
Andrea: Thanks you for your detailed reply.

I understand the concptual difference between Windows and SQL authentication
and thought I had done all the necessary steps, which is why I am puzzled.
As I mentioned, with SQL 2000 I used SQL Enterprise manager and have the
login working. I have tried to map the steps I took in SQL2000's SQL EM to
those in the new SQL Server Mgt. Studio Express.

1) I created a login under the server->security folder.
I did not give this Login any Roles. It is just a plain ol' user (public).

2) I went to the server instance name at the top and GRANTed "Connect SQL"
permission to the new Login just created;

3) I went to the database and granted "Connect" permission to the Login.

After these steps I get the error reported in my earlier post.

I should add that I am not an SQL Server expert and first looked at the SQL
Server Mgt. Studio Express BOL.They are absolutely useless.

Hope the above hels.

Andrew

[quoted text, click to view]

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrew Chalk
12/14/2005 6:05:27 PM
I don't understand the following stement:
[quoted text, click to view]

what is the difference between a Login and a User?

[quoted text, click to view]

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrea Montanari
12/15/2005 1:00:32 PM
hi Andrew,
[quoted text, click to view]

it's not a user, it's a login and there's no "public" server role... it's
just a login which is not member of server roles...

[quoted text, click to view]

yep... the login has been created, enabled, and granted access to the
instance..

[quoted text, click to view]

ok, you granted db access to the login, which is now member of th public
database role..

[quoted text, click to view]

I reproduced your steps and I can log on to SQLExpress as a standard SQL
Server Login, and access a db the login has been mapped to a corresponding
user.. I did it via SSMSExpress and not via ASP..

[quoted text, click to view]

:D
download the full BOL, december released..

[quoted text, click to view]

a Login is the very first part of the 2 phases security policy enforcement
of SQL Server... I repeat what I already wrote..
SQL Server uses a so called "2 phases" authentication policy:
first an SQL Server Login or a Windows login must be created in order to
grant access to the SQL Server instance... at the server level a login can
be made member of none, 1 or all of the fixed server roles, which include
"sysadmin" role and so on...

you can choose between 2 authentication modes:
WinNT (trusted) connections or SQL Server authenticated connections... the
latter always requires full user's credential such as "User
Id=sa;Password=pwd", the password can be NULL so it must not be specified,
but I strongly advise you always to ensure strong passwords are present....
WindowsNT authentication, on the contrary, does not requires credential
becouse it's directly provided by Windows via the logins' ID (sid), which
authenticate (Windows) user's login at the windows login step... SQL Server
only needs to verify that the corresponding login and/or group is granted to
log on the instance (checking the granted Login's existence in the SQL
Server instance)...

the second authentication phase is at database level, where each login will
be granted database access mapping to a database user... here access
permissions are set, as granting user/role SELECT/DELETE/EXECUTE (and so on)
privileges at an object level (or column level for tables and views)..
so, the second phase regards a database security implementation... in order
to access a specified database the simple login existance does not provide
database access, but a (database) user must be mapped to the corresponding
login.. and is about verifying that at each object level (including
database, tables, views, columns, procedures and so on) the Login/User
association is permitted access to...
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.16.0 - DbaMgr ver 0.61.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrew Chalk
12/15/2005 2:17:31 PM

[quoted text, click to view]

The phrase:
[quoted text, click to view]

Can you explain that.
How did it happen?
Who is the user?
Is it correct to say that the user is an instance of utilizing a login? I.e.
"users" have logins. Some may use the same logins as others (for example
several instances of an application). In which case each application trying
to use SQL server is a user and their name/password pair correspond to their
login?

Thanks.

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrew Chalk
12/15/2005 2:30:35 PM
I now have a role named 'fred' and a user named 'fred' of the database that
I want the application to access. Is the use of the same name the problem?

Thanks
[quoted text, click to view]

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrew Chalk
12/15/2005 3:00:39 PM
OK, fixed it, though mainly through luck than knowhow.

Deleted user "fred" and login "fred".
Recreated login Fred but made sure that I went to 'User Mapping' and checked
the database that I wanted this Login to be able to access;
Login was created and, like magic, a user appeared, also named 'fred', under
the database.

I still don't understand this.

Nonetheless, thanks for your help,

Andrew

[quoted text, click to view]

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Roger Wolter[MSFT]
12/15/2005 5:06:44 PM
A SQL Server instance can contain many databases. A login is a piece of
data stored in the master database that allows you to connect to the SQL
Server instance. It stores something to allow you to identify yourself to
SQL Server - either a password for SQL Server logins or your Windows
credentials for integrated logins. Once you have successfully identified
yourself to SQL Server and completed the connection, you need to access data
in a database. To do this, an administrator must create a user object in
the database you want to access and link it to your login. You can only
access databases that you have users created for you in. The user is
granted the permissions necessary for you to do what you need to do in the
database.

The reason for this duality is that you may have different permissions
depending on which database you are accessing. For example you may have
permissions to create and drop tables and update any data in the payroll
database but only have read permissions for data in the accounts receivable
database. You may not even be allowed to open the HR database.

I hope this helps clarify the difference and explains why you need both.

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

[quoted text, click to view]

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrea Montanari
12/15/2005 5:31:50 PM
hi Andrew,
[quoted text, click to view]

perhaps my english is not as good as I thought.. :D
perhaps here,
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_security_4fol.asp,
the architectural design is more clear..
a SQL Server Login (both standard SQL Server login or a WinNT login) is just
the very first brick in the wall in order to access a SQL Server instance...
without that you can not log in and connect to a specified instance... it
has a server wide range...
a User is just a database user (can have the same name as the corresponding
Login [Login is now somehaw obsolete, to be replaced by principals] but this
is not mandatory even if it's recommended in order to minimize troubles :D)
that, at creation time, is mapped via it's sid column
(dbname.sys.sysusers.sid) to an existing login
(master.sys.server_principals.sid)

SELECT u.name AS [Name in DB], u.hasdbaccess ,
p.name AS [Login Name]
FROM master.sys.server_principals p JOIN sys.sysusers u
ON p.sid = u.sid

Principals
http://msdn2.microsoft.com/en-us/library/ms181127(en-US,SQL.90).aspx
DB Users
http://msdn2.microsoft.com/en-us/library/ms190928(en-US,SQL.90).aspx

[quoted text, click to view]

Logins can be granted db access as database users, but they can even not..

[quoted text, click to view]

an application is not a user or a login... in certain case an application
role can represent this scenario
(http://msdn2.microsoft.com/en-us/library/ms190998.aspx)

[quoted text, click to view]

it's correct... you created a login... then you granted that login db access
via a database user (in the defined database) mapping it to the original
login ...
if you only create a login without grating him/her access to your desired
database(s), that login will only access it if the predefined "guest"
database user is available (and usually that db user is not available for
security reason)...
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.16.0 - DbaMgr ver 0.61.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrew Chalk
12/15/2005 11:39:49 PM
That URL does not use the work 'Login', only 'User'.

What is the difference between a login and a user?

Thanks,

Andrew

[quoted text, click to view]

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrea Montanari
12/16/2005 10:37:01 AM
[quoted text, click to view]

thank you Roger, usually we are told "italian(s) do it better" but this
thread trashed my convinctions about my (poor) english :(
:D
--
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtm http://italy.mvps.org
DbaMgr2k ver 0.16.0 - DbaMgr ver 0.61.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
--------- remove DMO to reply

Re: Creating a user in SQLExpress with SQL Server Management Studio Express Andrew Chalk
12/16/2005 4:08:57 PM
Excellent. That makes the two-stage validation make sense and explains what
each does.

Many thanks!

[quoted text, click to view]

AddThis Social Bookmark Button