SQL Server connection failure error analysis and exclusion (2)

Source: Internet
Author: User
Tags builtin connect odbc sql server driver mssqlserver sql odbc sql server driver ole
   second, "Unable to connect to the server, the user XXX login failed"





This error occurs because SQL Server uses Windows only authentication, so users cannot connect using SQL Server's logon account, such as SA. The workaround looks like this:



1. Use Enterprise Manager on the server side and select "Use Windows Authentication" to connect to SQL Server;



2, expand the "SQL Server group", the right mouse click on 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 above workaround, if you failed to connect to SQL Server using Windows authentication in step 1th, you can fix the problem by modifying the registry:



1, click "Start" "Run", input regedit, enter Registry Editor;



2, expand the key in turn, browse to the following registry: [HKEY_LOCAL_MACHINE\Software\Microsoft\MSSqlserver\MSSqlServer];



3, on the right side of the screen to find the name "LoginMode", double-click Edit Double byte value;



4, change the original value from 1 to 2, click "OK";



5, close Registry Editor;



6. Restart the SQL Server service.



At this point, users can successfully use SA to create new SQL Server registrations in Enterprise Manager, but still cannot use Windows Authentication mode to connect to SQL Server. This is because there are two default login users in SQL Server:



BUILTIN\Administrators
< machine name >\administrator was deleted.



To recover both accounts, you can use the following methods:



1, open Enterprise Manager, expand the server group, and then expand the server;



2, expand Security, right-click Login, and click New Login;



3, in the "Name" box, input BUILTIN\Administrators;



4. In the Server Roles tab, select System Administrators;



5, click "OK" exit;



6, use the same method to add < machine name >\administrator login.



Description



The following registry key:



The value of Hkey_local_machine\software\microsoft\mssqlserver\mssqlserver\loginmode determines what authentication mode SQL Server will take.



1, the use of "Windows Authentication" mode;



2. Represents the use of mixed mode (Windows authentication and SQL Server authentication).


   third, prompt connection timeout




If you encounter a third error, it is generally stated that the client has found the server and can connect, but that an error occurs because the connection time is greater than the allowed time. This is a rare situation, which typically occurs when a user runs Enterprise Manager on the Internet to register another server that is also on the Internet, and is a slow connection, which can cause more than one timeout error. In some cases, this error can also be caused by network problems in the LAN.



To resolve such an error, you can modify the client's connection timeout setting. By default, the timeout setting for registering another SQL Server through Enterprise Manager is 4 seconds, and the Query Analyzer is 15 seconds.



The specific steps are:



Settings in Enterprise Manager:



1, in Enterprise Manager, select the "Tools" on the menu, and then select "Options";



2, in the pop-up SQL Server Enterprise Manager Properties window, click on the "Advanced" tab;



3. Enter a larger number, such as 30, in the box to the right of login timeout (seconds) under Connection settings.



Settings in Query Analyzer:



Click "Tools"-> "Options"-> "Connect"; Set the logon timeout to a larger number, and the connection timeout to 0.



  fourth. Application connection Failure



All three of the above error messages occur in SQL Server's own client tools, and similar error messages are encountered in the application, such as:



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. Reason: not associated with a trusted SQL Server connection.



Microsoft OLE DB Provider for ODBC Drivers error ' 80004005 '.
[Microsoft] The [ODBC SQL Server Driver] timeout has expired.



If you encounter a connection timeout error, we can modify the timeout setting for 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, we can modify the timeout setting for 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
' Same in seconds, if set to 0 means unrestricted
Rs. Open Cmd1, CN
Rs. MoveFirst
. . .



 fifth. Summary



This article focuses on how to troubleshoot and troubleshoot connection failures in both cases of using SQL Server client tools and user-developed applications for the common failure of connections that most users use during SQL Server. After reading this article, I believe that each reader will have a more comprehensive and in-depth understanding of how SQL Server works, how to authenticate, and how to develop applications.







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.