A small trap about the character "\" escape

Source: Internet
Author: User
I. Introduction of the problem

A long time did not use C # to connect the database program, but found some information on the internet, basically still written out, but debugging the initial completion of the program, but found in Con.open () This method is always wrong, said that the database instance name can not be found, or remote connection failure, the display error is error40.

The error is as follows:

Ii. Introduction of the environment

1, my database is sqlserver2008, the development environment used is vs2013,.net4.0

2. My database installation takes a named instance, so the server name should be "computer name \ Data instance name" When writing the database connection string

The database connection characters are:

When I found the connection error, I thought it was my sql2008 and vs2013 the wrong environment caused by the error, I will open the previous project, attach the database, change the data connection string, found that the error is the same.

Third, error resolution

I've been looking for one hours. Error finally found that the previous write SQL connection character before the previous will add an @ symbol, because I have the character string "\", if not added will prompt error, so I will add every time. But the last time the system was re-installed, the named instance was changed to the name beginning with the "T" character. Then "\ t" This expression is a table character, so it is not an error, itself is an escape symbol of the correct use of the occasion, because there is no error, also forgot to add "@" .

The solution is to precede the string with an @.

Attention

Write the SQL connection string, or the Windows platform to write the file path when you remember to add the @ character, to form a good habit, let the small trap go to hell.

A small trap about the character "\" escape

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.