Bad T-SQL code for account creation - sql-server

How do I create a User using SQL code to join an SQL Server via SQL Server authentication mode. I used the code
CREATE LOGIN ANNACASSAR
WITH PASSWORD = '';
GO
CREATE USER ANNACASSAR FOR LOGIN ANNACASSAR;
GO
But I get this error:
Cannot connect to moscow\SQLSERVERMSWDEV.
Additional information:
login failed for user ANNACASSAR
(Microsoft SQL Server error 18456)

Set your server to Mixed authentication mode (right-click on the server in SSMS, Properties, Security, SQL Server and Windows Authentication mode, then restart the server).
However, you really should set a password, because it's a real security risk to create a login without a password.

Related

Cannot Access SQL Server to Connect Database

I have created a database on our SQL Server for Eplan. When I try to login to SQL using Windows Authentication I receive an error that states:
Login Failed. Login is from an untrusted domain and cannot be used with Windows authentication.
When I use my SQL server login it returns:
Connection could not be established. Login failed for user xxx
So I've verified that I am using the correct login/password. TCP/IP is enabled and SQL Server uses SQL Server and Windows Authentication.
I am really at loss as to what to do next.
Thank you!
EplanSQL

Error occurred while connecting to SQL Server 2012: Cannot open user database. Login failed. (Microsoft SQL Server, Error: 4064)

I unknowingly deleted SA user from the SQL Server 2012. Now i cannot be able to connect to the sever. It shows an error :
Cannot open user database. Login failed. Login failed for the user 'username'.(Microsoft SQL Server, Error: 4064)
Now i don't know what to do?
Help me please
Thanks
When ever get this error,we have to create a new user with server authentication to connect the data base
We can create login for data base under security tab-->create new login under it
If you have Windows administator permissions, you can restart SQL Server in single-user mode. Any administrator can then log in locally and fix things.
Give this a shot as a place to start:
Connect to SQL Server When System Administrators Are Locked Out (MSDN)

SQL server 2008 login issue

Hi I created a new login SQL server authentication in SQL server 2008, however I am unable to login with that user.
Getting an error like ,
TITLE: Connect to Server
Cannot connect to (local).
ADDITIONAL INFORMATION:
Login failed for user 'sa'. (Microsoft SQL Server, Error: 18456)
The error Login failed for user 'sa' means that connection to server was established, but server refused it under certain circumstances, such as:
Wrong password
Sql server uses only Windows Authentication (needs server restart)
In your Connection String you ask to connect to specified DB, which is not exists
sa login is Disabled or Denied to access sql engine
User Action
If you are trying to connect using SQL Server Authentication, verify
that SQL Server is configured in Mixed Authentication Mode.
If you are trying to connect using SQL Server Authentication, verify
that SQL Server login exists and that you have spelled it properly.
If you are trying to connect using Windows Authentication, verify
that you are properly logged into the correct domain.
If your error indicates state 1, contact your SQL Server
administrator.
From this article
Should this not help try troubleshooting this issue following these steps.

SQL Server 2008 - Login failed for user 'user1' The user is not associated with a trusted SQL Server connection

I have installed SQL Server 2008 R2 on Windows XP.
In installation process I selected 'SQL Server and Windows Authentication Mode'
When I click right button of the mouse in SQL Server Management Studio on Server -> Security tab 'SQL server and Windows Authentication Mode' is selected.
But when I click on my Database -> Properties - View connection properties Authentication Method is set on Windows Authentication.
To my database was added one user1 with password user1.
But I can't log in to my database from C# (Visual Studio 2008) because error occurs:
Login failed for user 'user1' The
user is not associated with a trusted
SQL Server connection
What isn't right ?
When I get:
string connectionStr = #"Data Source=rmzcmp\SQLExpress;Initial Catalog=ResourcesTmp;Integrated Security=True";
I have following error:
{"Cannot open database \"ResourcesTmp\" requested by the login. The login failed.\r\nLogin failed for user 'RMZCMP\rm'."}
rm is my original user name on which I log in to my computer.
When I get rm I have error:
{"Login failed for user 'rm'. The user is not associated with a trusted SQL Server connection."}
again.
Regards
You say a user was created in your database - did you also create a login to your server?
In SQL Server 2005 and up, security is a two-step process:
you first must define a login that enables a user to even log in to that SQL Server
based on that login, you can define user in your individual databases
Also: you're not showing us your connection string, so we can only guess what settings you're using. From the error message, I'm almost guessing you're using Integrated Security in your connection string - but from your other points in the question, it seems you've created a specific user (and possibly a login for that user) - so you don't want to use integrated (Windows) security...
Most likely, your connection string is invalid - or you're missing a login - or both. You need to give us a bit more information for us to be able to really help!
Can you change your Connection string based on :
Connection string.com
Make sure that your installation of SQL Server is successful.
Ex:
If you can create a SQL Server authentication login
You can login using username/password in SQL Server authentication. Use a connection string like:
Data Source=Servername;Initial Catalog=DatabaseName;User ID=user;Password=sa
But
If you can login using only windows authentication there is something wrong in your installation. Use connection string:
Data Source=Servername;Initial Catalog=DatabaseName;Integrated Security=True
Regards!
That error suggests your application is set to log in with "trusted" (i.e. Windows) credentials and that the Windows account that the program is running as doesn't have a login on the server. Based on the way that you phrased the adding of a user, my guess is that it's a SQL login and you should change your connection string to reflect that.
I created user on my machine (where ms sql is installed)
User name is user1 and password too.
I can log on to Ms sql server on this user (user1)
My connection string is:
string connectionStr = #"Data Source = rmzcmp\SQLExpress; Initial Catalog = ResourcesTmp; User Id = user1; Password = user1;";
I user MS SQL Server 2008
rmzcmp is my computer name.
In ResourcesTmp (my database) ->Security ->Users I have: dbo, guest, INFORMATION_SCHEMA, sys, user1, user2
I don't have sa user.
User1 has following permissions:
Schemas owned by this user:
db_accessadmin
db_datareader
db_datawriter
Database role membership
db_accessadmin
db_datareader
db_datawriter
db_owner
Server properties -> Permissions ->Explicit tab:
Connect SQL : Grantor sa, Grant true.
User1 all checkboxes has false
Security tab -> Server authentication : SQL Serve and Windows Authentication mode is selected as I mentioned in earlier post
Regards
This problem occurs if the user tries to log in with credentials that cannot be validated. This problem can occur in the following scenarios:
Scenario 1: The login may be a SQL Server login but the server only accepts Windows Authentication.
Scenario 2: You are trying to connect by using SQL Server Authentication but the login used does not exist on SQL Server.
Scenario 3: The login may use Windows Authentication but the login is an unrecognized Windows principal. An unrecognized Windows principal means that Windows can't verify the login. This might be because the Windows login is from an untrusted domain.
To resolve this problem, follow the steps that apply to your scenario.
Scenario 1: Configure SQL Server in Mixed Authentication Mode.
SQL Server 2012, SQL Server 2008, and SQL Server 2005
Open SQL Server Management Studio. To do this, click Start, click All Programs, click Microsoft SQL Server 200x (where x is the version of SQL), and then click SQL Server Management Studio.
Right-click the server, and then click Properties. See image.
On the Security page, under Server authentication, click the SQL Server and Windows Authentication mode option button, and then click OK. See image.
In the SQL Server Management Studio dialog box, click OK to restart SQL Server.
see http://support.microsoft.com/kb/555332

Sql Server 2005 login failed

I'm getting message login failed user not associated with a trusted Sql Server Connection
It's a Sql Server 2005 legacy system with linked servers. Whoever set it up left sa password blank (I will be changing.)
How do make a trusted Sql Server connection ?
A "trusted SQL Server connection" error usually means that you're attempting to authenticate using Windows Integrated security and the currently logged on Windows user has not been defined either directly or through group membership to have access to the sql server database being requested.
If the sa password is indeed blank you can login using sql server security as sa + [blank] and associate your Windows account with the appropriate server permissions (and change that sa pwd just after you verify your new account works ok...)
From code a Windows Integrated connection string looks like this:
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;
a SQL Server user id/pwd connection string looks like this:
Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;
(for more varieties check out connectionstrings.com)
Good luck!

Resources