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