0

This is my connection string

I have added double \\ for the unrecognized escape sequence in vs 2019

SqlConnection db = new SqlConnection("Server=localhost\\DESKTOP-8QL52AL\\ASADI; Database=atm;  Integrated Security=True;");
db.Open();

Error at line -26 check your server name or check your SQL Server is configured for remote connections

SQL SERVER CONNECTION IMAGE

1
  • You have given a host twice in the connection string. Remove either one. Commented Jun 21, 2020 at 13:58

3 Answers 3

2

You server/instance name is all wrong:

"Server=localhost\\DESKTOP-8QL52AL\\ASADI;

You can either have

  1. just the server name (or IP address) when connecting to the default, unnamed instance on your machine

     Server=DESKTOP-8QL52AL
    
  2. or you can have the server name and an instance name, if you're connecting to a named instance

     Server=DESKTOP-8QL52AL\\ASADI
    

And in both cases, you can replace the actual physical machine name with localhost to connect to the local machine (without specifying its explicit name):

    Server=localhost
    Server=localhost\\ASADI

but you CANNOT have localhost AND your explicit machine name DESKTOP-8QL52AL in a single connection string - that just doesn't make any sense and isn't supported.

Sign up to request clarification or add additional context in comments.

Comments

0

If the SQL server is on the local machine and you only have 1 sql instance installed

"Server=localhost; Database=atm; Integrated Security=True;"

if its SQL EXPRESS use

"Server=localhost\SQLEXPRESS; Database=atm; Integrated Security=True;"

Comments

0

Basic Sql Server connection string syntax:

connetionString="Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"

If you have a named instance of SQL Server, you'll need to add that as well.

"Server=localhost\sqlexpress"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.