7

I want to add a user in SQL Server 2008 so I can use SQL Server Authentication instead Windows Authentication for connecting to SQL, and have tried this code to create a user with login:

CREATE login [newLog] with password = 'passnewLognewLog'

I get it done, but when I want to connect to SQL Server using SQL Authentication, I get this message

Cannot connect to "Mydb"
additional information: Login failed for user 'newLog'. (Microsoft SQL Server, Error: 18456 )

What am I missing here?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
edgarmtze
  • 24,683
  • 80
  • 235
  • 386
  • Important, the mixed authentication has to be [enabled][1] [1]: http://stackoverflow.com/questions/1719399/sql-server-2008-cant-login-with-newly-created-user?answertab=votes#tab-top – denzel Sep 09 '15 at 21:40

3 Answers3

13

After creating the login, you need to add the user to the database. This example is from the sql server documentation for CREATE USER:

CREATE LOGIN AbolrousHazem 
    WITH PASSWORD = '340$Uuxwp7Mcxo7Khy';
USE AdventureWorks2008R2;
CREATE USER AbolrousHazem FOR LOGIN AbolrousHazem;
GO 

Edit

To test, I ran this T-SQL:

create login Foo with password ='f00';
go

use TestDB
create user Foo for Login Foo
go

and opened a connection successfully using this connection string:

"Server=<server>; user id=Foo; password=f00; initial catalog=TestDB"
Jeff Ogata
  • 56,645
  • 19
  • 114
  • 127
  • I have tried that but can not login using SQL Server Authentication – edgarmtze Jul 10 '11 at 21:23
  • what else do I have to do so I can connect using SQL Server Authentication with the created user?? – edgarmtze Jul 10 '11 at 21:30
  • @cMinor, see my edit. I was able to create a login, add the user and connect successfully. Is it possible you executed the `create user` statement in the context of a different database (perhaps master)? – Jeff Ogata Jul 10 '11 at 21:39
5
  1. You need to create a user for the login, e.g.

    CREATE USER [newLog] FOR LOGIN [newLog] WITH DEFAULT_SCHEMA=[dbo]
    
  2. Check that mixed authentication is enabled: https://stackoverflow.com/a/1719476/188926

Community
  • 1
  • 1
Dunc
  • 18,404
  • 6
  • 86
  • 103
1

Try the following. They worked for me when I had this connection issue.

 -When you are adding SQL user, make sure 'enforce password policy' is unchecked.
 -Make sure that user is mapped to the database with proper permissions.
 -on SSMS, right click server and then go to Security tab. Select 'SQL Server and Windows Authentication mode' option.
 -restart PC.
Programmer
  • 86
  • 3