1

I know this is an answered question , however I have tried all the steps mentioned like:

  1. In SQL Configuration manager have Enabled TCP/IP,Shared Memory and Named Pipes.
  2. Restarted the SQLSERVER
  3. In Services.msc I have restarted SQLSERVER and SQL Server Agent
  4. Added port 1433 in firewall's Inbound rule
  5. Restarted PC number of times
  6. Even Registered Local Server in SQL Server Management tools

I can open SQL Server Management tools
It was working fine and now its not. However I am able to login , then I cannot do any work on it, it gives me an error as :
enter image description here

Tried all the steps mentioned in the accepted answer HERE I have some other application accessing same SQL Server and they are working fine.
My Connection string :

public SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Database=RMS_EXPRESS;Integrated Security=True;User Id=sa;Password=xxxxxx");

I also tried with the following connection string

Data Source=.;Database=RMS_TS1;Integrated Security=False;User Id=sa;Password=xxxxxxx

It gave me an error. "Login Failed for User 'sa'"

My application and Database are on the same PC

So , please help. Thanks

Cleptus
  • 3,446
  • 4
  • 28
  • 34
mark
  • 623
  • 3
  • 21
  • 54
  • Possible duplicate of [How do I fix the error 'Named Pipes Provider, error 40 - Could not open a connection to' SQL Server'?](https://stackoverflow.com/questions/9945409/how-do-i-fix-the-error-named-pipes-provider-error-40-could-not-open-a-connec) – Dzmitry Paliakou Sep 12 '18 at 12:03

2 Answers2

1

You can not setup in your connection string both Integrated Security=true and User Id=sa;Password=xxxxxx

Integrated Security = true means it is using windows credentials (of the user the application is running into). A database connection cannot use both windows AND SQL Server authentication.

You should either:

  • Use Integrated Security=true and do not specify User Id nor password. This would use windows authentication.
  • Use Integrated Security=false or remove it althogether and specify both User Id and Password. This would use SQL Server user/password authentication.

Besides that, there was an adittional problem, originally you put Data Source=.\SQLEXPRESS but had to access default instance via Data Source=. which caused that error.

Cleptus
  • 3,446
  • 4
  • 28
  • 34
  • You're completely right but this will certainly not cause the error mentioned – Nick.Mc Sep 12 '18 at 13:26
  • This is strange. In the question mark says `"Data Source=.\SQLEXPRESS;"` but in his last comment says `"Data Source=.;"` Maybe he should read about sql server instances, that could really cause the error mentioned. – Cleptus Sep 12 '18 at 15:05
  • @bradbury9 it worked I put in `Data Source=.;Database=RMS_TS1;Integrated Security=True` Thanks – mark Sep 12 '18 at 15:43
  • @Nick.McDermaid Edited the answer to add the second problem, the one causing the error mentioned. – Cleptus Sep 12 '18 at 17:55
  • So after all that... there was no technical issue. The problem was that the wrong hostname was in the connection string. – Nick.Mc Sep 12 '18 at 23:33
  • @Nick.McDermaid it was same earlier it worked,suddenly it was not connecting. Dont know what happened what caused it – mark Sep 13 '18 at 06:38
  • I'm not trolling or arguing here, just saying it would appear then that this answer did not solve your question. That's fine. There's probably enough value in this question to just keep it this way. – Nick.Mc Sep 13 '18 at 06:52
  • @Nick.McDermaid If you think it can be improved changing the order of the paragraphs and putting more enphasis on the last one (the one that addresses the instance name, because the hostname was ok) feel free to submit an edit. – Cleptus Sep 13 '18 at 07:37
0

Allow Remote Connections enabled under Connections in SQL Server Properties.