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