SQL Server does not exist or access is denied)

Source: Internet
Author: User
Tags builtin sql server driver mssqlserver odbc sql server driver

Such as the Enterprise Manager, query analyzer, and transaction probe. The second is to use the userSelf-developed client programSuch 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.

  1. "SQL Server does not exist or access is denied"

  

(Figure 1)

"SQL Server does not exist or access is denied" errors are usually the most likely to occur, because there are many causes of errors, so there are also many aspects to check.

Generally, there are several possibilities:

1. network connection problems;

2. SQL Server problems;

3. server network configuration problems;

4. Client network configuration problems.

First, check the network connection:

1. ping the Server IP address. First, shut down the firewall on the server and client to prevent the firewall software from blocking the ping and telnet responses. Then start to ping the Server IP address. If the ping server ip address fails, the physical connection is faulty. In this case, check the hardware devices, such as the NIC, HUB, and vro.

2. ping the server name. If it fails, the name resolution is incorrect. Check whether the Netbuis protocol is installed and the DNS service is normal.

Second, use the telnet command to check the operating status of the SQL Server. 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 Server has not started the SQL Server service, or the Server has not enabled the TCP/IP protocol, or the Server does not listen on the default port 1433 of SQL Server.

Finally, we need to check the network configurations of the server and client. The server checks whether the named pipe is enabled, whether the TCP/IP protocol is enabled, and so on. We can use the Server network tools provided by SQL Server for inspection.

Click program> Microsoft SQL Server network usage tool. After the tool is opened, You can see which protocols are enabled on the Server in "General, by default, the named pipe and TCP/IP protocol are enabled. Click "properties" in the TCP/IP protocol to check the default port settings of the SQK Server service. Generally, we use the default port 1433 of SQL Server. If you select "Hide server", it means that the client cannot see this server by enumerating the server. This protects the server, but does not affect the connection.

  

(Figure 2)

  

(Figure 3)

Next we will go to the client to check the network configuration of the client. We can also use the client network provided by SQL Server to perform the check. The difference is that this tool is run on the client this time. Click program> Microsoft SQL Server Client. After you use the tool to open the tool, you can see which protocols are enabled on the client in "General. Similarly, we need to enable the named pipe and TCP/IP protocol. Click TCP/IP protocol and select "properties" to check the default connection port settings of the client. The port must be consistent with the server.

  

(Figure 4)

Through the above checks, the first error can be basically ruled out.

1.2:"Unable to connect to the server, user xxx Login Failed"

  

(Figure 5)

This error occurs because SQL Server uses"Authentication Method for Windows onlyTherefore, you cannot use the SQL Server login account (such as sa) to connect. The solution is as follows:

1. Use the enterprise manager on the Server side and select "use Windows Authentication" to connect to SQL Server;

2. Expand "SQL Server group", right-click the name of the SQL Server, select "properties", and then select the "Security" tab;

3,Under "authentication", select "SQL Server and Windows";

4. Restart the SQL Server service.

In the preceding solution, ifFailed to connect to SQL Server using Windows AuthenticationTo solve this problem by modifying the registry:

1. Click "start" "Run", enter regedit, and press enter to enter the Registry Editor;

2. Expand the registry items in sequence and navigate to the following registry: [HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSSQLServer];

3. Find the name "LoginMode" on the right of the screen and double-click to edit the double-byte value;

4. Change the original value from 1 to 2 and click "OK ";

5. Close the Registry Editor;

6. Restart the SQL Server service.

In this case, you can successfully use sa to create an SQL Server registration in the Enterprise Manager, but you still cannot connect to SQL Server in Windows Authentication mode. This is because there are two default login users in SQL Server:

BUILTIN \ Administrators
<Machine Name> \ Administrator is deleted.

To restore these two accounts, you can use the following methods:

1. Open the Enterprise Manager, expand the server group, and then expand the server;

2. Expand security, right-click logon, and click New logon ";

3. In the Name box, enter BUILTIN \ Administrators;

4. On the "server role" tab, select "System Administrators ";

5. Click "OK" to exit;

6. Use the same method to add <machine Name> \ Administrator to log on.

Note:

The following registry key:

The value of HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSSQLServer \ LoginMode determines the Authentication mode that SQL Server will adopt.

1. indicates that the "Windows Authentication" mode is used;

2. hybrid mode (Windows Authentication and SQL Server Authentication) is used ).

1.3:Prompt connection timeout

  

(Figure 6)

If a third error occurs, it generally indicates that the client has found this server and can be connected. However, an error occurs because the connection time exceeds the allowed time. This situation is rare. Generally, when a user runs the enterprise manager on the Internet to register another server that is also on the Internet and has a slow connection, the above timeout error may occur. In some cases, the LAN may cause such errors.

To solve this problem, you can modify the connection timeout settings of the client. By default, the timeout setting for registering another SQL Server through the Enterprise Manager is 4 seconds, and the query analyzer is 15 seconds.

The procedure is as follows:

Settings in Enterprise Manager:

1. In Enterprise Manager, select "Tools" from the menu, and then select "options ";

2. In the displayed "SQL Server Enterprise Manager properties" window, click the "advanced" tab;

3. Enter a large number, such as 30, in the "Login timeout (seconds)" box on the right under "connection settings.

Query settings in Analyzer:

Click "Tools"-> "options"-> "connection"; Set logon timeout to a large number, and set connection timeout to 0.

2. Application connection failed

The preceding three error messages occur in the client tool provided by SQL Server. In the application, we also encounter similar error messages, for example:

Microsoft ole db Provider for SQL Server (0x80004005)
[DBNETLIB] [ConnectionOpen (Connect ().] Specified SQL server not found.
Microsoft ole db Provider for SQL Server (0x80004005)

User 'sa 'Login Failed. Cause: it is not associated with a trusted SQL Server connection.

Microsoft ole db Provider for ODBC Drivers error '20140901 '.
[Microsoft] [odbc SQL Server Driver] timeout has expired.

If a Connection timeout error occurs, you can modify the timeout settings of the Connection object in the program and then open the Connection. For example:

<%
Set Conn = Server. CreateObject ("ADODB. Connection ")
DSNtest = "DRIVER = {SQL Server}; SERVER = ServerName; UID = USER; PWD = password; DATABASE = mydatabase"
Conn. Properties ("Connect Timeout") = 15' in seconds
Conn. open DSNtest
%>

If you encounter a query timeout error, you can modify the timeout setting of the Recordset object in the program and then open the result set. For example:

Dim cn As New ADODB. Connection
Dim rs As ADODB. Recordset
...
Cmd1 = txtQuery. Text
Set rs = New ADODB. Recordset
Rs. Properties ("Command Time Out") = 300
'The unit is second. If it is set to 0, there is no limit.
Rs. Open cmd1, cn
Rs. MoveFirst
...

This article focuses on the common connection failure errors that most users encounter when using SQL Server. It focuses on the use of SQL Server Client tools and applications developed by users, how to diagnose and solve connection failure errors. After reading this article, I believe that every reader will have a comprehensive and in-depth understanding of the connection principle, authentication methods, and application development of SQL Server.

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.