When using SQL Server, the most common problem you encounter is that the connection fails. Generally, there are two ways to connect to SQL Server. One is to use the client tools provided by SQL Server, such as the Enterprise Manager, query analyzer, and transaction probe; the second is to use a client program developed by the user, such as ASP scripts and vbprograms. The client program uses ODBC or ole db to connect to SQL Server. Next, we will discuss the two Connection Methods in detail how to solve the connection failure problem.
I. Client tool connection failed
When using the client tool provided by SQL Server (taking the Enterprise Manager as an example) to connect to SQL Server, the most common errors are as follows:
1. SQL Server does not exist or access is denied
ConnectionOpen (Connect ())
2. User 'sa 'Login Failed. Cause: it is not associated with a trusted SQL Server connection.
3. the timeout has expired.
The following describes how to solve the three most common connection errors.
The first error "SQL Server does not exist or access is denied" is usually the most complicated. There are many causes of the error and there are many aspects to check. Generally, there are several possibilities:
1. the SQL Server name or IP address is incorrectly spelled;
2. The server network configuration is incorrect;
3. The client network configuration is incorrect.
To solve this problem, we generally need to follow the steps below to find out the cause of the error step by step.
First, check the network physical connection:
Ping <Server IP address>
Or
Ping <Server Name>
If ping <Server IP address> fails, the physical connection is faulty. In this case, Check hardware devices, such as NICs, hubs, and routers. Another possible cause is the installation of firewall software between the client and the Server, such as ISA Server. Firewall software may block responses to ping, telnet, and so on. Therefore, when checking connection problems, we must temporarily disable the firewall software or open all closed ports.
If the ping <Server IP address> succeeds and the ping <Server Name> fails, it indicates that there is a problem with name resolution. In this case, check whether the DNS service is normal. Sometimes the client and server are not in the same LAN. At this time, you may not be able to directly use the server name to identify the server. At this time, you can use the HOSTS file for name resolution. The specific method is:
1. Use notepad to open the HOSTS file (usually in C: \ WINNT \ system32 \ drivers \ etc ).
2. Add a record corresponding to the IP address and server name, for example:
172.1610.24 myserver
You can also configure it in the SQL Server Client Network utility, which will be described in detail later.
Second, use the telnet command to check the SQL Server's working status:
Telnet <Server IP addresses> 1433
If the command is successfully executed, you can see that the cursor does not stop flashing in the upper left corner after the screen flashes. This indicates that the SQL Server is working normally and is listening for TCP/IP connections on port 1433; if the command returns an error message "unable to open the connection", it indicates that the SQL Server service is not started on the Server, or the TCP/IP protocol is not enabled on the Server, or the Server does not listen on the default port 1433 of SQL Server.