A small trap for escape character "\", character escape trap

Source: Internet
Author: User

A small trap for escape character "\", character escape trap
I. Problem Introduction

I haven't used c # to connect to the database program for a long time. However, I found some information on the Internet and wrote it out. However, when I debug the preliminary program, I found it on con. open () is always an error,The error message returned when the database instance name cannot be found or the remote connection fails.Error40.

The error is as follows:

 

II. Environment Introduction

1. My database is sqlserver2008 and the development environment is vs2013 and. net4.0.

2. My database is installed with a named instance. Therefore, when writing a database connection string, the server name should be [computer name \ data instance name]

The database connection character is:

When a connection error is found, I thought it was an error caused by the incorrect environment of my sql2008 and vs2013. Later I opened the previous project and attached the database, change the data connection string and the error is the same.

Iii. troubleshooting

After finding an error for more than an hour, I found that when I used to write SQL connection characters, I added one before.@Symbol, because my string contains characters"\"If it is not added, an error is prompted, So I add it every time. However, during the last system reinstallation, the Instance name was changed to the name starting with "t. Then[\ T]This is a table character, so it is not an error, it is a correct use of escape symbols, because there is no error, it will forget to add"@".

The solution is to add @ in front of the string @.

Note:

When writing SQL connection strings or writing file paths on the windows platform, remember to add @ characters in front of them to form a good habit. Let's go to the trap.

Related Article

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.