3

First of all i search answer on similar question I try:Developer Command Propmpt and this: Cannot open database "test" requested by the login. The login failed. Login failed for user 'xyz\ASPNET' I even formatted my pc. But still i have this problem. For long time my application connects to local MSSQl Server without any problems. But in one moment i decide to delet my database using Server Menager. And this start to happend. my C# code to connect(it works before I decide to delete database, and replaced it):

using (SqlConnection con = new SqlConnection(@"Server=tcp:DESKTOP-56F50SS;Database=Test;
User ID=sa;Password=Temptemp;Trusted_Connection=False;Encrypt=False;"))
Jayasurya Satheesh
  • 7,826
  • 3
  • 22
  • 39
Martsan
  • 31
  • 2
  • Your `con.open()` was successfull or failed? – Tuan Zaidi Jan 25 '18 at 03:50
  • 2
    You probably didn't recreate the proper user/user permissions in the test database after you dropped it and recreated it. – ColdSolstice Jan 25 '18 at 04:17
  • @TuanZaidi before I deleted database con.open() works perfectly fine – Martsan Jan 25 '18 at 06:46
  • Then the problem is on you SQL Server. Make sure user sa have right access to database and TCP/IP was enable in SQL Configuration. – Tuan Zaidi Jan 25 '18 at 06:53
  • @Tuan Zaidi I do not have this option in my Configuration Manager, I try configure my TCP/IP by method discribe by Revathi Vijay(answer below) and i have only this option https://ibb.co/fMihyb :( – Martsan Jan 25 '18 at 07:25
  • Based on your pictures, server name should be `DESKTOP-56F50SS\MSSQLSERVER` – Tuan Zaidi Jan 25 '18 at 07:36

2 Answers2

0

Looks like we were unable to set the permission on the TCP/IP.Plese check the permission for TCP/IP.

To enable the TCP/IP network protocol

Start SQL Server Configuration Manager. Click Start, point to All Programs, and click Microsoft SQL Server. Click Configuration Tools, and then click SQL Server Configuration Manager.

In SQL Server Configuration Manager, in the console pane, expand SQL Server Network Configuration.

In the console pane, click Protocols for .

In the details pane, right-click TCP/IP, and then click Enable.

In the console pane, click SQL Server Services.

In the details pane, right-click SQL Server (), and then click Restart, to stop and restart the SQL Server service.

Revathi Vijay
  • 1,238
  • 1
  • 13
  • 25
0

I had the same issue with a copied database and it due to my user didn't have the correct privileges to connect to the Database.

1) Right click to the Database you want to connect and select properties.

2) At the Permissions select the user sa and down to the Permission for sa Grant the permission Connect to your user.

Also this answer could help you.

Anastasios Selmani
  • 3,579
  • 3
  • 32
  • 48
  • 1
    The `sa` account *is* the dba and should have permissions to connect to anything. The problem in your case was that the database came with permissions for a *different* `sa` account. In the OP's case though, even the connection string is wrong – Panagiotis Kanavos Jul 25 '18 at 15:18
  • My actual case had to do with a different user than the sa that wasn't configured right. So maybe at some point the permissions of the sa were not right from some error in the configuration. – Anastasios Selmani Jul 25 '18 at 15:32