SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

  新的Sharepoint服务器上的SQL SERVER2008数据库实例需要启用远程访问,在此做个笔记以便以后查阅。
 通常如果我们没有启动远程访问服务,我们会遇到"Cannot connect to SQL-Server-Instance-Name"错误提示信息:
  错误信息的具体内容可能为 

 1.An error has occurred while establishing a connection to the server. When connecting to SQL Server 2008this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 28 – Server doesn’t support requested protocol) (Microsoft SQL Server)” 
 
2.An error has occurred while establishing a connection to the server. When connecting to SQL Server 2008this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified) (Microsoft SQL Server)”
 
3.Login failed for user ‘username‘. (Microsoft SQL Server, Error: 18456)”

  为了打开SQL SERVER2008的远程服务,我们通常需要下面四个步骤
 1. 开启SQL Server Browser service,此服务是用于侦听远程来访的服务请求并提供SQL SERVER实例信息。
 2. 打开TCP/IP protocol for SQL Server 2008,以便于远程来访
 3.(可选项)把Server Authentication 的方式改为 SQL Server and Windows Authentication. 如果你需要特定的用户连接到SQL Server,你就必须要修改此处的设置。
 4.开启SQL Server2008以及服务器防火墙的1433端口.


  具体操作步骤
A.开启SQL Server Browser service
Step 1. 启动SQL Server Configuration Manager。在操作系统桌面上点击 Start -> Programs -> Microsoft SQL Server 2008 -> Configuration Tools -> SQL Server Configuration Manager.

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

 

Step 2. 在SQL Server Configuration Manager中, 选中左侧的 SQL Server Services.在其中选中 SQL Server Browser,如果它没启动,则启动它。如果已经启动,则直接进入第Step 6.

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

Step 3. 双击 SQL Server Browser, 会跳出其 Properties 窗口. 选择一个帐号来启动SQL Server Browser Service. 此例中,我设置的是Local Service account.

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

Step 4.在SQL Server Browser的属性窗口, 进入 Service 选卡,更改Start Mode 为 Automatic. 这样,当服务器重新启动时,就会自动启动此服务。点击 OK使更改生效。

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)
  我们也可以通过修改注册表来实现此目标,具体的操作方法是:
 将HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\SQLBrowser\Start值4修改为2(即设置为自动启动),重启服务器后就会自动启动。


Step 5. 回到SQL Server Configuration Manager,右击右边窗口中的SQL Server Bowser,在弹出的菜单中选择Start,以启动此服务。

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

 

Step 6.在SQL Server Configuration Manager的左侧窗口,展开 SQL Server Network Configuration -> Protocols for SQLEXPRESS. 你会发现TCP/IP protocol的当前状态是disable的。

 SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

B. 打开TCP/IP protocol for SQL Server 2008
Step 7.右击TCP/IP,在此更改其状态为Enable.

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

Step 8.你会看到一个弹出信息窗口,要求你重启SQL Service以使更改生效。

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

Step 9.在SQL Server Configuration Manager的左侧窗口, 选择 SQL Server Services. 然后在右侧窗口中选中 SQL Server (SQLEXPRESS),右击选项,在弹出菜单中 Restart.这样SQL Server service就重启了。

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

C.(可选项)把Server Authentication 的方式改为 SQL Server and Windows Authentication
Step 10. 打开 Microsoft SQL Server Management Studio 并连接到SQL Server 2008实例,进入其Property设置,在其Security设置下修改Authentication mode。然后,照上方法重启SQL Service服务。

也可以参见我的另一短文SQL : Microsoft SQL Server-Login failed for user ‘username’解决办法

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

D.开启SQL Server2008以及服务器防火墙的1433端口.
 开启SQL Server2008的1433端口操作步骤如下:
 在操作系统桌面上All Programs -> Microsoft SQL Server 2008 -> Configuration Tools -> SQL Server Configuration Manager--展开SQL Server Netwoek Configuration-->选中 Protocol for MSSQLSERVER-- 选择它的TCP/IP属性项-->右击在弹出菜单中选择Property进入TCP/IP的属性设置,依下面内容进行设置:
IP1=> Active=Yes, Enabled=Yes,IP Address =<machine ip address>, TCP Dynamic Port=Empty, TCP Port=1433
IP2=> Active=Yes, Enabled=Yes,IP Address =127.0.0.1, TCP Dynamic Port=Empty, TCP Port=1433
IP3=> TCP Dynamic Port=Empty, TCP Port=1433
设置完成后,仍按上面方法重启SQL Server Service
在Windows Server2008中开启防火墙的1433端口方法如下:

SQL:如何为SQL SERVER2008 启用远程连接(Remote Connect)

 

网上也有用脚本来实现开启指定端口的,方法是在服务器上建一个OpenServerPort.bat,直接运行此批处理文件就行了。其脚本内容如下:

@echo =========  SQL Server Ports  ===================
@echo Enabling SQLServer 
default instance port 1433
netsh firewall 
set portopening TCP 1433 "SQLServer" 
@echo Enabling Dedicated Admin Connection port 
1434
netsh firewall 
set portopening TCP 1434 "SQL Admin Connection" 
@echo Enabling conventional SQL Server Service Broker port 
4022  
netsh firewall 
set portopening TCP 4022 "SQL Service Broker" 
@echo Enabling Transact
-SQL Debugger/RPC port 135 
netsh firewall 
set portopening TCP 135 "SQL Debugger/RPC" 
@echo 
=========  Analysis Services Ports  ==============
@echo Enabling SSAS Default Instance port 
2383
netsh firewall 
set portopening TCP 2383 "Analysis Services" 
@echo Enabling SQL Server Browser Service port 
2382
netsh firewall 
set portopening TCP 2382 "SQL Browser" 
@echo 
=========  Misc Applications  ==============
@echo Enabling HTTP port 
80 
netsh firewall 
set portopening TCP 80 "HTTP" 
@echo Enabling SSL port 
443
netsh firewall 
set portopening TCP 443 "SSL" 
@echo Enabling port 
for SQL Server Browser Service''Browse' Button
netsh firewall set portopening UDP 1434 "SQL Browser" 
@echo Allowing multicast broadcast response on UDP (Browser Service Enumerations OK)
netsh firewall 
set multicastbroadcastresponse ENABLE 


 

转载于:https://www.cnblogs.com/wsdj-ITtech/archive/2011/05/06/2038685.html