-1

I'm getting this error whenever I run my code:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

I tried using the solutions provided in the internet, however nothing seems to work. Like the one using the windows services, I can't find the "SQL SERVER (NAME)" in the list of Services Local.

SqlConnection connect = new SqlConnection (@"Data Source = DESKTOP-766P0MJ; Initial Catalog = LoginCredentials; Integrated Security = True");
SqlDataAdapter adapt = new SqlDataAdapter("SELECT COUNT(*) FROM LoginCredentials where username = '" + txtbox_username.Text + "' AND password = '" + txtbox_password.Text + "'", connect);

DataTable dt = new DataTable(); //this is creating a virtual table  
adapt.Fill(dt);

if (dt.Rows[0][0].ToString() == "1")
{
    /* I have made a new page called home page. If the user is successfully authenticated then the form will be moved to the next form */
    this.Hide();
    new InternRequest().Show();
}
else
    MessageBox.Show("Invalid username or password");
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • this is a default name in windows services `SQL Server (MSSQLSERVER)`, found it and check it shoud start. – hassan.ef Apr 28 '19 at 05:36
  • couldn't find it in the windows services – Camille Apr 28 '19 at 05:38
  • you dont have any sql server service in windows service? – hassan.ef Apr 28 '19 at 05:42
  • Possible duplicate of [Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?](https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci) – Masoud Keshavarz Apr 28 '19 at 05:50
  • @MasoudKeshavarz solutions stated in that thread doesn't work in my case, i tried it. – Camille Apr 28 '19 at 13:18
  • If there is no `SQL Server` in services, you haven't installed sql server ENGINE. Do you have `SQL Server Management Studio` on your machine? You can see Engine name on it in a drop down list at first before you connect to it. – Masoud Keshavarz Apr 29 '19 at 05:43

2 Answers2

0

If your sql server service is start and you have this error again then start another sql server service that name is SQL Server Browser and when you run sql server management studio in the server name you can select Browse for more and in Database Engine show your instance name of sql server click on it and connect it and also check your username and password for connection.

hassan.ef
  • 1,300
  • 2
  • 11
  • 19
0

open run and type services.msc. The services window will open . In that window find MSSQLSERVER and its related files. Start it or you may restart it if if it is started.

Rupak
  • 409
  • 1
  • 3
  • 18