Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 703
Rob Avatar asked Jan 18 '23 03:01

Rob


1 Answers

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.

like image 98
competent_tech Avatar answered Jan 22 '23 13:01

competent_tech