1

I want to connect to database with this connection string

SqlConnection connection = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename="C:\Users\4L46D\Documents\Visual Studio 2013\Projects\create table\create table\Database1.mdf";Integrated Security=True");

but I get the following error: get red line on address of database file:

AttachDbFilename="C:\Users\4L46D\Documents\Visual Studio 2013\Projects\create table\create table\Database1.mdf

enter image description here

Could you please help to how write the connection string?

solution : use @ before first double quotation(") and delete " from database path . use like this :

SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\4L46D\Documents\Visual Studio 2013\Projects\create table\create table\Database1.mdf;Integrated Security=True");
5
  • i just copy connection string and paste to sqlconnection().i have upload the picture. Commented Apr 26, 2020 at 20:35
  • Please add your error as text not image. Commented Apr 26, 2020 at 21:11
  • red line on address of database file (syntax error)AttachDbFilename="C:\Users\4L46D\Documents\Visual Studio 2013\Projects\create table\create table\Database1.mdf Commented Apr 26, 2020 at 21:57
  • Edit directly into your question. Commented Apr 26, 2020 at 21:57
  • How can i define the address of database file in connection string? Commented Apr 26, 2020 at 22:00

1 Answer 1

1

To use inverted commas with in string. you need to escape character with backslash i.e (\)

SqlConnection connection = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=\"C:\\Users\\4L46D\\Documents\\Visual Studio 2013\\Projects\\create table\\create table\\Database1.mdf\";Integrated Security=True");


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

2 Comments

Do you found this answer useful ?
No .not work for me .thnx anyway .the solution added the post

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.