Add login and connect to SQL with SQL Server Authentication - sql-server-2008

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?

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"

You need to create a user for the login, e.g.
CREATE USER [newLog] FOR LOGIN [newLog] WITH DEFAULT_SCHEMA=[dbo]
Check that mixed authentication is enabled: https://stackoverflow.com/a/1719476/188926

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.

Related

SQL Server SA Password for SQL Server Authentication?

I am working on SQL Server 2008 and currently I am using my local server with windows authentication. Can i set SA password for SQL Server Authentication? What are the steps and also I want to know what is the difference between Windows and SQL Server Authentication?
Window Authentication: If you are authorized user to window and you have proper right to access sql server. you are all done to access sql server, you don't need any username/password to access sql server.
SQL Server Authentication: You need to create new user to access sql server (a part from window user). You need username & password of newly created user to access sql server.
You can create new SQL Server Authentication user by: Object Explorer >> Security >> Login >> New Login. Again, you need required right for the window user through which currently you are accessing sql server.

Problems In Connection String with different Users in System for Windows Authentication

Hi this is my Connection String:
Windows Authentication:
<add name="strConnection" connectionString="Data Source=MURALI\SQLEXPRESS;Initial Catalog=Ecowhisk28113;Integrated Security = True" providerName="System.Data.SqlClient;"/>
i run this applications in System's Administrator means working correctly but same application
run in System's Users means I get This Error.
'Cannot open database "Ecowhisk28113" requested by the login. The login failed. Login failed for user 'MURALI\Murali'. '
I want know whether the connection string error or system settings problem...
please help to solve this bug....
Thanks.....
You need to Login to SSMS and grant the users that will be accessing the database proper permissions to the database. You can check this by opening SSMS connecting to the SQL server expanding the Security folder right click on Logins and create a new Login for 'MURALI\Murali'and add the new Login access to the Ecowhish28113 database. You depending on the type of access required you will need to add the login to the database roles in that DB as well.

New SQL Server user failed to login

I've created new user in SQL Server Management Studio (SQL Server 2008 Express) in security tab.
Specified the login name, SQL Server authentication, entered a password, assigned server role sysadmin, mapped to my database and there specify it as db_owner. Also in database security is specified in tab Schemas owned by this user is db_owner.
I've checked a lot of tutorials but all of them do the same as me but when I try to login to SQL server (even manually) error message is thrown:
Login failed for 'MyUser' (Microsoft SQL Server, Error: 18456)
Any idea what's wrong?
Thanks a lot.
Peter
Failed to login SQL Server after installing SQL Server and creating new login user for SQL Server? You can check error description in Error Log file at first. Look for entry and then confirm what "State" means in entry.
After making sure which lead to this SQL Server login error, take appropriate measures. Generally, you would need to do according to different situations.
You would need to change authentication mode to Mix Authentication or SQL Server Authentication mode.
You would have to enable SQL login user if the login is disabled.
Reset SQL Server user password if the login user password is incorrect.
Configure Windows Firewall to allow SQL Server access if the login is valid but server access is failed.
More details about fixing failed login error for user, you can refer to this article.
http://www.isunshare.com/sql-server/fix-sql-server-failed-login-error.html
I came across the same problem and solved mine by changing the Server to Mixed Authentication Mode. In my case, I was trying to log in with a SQL server login, but the server was only set up to accept Windows Authentication.
See this link for how to change it:
http://support.microsoft.com/kb/555332
I realise this question is old, but I hope the answer helps someone.
Thanks

Error in login to SQL Server

When I want to connect to SQL Server 2008, I get this message:
Cannot connect to server.
Additional Information: Cannot open user default database. Login failed. Login fail for user 'sa'. (Microsoft SQL Server. Error:4064)
How do I resolve this error?
This error (Microsoft SQL Server.Error:4064) occurs when the database which is dropped is default for some database user.
When the user tries to login and their default database is dropped the error shows up.
Cannot open user default database. Login failed. Login failed for user
‘UserName’. (Microsoft SQL Server, Error: 4064)
The way to resolve this is given here, summarized below.
The solution to log on is:
From the Connect to Server dialog, click Options
Change value of Connect to database: to any valid database on the server
The permanent solution to fix the server is to run SQL like:
ALTER LOGIN [test] WITH DEFAULT_DATABASE = master
GO
In my case this was due to a user being a member of multiple groups, each group having its own login. All groups' logins need to have their default database set to a database accessible to the user.
Other possible problems are listed at https://support.microsoft.com/en-us/kb/307864.
You can set each login with an invalid default database to have a default database of master (accessible to all logins):
alter login [loginname] with DEFAULT_DATABASE = master
The user default database is unavailable at the time of connection so that this error message will popup .SO check which server you tagged to that particular user to access whether it is online or offline mode.

How to make SQL Server find a login matching the name provided?

I have just restored a database backup to my local SQL Server express instance.
In management studio under the server instance node I went to: Security -> Logins -> New login...
Then I filled in a login name, password and chose SQL Server authentication. And at the bottom I selected the newly restored database to be the Default database.
At the User Mapping 'tab' at the left, I mapped the user to the newly restored database and gave it "db_owner" role.
When I try to login the following error is given in the log:
Login failed for user 'username'. Reason: Could not find a login matching the name provided. [CLIENT: ]
How can I make SQL Server find the login matching the name I provided?
Other info:
Named pipes are enabled
TCP/IP is enabled
Remote connections are allowed
Please make sure you have selected "SQL Server Authentication" mode for user you created from
Server > Security > Logins option.
Another possibility, is that you created the SQL Server login using Management Studio, and the option requiring the user to change the password on first login was checked. If you didn't immediately login with Management Studio, and change the password, then the attempt to login from the other machine is not able to pop up a dialog box to change the password and so it fails.
try it by removing user and create again.
This is old but for some one who encounters error for ASP.Net Core 2.2 using EF core and VS Code, I got error
Error Number:18456,State:1,Class:14
Login failed for user 'sa:password=MyPassword'.
I looked logs from SSMS and found error as
Login failed for user 'sa:password=MyPassowrd'. Reason: Could not find a login matching the name provided. [CLIENT: MyIp]
After searching here and there i found that I have to add Persist Security Info=False in connection string, so my connection string became like
"Default":"Persist Security Info=False;User ID=sa;Password=MyPassword;Initial Catalog=MyDb;Server=MyServerIp"
I found this format from Microsoft Docs. After that it worked fine.
persist security info=false is default. I didnot found any reason why my connection string without it was not working. From here