How to solve an error when using sqlcmd to connect to the database

Source: Internet
Author: User

I. Problems
When using the sqlcmd client tool to connect to data, the following error occurs:
C: \> sqlcmd
HResult 0x2, level 16, status 1
Named pipeline provider: connection to SQL Server cannot be opened [2].
Sqlcmd: Error: Microsoft SQL Native Client: Connection established to the server
The fact that remote connection is allowed may cause failure ..
Sqlcmd: Error: Microsoft SQL Native Client: the logon timeout has expired.

Ii. Cause
1. The network protocol and related ports are not enabled
2. No identity authentication method is specified for logon.

Iii. Solution Process
1. enable the network protocol
SQL Server Configuration Manager-> network Configuration-> Protocol
TCP/IP attributes
Keep activity status --> 30000
All listeners --> NO
No latency --> NO
Enabled --> Yes

IP address
IP address --> Database Server IP Address
Dynamic TCP port --> not filled
TCP port --> 1433
Activity --> Yes
Enabled --> Yes

2. Connect to the database
(1) Use Windows Identity Authentication: C: \> sqlcmd-E-S \ Instance name-d master
(2) use SQL SERVER Identity Authentication: C: \> sqlcmd-S \ Instance name-d master-U user name-P Password

4. Use SQLCMD
1. View help: C :\> sqlcmd -?
2. Execute SQL statements
C: \> sqlcmd-E-S \ WWDD-d master
1> use www
2> go
The database context has been changed to 'www '.
1> select * from guangd;
2> go

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.