简体   繁体   English

从另一台计算机访问SQL数据库

[英]Access a sql data base from another computer

I have a SQL Server 2008 Express database and currently the database is on my personal laptop. 我有一个SQL Server 2008 Express数据库,当前该数据库在我的个人笔记本电脑上。 I want to access my database from another computer which belongs to the same local area network. 我想从属于同一局域网的另一台计算机访问数据库。 I am using Windows authentication to log in to SQL Server. 我正在使用Windows身份验证登录到SQL Server。

My connection string is as follows. 我的连接字符串如下。

Data Source=.\sqlexpress;Initial Catalog=Project_Monitoring;Integrated Security=True

Please explain how to do the setting for above requirement. 请说明如何进行上述要求的设置。 Thanks in advance. 提前致谢。

You still need to allow SqlExpress to allow remote connections. 您仍然需要允许SqlExpress允许远程连接。 On the machine that is hosting the SqlExpress process you need to do the following 在托管SqlExpress进程的计算机上,您需要执行以下操作

  • Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer. 在要从远程计算机连接到的SQL Server实例上启用远程连接。

  • Configure SQL server to listen on static port Turn on the SQL Server Browser service. 配置SQL Server以在静态端口上侦听打开SQL Server Browser服务。

  • Configure the firewall to allow network traffic that is related to SQL Server and to the SQL Server Browser service. 配置防火墙以允许与SQL Server和SQL Server Browser服务相关的网络流量。

See here http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/ 参见此处http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/

The article uses 2012 as an example, but this the process is the same for any version of SqlExpress 本文以2012年为例,但是此过程对于任何版本的SqlExpress都是相同的

As well as change the connection string on remote computers to 以及将远程计算机上的连接字符串更改为

Data Source=<hostcomputername>\sqlexpress:<configured-port>;Initial Catalog=Project_Monitoring;Integrated Security=True

By default, SQL Server Express does not add a firewall rule, and it has the TCP protocol disabled. 默认情况下,SQL Server Express不添加防火墙规则,并且禁用了TCP协议。 Therefore, you need to add these in order to be able to connect. 因此,您需要添加这些才能连接。

Open "SQL Server Configuration Manager". 打开“ SQL Server配置管理器”。 In the management console, open the "SQL Server Network Configuration" tab, protocols, TCP/IP, enable. 在管理控制台中,打开“ SQL Server网络配置”选项卡,然后启用协议,TCP / IP。 Restart the service for the changes to be applied. 重新启动服务以应用更改。 Also, you might need to enable and start the "SQL Server Browser" service in "SQL Server Services". 另外,您可能需要在“ SQL Server服务”中启用并启动“ SQL Server浏览器”服务。

Open Windows Firewall with Advanced Security, Inbound Rules, Add new rule, Custom, Services, Apply to this service: "SQL Server (SQLEXPRESS)", OK, Next... until you can name and finish the rule. 打开具有高级安全性的Windows防火墙,入站规则,添加新规则,自定义,服务,应用于此服务:“ SQL Server(SQLEXPRESS)”,确定,下一步...,直到可以命名和完成规则。 Do that again for the Browser Service. 对浏览器服务再次执行此操作。

The server name is then the remote computer name instead of . 这样,服务器名称就是远程计算机名称,而不是. , the rest of the connection string remains the same. ,其余的连接字符串保持不变。

Note that you might run into authentication problems if the accounts are not trusted on the remote computer; 请注意,如果远程计算机上的帐户不受信任,则可能会遇到身份验证问题。 for instance if you're not in a domain. 例如,如果您不在域中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM