Connection SqL2005 Database error resolution and escape characters in C #

Source: Internet
Author: User
sql|sql2005| Error | resolution | data | database

An error occurred while establishing a connection with SQL2005 in C #:
An error occurred while establishing a connection to the server. When you connect to SQL Server 2005, this failure may be caused by SQL Server not allowing remote connections under the default settings. (provider: Named pipe provider, error:40-cannot open a connection to SQL Server)

Find information from the Start menu, bring up the SQL Server perimeter application configurator in the Configuration tool. Then click the Services and connections perimeter configuration, select the database instance (default is "SQLEXPRESS", select Remote connection for the DB engine "Local and remote connections (with TCP/IP)" In this way to open remote connections to SQL Server 2005 (not allowed by default). ", but can not be effectively resolved, after many tests found that the original connection string of the server name error may also appear above error prompts. The correct connection string should be in the following format:

SqlConnection con=new SqlConnection ("Data source= server name \\sqlexpress;initial catalog= database name; User Id=sa; password= password; ");

Remember to use the escape character "\ \" between the "server name" and "SqlExpress" here.

C # Escape characters

\ n Carriage return line wrap
\ t jumps horizontally to the next tab position
\v Vertical Jump
\b Backspace
\ r Carriage Return
\f Walk Paper Change page
\ backslash character "\"
\ ' Single quote character
\a Ringing
\DDD the characters represented by the 1~3 bit octal number
\xhh the character represented by the hexadecimal number of 1~2 digits



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.