Can't connect to SQL Server database: Login failed for user 'sa''

Rob picture Rob · Dec 5, 2011 · Viewed 20.1k times · Source

I can't simply connect to my database because of this error

Login failed for user 'sa'

Consider these lines of code:

SqlConnection conn = new SqlConnection("Data Source=arohbi;Initial Catalog=SPADA_FIS;Persist Security Info=True;User ID=sa;Password=p@ssword");
conn.Open();

After the execution of conn.Open() I got this weird error message

Login failed for user 'sa'.

Last time I used this setup and connection string and it work perfectly but one day when I try to connect this message is the only response. Still I manage to connect using management studio. The connection from the serverdatabase to my local machine work perfectly. Anyone guys knows the answer.

Things get worst this time. Take a look at these images: enter image description here

enter image description here

I used same connection string on both sqlconnection but i was confuse why the other one failed?

Connection string used on both:

Data Source=arohbi;Initial Catalog=SPADA_FIS;Persist Security Info=True;User ID=espada;Password=p@ssword

Answer

competent_tech picture competent_tech · Dec 5, 2011

There are a three primary reasons that I can think of off the top of my head that would cause this:

1) The sa user's password has expired or is different than what you have specified.

2) The sa user has been disabled, either by being denied permission to connect to the database engine or having the login disabled.

3) Your instance of SQL server is not configured for SQL authentication.