SQL database instance name not found or remote connection failed and display error Error40 reason and resolution _MSSQL

Source: Internet
Author: User

A solution that shares the SQL database instance name caused by the character "\" Escape or fails the remote connection and displays an error ERROR40:

First, the problem introduction
A long time no use C # to connect the database program, however, found some information on the internet, basically still write 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 could not be found, or the remote connection failed, the error displayed is Error40.

The error is as follows:

Second, the environment introduction
1, my database is sqlserver2008, using the development environment is vs2013,.net4.0

2, my database installation of the named instance, so when writing the database connection string, the server name should be "computer name \ Data Instance Name"

The database connection characters are:

When I found the connection error, I thought it was my sql2008 and vs2013 environment wrong, then opened the previous project, the database attached, change the data connection string, found that the error is the same.

Iii. Solutions
One-hour error found the last time you wrote a SQL connection character, you would add a @ symbol, because I have the character "\" in the string, and if not, I will add it every time. But the last time the system was reset, the named instance was changed to the name beginning with the "T" character. Then "\ t" this representation is a table character, so it is not an error, it is an escape symbol in the correct use of the situation, because there is no error, also forget to add "@".

The solution is to precede the string with a @.

Attention

When writing a SQL connection string, or when writing a file path on the Windows platform, remember to precede it with the @ character and develop good habits.

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.