I have SQL Server 2008 Enterprise edition, and C# code that should connect to said server. It's a local server on my computer and when I try to log on I get this error:
Cannot open database "Clients" requested by the login, the login failed.
Login failed for user crmsys.
This user has the right permissions, this server is even configured to allow remote connections and through the management studio I can access as this user.
Here's my connection string:
Data Source=./; Initial Catalog=Clients;user ID=crmsys;Password= Password;
In your snippet of configuration settings in your initial post there is a space between the equals sign and the first character of the password - is this correct?
i'm not sure "./" is a valid datasource. I always use "localhost" or ". \ [instancename]"
just an idea.
Make sure you dont have a firewall blocking you; the windows one does by default... If thats all ok check remote connections are enabled: From management studio Check Properties, Connections, and check "Allow Remote Connections To This Server" is checked.
If that is checked then restart SQL Server and try again; if it still fails check that TCP/IP is enabled and the settings using the Configuration Manager.
Are you sure the crmsys user has permission to connect to the database?
If you right-click the "Clients" database entry in SSMS, then go to "Properties" -> "Permissions", then select the "crmsys" user from the "Users or roles" pane, and then click the "Effective" tab, can you confirm that the "CONNECT" permission is there?
Edit: it should look like the image below:
alt text http://img42.imageshack.us/img42/4696/ssms.png
Have you tried Server=.\sqlexpress;Database=Clients;Uid=crmsys;Password=Password;Integrated Security=false
Solved it!!!!!! that was very weird but guess it turned out to be a conflict in the db properties, it's mixed out with the previues user which was crmsys(on the first computer) and when i restored it into my computer i made allready a user name crmsys - delete the user from the DB, deleted the Login crmsys, restored it and then opened a new user with the same permissions, and that it! Thanks you all for helping me figuring it out!
Related
We use entity framework to read from an existing database.
This is a simplified version of our code.
using (my context context = new mycontext())
{
if(context.Database.Connection.State == System.Data.ConnectionState.Closed)
{
_logger.Info(" Opening the connection to the database");
context.Database.Connection.Open();
}
context.Configuration.LazyLoadingEnabled = false;
IQueryable<mymodel> people;
people = context.People.OrderBy(x => x.Firstname);
_lstContacts = people.ToList();
if (context.Database.Connection.State != System.Data.ConnectionState.Closed)
{
context.Database.Connection.Close();
context.Database.Connection.Dispose();
_logger.Info(" Connection to the database Closed");
}
}
It works 100% of the time, but...
On our UAT environment we can see failed connections to the Microsoft SQL server with the error:
Login failed for user "my user". Reason: Failed to open the explicitly
specified database "null". Client my IP.
For us, these are ghost connections because at the time when we see the errors in the SQL server, our code is not executed.
Initially we didn't close and open the connection explicitly, we just added it trying to control when EF open and closes the connection, but it didn't fix the issue.
Our connection string is using the following format:
<add name="MYCN" connectionString="metadata=res://*/CVs.Cvs.csdl|res://*/CVs.Cvs.ssdl|res://*/CVs.Cvs.msl;provider=System.Data.SqlClient;provider connection string="data source=myserver\;initial catalog=mydatabase;Integrated Security=;User ID=myuser;Password=XXXXXXX;MultipleActiveResultSets=True;App=EntityFramework"/>
As you can see, we are specifying the database in the connection string and our user only have access to our database, so we understand the error when EF doesn't include the database in the connection string, but we don't understand why it's trying to perform these connections.
We know the connections are coming from our application, because we are the only one using that specific user, the IP is the IP of our server, and because the logs in SQL server tell us that the application is "EntityFramewrok"
I didn't personally see the error before, but researched for you and seen that many people suffered from the same problem discussed here: https://blogs.msdn.microsoft.com/sql_protocols/2006/02/21/understanding-login-failed-error-18456-error-messages-in-sql-server-2005/
I read all the messages in the website specified, and here are the solutions offered and at least one other user confirmed that it worked. You might not use 2005 as you didn't specify your version in your question, some solutions I believe will still work for you. Try the list below.
Solution list:
1) Please check the state number of this error and search solution by the state number in addition to the message, might give your more accurate solution proposals. Most common states are listed:
All state-error descriptions you can find here: https://sqlblog.org/2011/01/14/troubleshooting-error-18456
2) Make sure the username and password are correct.
3)
Logon to SQL Server using windows authentication.
Right click in the query window that appears and select "Open Server in Object Explorer"
Go to object explorer and open the "Security" folder and then the "Logins" folder.
Double-click the "sa" user and change the password. Also, like another user mentioned above, untick the "Enforce Password Policy" in
addition to resetting the password.
4) Try to change the password and turn off the policy, and try with new password.
exec sp_password #new = ‘sqlpassword’, #loginame = ‘sa’
alter login sa
with password = ‘sqlpassword’ unlock,
check_policy = off,
check_expiration = off
5) Run your application/browser and SSMS (if you work on it) in administration mode.
6)
Open Windows Services
Configure Microsoft Single Sign-on Service to use the proper account
Open Central Administration >> Operations >> Manage settings for single sign-on
Configure properties to use the same account used for Microsoft ‘Single Sign-on Service
7) Go to Sql server configuration manager and Enable TCP/IP and named pipes
8)
go to sql server
right click on server, choose properties
click on security
on server authentication, enable SQL Server authentication
These might help:
https://www.wikitechy.com/errors-and-fixes/sql/login-failed-error-18456-severity-14-state-38-reason-failed-to-open-the-explicitly-specified-database
https://dba.stackexchange.com/questions/90445/login-failed-for-user-error-18456-severity-14-state-38
I think this is just an access issue for myuser in the UAT environment. Just make sure myuser has access in the UAT environment for UAT database and you should be good.
We've got an ASP.NET application which connects to our database. We handle this connection using an XML config file which contains information with how access the database (username, password, etc). However when we try to access certain pages we're greeted with the yellow screen of death and a message saying Login failed for user xxx.
When run locally as localhost this error does not appear. When we deploy our service to the server this error message appears. Our connection string looks like this:
<add key="DBConnection" value="Data Source=[ServerNameHere];Initial Catalog=[DBNameHere];MultipleActiveResultSets=True;User Id=[usernamehere];Password=[passwordhere];" />
For our SQL Server we've got both SQL Server and Windows Authentication mode enabled. I've checked the login properties for the sa account and changed the "Permission to connect to the database engine" set to "Grant" and the "Login" is set to "Enabled", both of which still present the same issue. The server and database are on the same machine also.
These were the most common resolutions to others who had the same issue, is there something else we can try to fix the issue?
One final note is that when we get the Loging failed for user xxx, the xxx is the name of the machine, so it looks like Domain\MachineName$ when we get the yellow screen of death.
EDIT: The exception being thrown is the following:
System.Data.SqlClient.SqlException: Login failed for user 'Domain\MachineName$'. I've disabled "continue on exception" in my Visual Studio but this error is nowhere to be found when debugging the application locally.
Ok so it turns out the issue was that our IIS Manager which was hosting the service for our web application did not have the correct permission to access the database. To resolve the issue it required going into SQL Manager and adding both a login AND user for our app pool...
Open SQL Server Management Studio and connect to your target server
Under your server expand the Security folder, right click Login and select New Login...
Keep Windows Authentication enabled. The login name should be IIS APPPOOL\[NAME OF YOUR SERVICE HOSTED ON IIS]
Click on the Server Roles link on the left of the screen and ensure that public and sysadmin is selected.
Click on the User Mapping link on the left of the screen and select the DB you'd like your web service to be able to reach.
Click on the Status link on the left and ensure that the settings are set to Grant for permission to connect to the DB and Enabled for the login.
Now create a user for the db you'd like to access...
Expand your chosen DB and expand the Security folder (not to get confused with the security folder above!). Right click it and select New User...
Ensure the user type is SQL user with login (may change depending on how your project is accessing the DB)
To the left of the Login name box there will be a button with ... on it, click it
This brings up a new window. Click on it and then select the login you created previously. Ok all the windows.
Copy and paste the login name as the username
On the left select Owned Schemas and ensure db_reader and db_writer are selected
On the left select Membership and ensure that db_reader and db_writer are selected
Click ok to create the user; your app pool hosting your service should now be able to access the DB
I got this error message while connecting my app with the database at my website.
If i try using XAMPP using my computer, its work well.
FYI, the username and password is same as username and password that i created using XAMPP.
and also grant the privileges.
this is the connection string. for example the server is 174.125.80.140, the database name is myDB, the Uid is alfred, and the password is Alfred111.
MySqlConnection conn = new MySqlConnection("Server=174.125.80.140; Database=myDB;Uid=alfred;Pwd=Alfred111;");
I'm using MySQL client version: 4.1.22.
I'm still can't access the database. is there any solution??
If you are using MySQL workbench,
1) Start the workbench
2) click on the option "Users and Privileges" under SECURITY
3) click on add user (for the specific user), this is more secure because it lets you handle who has access over your database and lets you control access.
however if you want to grant access a large number of users for an application like c# application, then hard-code the username and password in the application, from the user privileges that you have set above.
Hope this helps (^_^)
Yes, you may have supplied the user and password correctly but have you configure the server (new server) to accept Uid=alfred;Pwd=Alfred111;?
Adding User in MySQL Server
If your app is on a different host that the MySQL server then you most likely need to add a new user granting permission for that host. Your alfred user is probably allowed by localhost and nothing else. Try CREATE USER 'altred#'%' identified by 'password'; and then grant that user privileges on myDB.
You can replace % with a specific IP address or hostname as well, % allows the connection from any host which is not necessarily safe.
You can try the following query to see the allowed user/host combos:
SELECT `User`, `Host` FROM `mysql.user`
Hope that helps.
I am working on development machine without making any user account [i have three of four account who comes when i installed them].
so i open the connection everywhere by a globals variable who hold the connectionstring off-course value of variable can not be changed it's constant.
i open the connection using root account who come by default in mysql server. they work fine everywhere.
but my code try to run a command then server return the error that
The user specified as a definer ('admin'#'localhost') does not exist
i don't know why i got this error even in debug i found that connection open by root and they work fine everywhere else.
so the problem is why they tell me about admin#localhost even the connection my code open by root.
are their anything my code try to do who need authentication or need admin account even they not have then give me exception.
Are you know that what is gone wrong.
I got this error after DB was moved to another server.
There no such user 'admin' so I got the error.
Solution:
log into mysql as root
grant all on *.* to admin#localhost identified by "s!5_superp#ss!";
flush privileges;
I am not able to connect to Oracle using connection string and the correct password. I've tried the same parameters in SQL developer and sqlplus(commandline) and they are working. I even tried changing the password but no use.
Any ideas what might be wrong or where should I start looking?
The exact Oracle error is :
invalid username/password password, logon denied
and after trying a few times account is getting locked with
the account is locked
When I've run into this, it has ALWAYS been an issue with my connect string.
What is your connect string? It should be something like "User Id=[ID]; Password=[PWD]; Data Source=[DB]"
Of course, you'd replace [ID], [PWD] and [DB] as appropriate.
Is it just your computer that exhibits the problem, or are others seeing it as well?
Can you test your connection in the ODBC Data Source Administrator? Does that work?
Try to install the Oracle Developer Tools for Visual Studio. It's free but you need to register, also free.
You need to unlock the account.
(From above referenced site)
SQL> ALTER USER username ACCOUNT LOCK;
SQL> ALTER USER username ACCOUNT UNLOCK;
Actually the problem was with cache on the computer. Even though I am giving "server='correctdb'" visual studio was taking "server='olddb'" as input and hence I am not able to connect. Pathetic but that's what happened.