从网络连接到数据库 [英] Connect to database from network

查看:105
本文介绍了从网络连接到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我用这个连接字符串连接到服务器上的数据库。

Hi,
I connect to database on server with this connection string.

Data Source=.;Initial Catalog=test;Integrated Security=true



如何从网络上的另一台计算机连接到此数据库?我使用这个连接字符串,但它不起作用。


How can I connect to this database from another computer on network? I use this connection string but it's not work.

Data Source=192.168.1.6\SQLEXPRESS;Initial Catalog=test;Integrated Security=true

推荐答案

根据我的经验,除非应用程序与数据库位于同一台计算机上,否则 Integrated Security = true 要求用户使用域帐户登录,而不是本地Windows帐户。因为您的示例包含192.168。*。* IP地址,所以我假设您没有在使用域帐户登录的环境中运行。



因此,不要使用 Integrated Security = true ,请使用 Integrated Security = False ;用户ID = xxxxx;密码= yyyy 其中xxxxx是配置到数据库服务器的用户ID,yyyy是用户ID xxxxx的密码。



使SQL Server能够使用SQL Server身份验证并接受远程连接

在SQL Server Management Studio中,右键单击服务器名称,然后单击属性。在 Connections 页面中,确保选中允许与此服务器的远程连接。在安全文件夹中,单击 SQL Server和Windows身份验证模式。单击确定按钮。重新启动 SQL Server 服务。



创建SQL Server用户ID

在SQL Server Management Studio中,左键单击服务器下的安全文件夹,然后右键单击登录并左键单击新登录。在登录 - 新建对话框窗口中,选中 SQL Server身份验证单选按钮,在相应的文本框中输入登录名和密码,然后取消选中用户必须在下次登录时更改密码复选框。单击确定
In my experience, unless the application is on the same computer as the database, Integrated Security=true requires that the user be signed on with a domain account and not a local Windows account. Because your example includes a 192.168.*.* IP Address, I assume that you are not running in an environment where you are logged on with a domain account.

Therefore, instead of using Integrated Security=true, use Integrated Security=False;User id=xxxxx;Password=yyyy where xxxxx is a user id configured into the database server and yyyy is the password for user id xxxxx.

To enable SQL Server to use SQL Server Authentication and accept remote connections
In SQL Server Management Studio, right-click on the server name and click properties. In the Connections page, ensure that Allow remote connections to this server is checked. In the Security folder, click on SQL Server and Windows Authentication mode. Click the OK button. Restart the SQL Server service.

To create a SQL Server User Id
In SQL Server Management Studio, left-click on the Security folder under your server, then right-click Logins and left-click New Login. In the Login - New dialog window, check the SQL Server authentication radio button, enter a Login name and a Password in the appropriate textboxes, and uncheck the User must change password at next login checkbox. Click OK.


这篇关于从网络连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆