12

Alright, I have a classic asp application and I have a connection string to try to connect to db.

MY connection string looks as follows:

 Provider=SQLOLEDB;Data Source=MYPC\MSSQLSERVER;Initial
 Catalog=mydb;database=mydb;User Id=me;Password=123

Now when I'm accessing db though front-en I get this error:

Microsoft OLE DB Provider for SQL Server error '80040e4d'
Login failed for user 'me'. 

I looked in the sql profiler and I got this:

 Login failed for user 'me'.  Reason: Password did not match that
 for the login provided. [CLIENT: <named pipe>]
 Error: 18456, State:8. 

What I've tried:

  1. checked 100 times that my password is actually correct.
  2. Tried this: alter login me with check_policy off (Do not even know why I did this)
  3. Enable ALL possible permissions for this account in SSMS.

Update: 4. I've tried this connection string: Provider=SQLOLEDB;Data Source=MYPC\MSSQLSERVER;Initial Catalog=mydb;database=mydb; Integrated Security = SSPI

And I got this error:

Microsoft OLE DB Provider for SQL Server error '80004005' Cannot open database mydb requested by the login. The login failed.

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
user194076
  • 8,787
  • 23
  • 94
  • 154
  • Are you able to log on with any account? For example, if you create a new account and use that instead, does it work? – user995048 Oct 19 '11 at 04:49
  • No. not a singe account works. (It does work if I go directly to SSMS though.) SO, I assume there's a problem with IIS or maybe Windows auth...don't know... – user194076 Oct 19 '11 at 04:51
  • @user194076 Does the login have SQL Server authentification mode? – Igor Borisenko Oct 19 '11 at 05:07
  • @Igor, How do I check? Are you talking about Right click on the server in SSMS - Properties - Security - yes, it says: "SQL Server and windows authentication mode" – user194076 Oct 19 '11 at 05:13
  • @user194076 Yes, I told about that. It could be that you tried to connect to logiw with windows authentification mode. Did you read this http://msdn.microsoft.com/en-us/library/cc645917.aspx? – Igor Borisenko Oct 19 '11 at 05:36
  • @user194076 - silly question, have you tried adding a trailing semicolon after the password? – JNK Oct 25 '11 at 15:00
  • What SQL Server version are you using? – Gabe Thorns Oct 26 '11 at 21:35
  • @Gabobcat, sql-server-2008-r2 – user194076 Oct 26 '11 at 21:36
  • Take a look at my answer, I think it is what you are looking for. – Gabe Thorns Oct 27 '11 at 15:46
  • Please provide the exact source of the code you are using. Not just a copy of the connection string. (You can change user name and password.) I'd like to see how you are using the connection string. – Hogan Oct 26 '11 at 21:53
  • Are you able to create an ODBC connection to the same SQL server, instance and user credentials and test it successfully? –  Oct 28 '11 at 05:12
  • Check this: http://social.msdn.microsoft.com/forums/en-US/adodotnetdataproviders/thread/a31656a9-5715-4910-ad96-fa590344a407/ and also this: http://stackoverflow.com/questions/2697503/cannot-open-database-dbname-requested-by-the-login-the-login-failed – MicSim Oct 28 '11 at 07:23
  • Does specified login has mapped user in given database? – rsc Oct 28 '11 at 07:45

9 Answers9

4

In my case, I had a connection string working with SQL Server 2008 R2, but after updating to SQL Server 2014, I received the mentioned error. Here is what my original connection string was like:

server=.\SQLEXPRESS;database=mydb;User Id=me;Password=123

Here is the update connection string that works with 2014:

Integrated Security=SSPI;Data Source=.\SQLEXPRESS;Database=mydb;User Id=me;Password=123
user8128167
  • 6,929
  • 6
  • 66
  • 79
  • Adding *Integrated Security=SSPI;* to my connection string fixed it for me using SQL 2014 as well – blizz May 15 '16 at 16:39
  • Doesn't adding Integrated Security just cause it to use Windows Authentication instead of the provided credentials? http://stackoverflow.com/questions/1229691/difference-between-integrated-security-true-and-integrated-security-sspi – Chris Nevill Mar 09 '17 at 12:02
  • That appears to be the case except for CE: https://www.connectionstrings.com/sql-server-2012/ – user8128167 Mar 09 '17 at 23:19
1

Change your connection string to:

Provider=SQLNCLI10;SERVER=MYPC\MSSQLSERVER;DataTypeCompatibility=80;Database=mydb;User Id=me;Password=123

It worked for me. Try to use IP if server is remote or (local) if it is on the same machine.

Hope this helps.

Gabe Thorns
  • 1,426
  • 16
  • 20
  • @user194076 - Have you tried Gab's answer here? I've encountered login failures like this when the Provider in the connection string was set incorrectly. – Carth Oct 28 '11 at 18:28
0

Try in this format as below.

strConnection ="Driver={SQL Server};Server=serverName;Database=DatabaseName;Uid=userID;Pwd=Password;"

Thanks
Jinesh Jain
Jinesh Jain
  • 1,232
  • 9
  • 23
  • Now it says the following: Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified – user194076 Oct 19 '11 at 14:36
  • Provider=SQLOLEDB;Data Source=MYPC\MSSQLSERVER;Initial Catalog=mydb;database=mydb;User Id=me;Password=123 please remove database=mydb; from your string because initialcatalog and database is same thing – Jinesh Jain Oct 20 '11 at 07:40
  • The same thing. Does not help :( – user194076 Oct 20 '11 at 23:42
  • can you able to login to SQL server management by same credential mentioned as above ? because this same connection string is working with my credential so in connection string there is no Problem. – Jinesh Jain Oct 21 '11 at 05:25
  • Yes I can connect to SSMS both with windows and user auth. – user194076 Oct 23 '11 at 17:26
  • Can you adjust this as a window authentication for just testing and can see is this works or not – Jinesh Jain Oct 24 '11 at 11:55
  • I did. I tried Integrated Security = SSPI, and it still does not work. the same error. I wrote about this in my post. – user194076 Oct 24 '11 at 16:26
  • A driver issue? Can you connect from a different machine? – SteveCav Oct 26 '11 at 21:52
0

Here is a reference of the various ways you can connect to SQL server 2005, with sample connection strings:

http://www.connectionstrings.com/sql-server-2005

Or to connect to SQL Server 2008:

http://www.connectionstrings.com/sql-server-2008

Please remember that you should have the corresponding client piece installed on the computer that is running the ASP app, that is the SQL Server native client.

Don't know which method are you using but there are two ways OLE DB applications can initialize data source objects:

IDBInitialize::Initialize 

IDataInitialize::GetDataSource (seems like you are using this one)

Both methods initialize the same OLE DB connection properties, but different sets of keywords are used.

If you are using IDBInitialize::Initialize

the keyword for userid is UID
the keyword for password is PWD
NO Provider keyword may be used
Trusted_Connection keyword may be used and should be No

If you are using IDataInitialize::GetDataSource

the keyword for userid is User ID
the keyword for password is Password
the Provider keyword is for SQL Server Native Client and it should be SQLNCLI10
the keyword for aunthentication Integrated Security you can remove it, or use SSPI only if you wish Windows authentication

I made few changes to your original connection string below, try it out:

Provider=SQLNCLI10;Data Source=MYPC\MSSQLSERVER;DataTypeCompatibility=80;Initial  Catalog=mydb;User ID=me;Password=123 

This document describes the connection string keywords for each connection method for OLE DB applications using the SQL Server Native Client when connecting to SQL Server 2008 R2.

http://msdn.microsoft.com/en-us/library/ms130822.aspx

Only You
  • 2,051
  • 1
  • 21
  • 34
0

Try switching up your User Id to

MYPC\me

Maybe adding in the domain for the User ID will help Sql server resolve permissions

Rondel
  • 4,811
  • 11
  • 41
  • 67
0

Can you log in using management studio with this user, and see the database you are trying to log into?

Perhaps there is an character encoding issue with the file that holds the connection string. Is the connection string stored as text in its own file? If so, try opening that file in Notepad++ and check what is selected in the "Encoding" menu at the top. Try changing it to UTF-8 or ANSI.

UPDATE

I just read some comments, and it sounds like you can't log in using management studio. It sounds like the Windows Authentication Mode vs SQL Server Authentication Mode is a good candidate for a root cause.

Try this:

  • Login to management studio and connect to your database using sa
  • Right-click the database server in the object explorer on the left
  • Go to the Security tab
  • Make sure you are using "SQL Server and Windows Authentication mode", not just "Windows Authentication Mode"
  • If you are currently using "Windows Authentication Mode", change it
  • Find your application user in Security > Logins
  • Right-click > Properties
  • Make sure "SQL Server authentication" is selected
  • If its not, you can try to change it, or create a new user, and make sure you select "SQL Server Authentication"
Sean Adkinson
  • 8,425
  • 3
  • 45
  • 64
0

The way should be like for example...
Provider=SQLNCLI;Server=myServerName\theInstanceName;Database=myDataBase; Trusted_Connection=yes;

(Trusted_connection just in case, that's optional I believe)

Rodolfo
  • 4,155
  • 23
  • 38
0

First, do you understand the difference between SQL Server authentication and Windows Authentication? Based on some of the comments, I'm not sure.

You state that you checked your password 100 times; did you log into SSMS using SQL Server Authentication and verify it there? My theory is that you have a SQL Server account with the same name as your Windows account, and that you're connecting into SSMS using the Windows account, and NOT the SQL account.

Stuart Ainsworth
  • 12,792
  • 41
  • 46
0

Sure your Computer name is all uppercase? I found some time ago that a name in camelCase or with spaces within can cause such behavior.

If it's not, change it adding at least one letter or the change won't be succesful.

Alfabravo
  • 7,493
  • 6
  • 46
  • 82