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?
In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties. On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
Open SQL Server Management Studio. In Connect to Server, select Database Engine, enter your SQL Server name, and enter administrator credentials to connect to the server. Select Connect. In Object Explorer, expand the SQL Server, expand Security, right-click Logins, and then select New Login.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With