SQL Server does not exist or access is denied

Source: Internet
Author: User
Tags builtin sql server driver mssqlserver odbc sql server driver
When using SQL Server, the most common problem is that the connection fails. Generally, there are two ways to connect to SQL Server. One is to use Client tools provided by SQL Server Such as the Enterprise Manager, query analyzer, and transaction probe. Self-developed clientProgram 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.

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 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 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 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.

Ping IP Address
Ping Domain Name
Telnet IP address 1443
 

--Ms SQL Server database in Win2000 and 2003 above is generally easy to use, do not have to play SP4 and Sp3 patch.Patching is because SQL Server is prone to the worm virus (symptom: When you access the Internet, you will not be able to access the Internet)

However, if you are using a JDBC connection (such as the landlord), you must first check whether the JDBC file (Three jar packages) is installed on webserver (such as Tomcat ), then check whether you have set the mixed logon mode. If both of them are done, they will be useful (except WINXP ).

If it is Windows XP, you need to check more information. It seems that you must install patches at or above the SP3 level, install the sqlserver Personal Edition, install the JDBC package, and set it to the hybrid mode, the most important thing is to look at your ownCodeWrite to none, haha!

-- If you are a WINXP user, you may not succeed even if all of the above operations are done!

 

-- The operating system is Windows XP, and the SQL Server 2000 database must be patched with SQL Server 2000 sp3. Otherwise, "exception in thread" Main "Java will be reported when you connect to the database. SQL. sqlexception: [Microsoft] [sqlserver 2000 driver for JDBC] Error establishing socket."

-- In the past, Windows 2000 was used during development. Later, the client machine was WINXP and the Error establishing socket was always reported. Later, I checked that it was a problem with the WINXP SP patch, fix SQL Server 2000 SP3 in the database.

 

-- Install the SP3 or SP4 patch. I will use it now.

-- I have encountered this problem, but after I reinstall SQL Server, I can connect to the database. It seems to be the cause of the database.

-- Install the SP3 patch of sqlserver and set the users logging on to the database to the Hybrid Authentication mode.
In this way, I use XP, and I can use these two steps.

-- I have already connected. Thank you!

 

 

 

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.