The SQL database instance name cannot be found or the remote connection fails, and the error error40 cause and solution are displayed. sqlerror40

Source: Internet
Author: User

The SQL database instance name cannot be found or the remote connection fails, and the error error40 cause and solution are displayed. sqlerror40

Share the solution that the sqldatabase Instance name cannot be found due to the Escape Character "\" or the remote connection fails and the error error40 is displayed:

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. If the database instance name cannot be found or the remote connection fails, the error is 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 incorrect environment of sql2008 and vs2013. Then I opened the previous project, appended the database, and changed the data connection string, the error is the same.

Iii. Solution
After finding an error for more than an hour, I found that when I used to write SQL connection characters, I added an @ symbol to the front, because my string contains the character "\". 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] indicates that it is a table operator, so it is not an error, it is a correct use of escape symbols, because there is no error, I forgot to add.

The solution isAdd @ to the front of the string @.

Note:

When writing SQL connection strings or writing file paths on windows platforms, remember to add @ characters to the front to form a good habit.

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.