[英]SQL Server on remote computer
I have a SQL Server Express instance on a computer with IP 192.168.66 on a home network. 我在家庭网络上IP为192.168.66的计算机上有一个SQL Server Express实例。
I have enabled TCP/IP on port 49170 and added the incoming rule on Windows firewall. 我已在端口49170上启用了TCP / IP,并在Windows防火墙上添加了传入规则。
I have an application that I want to install on different computers inside my network. 我有一个要安装在网络内部不同计算机上的应用程序。 When I am testing my application in Visual Studio, I am not able to connect to my instance on the remote computer. 在Visual Studio中测试应用程序时,无法连接到远程计算机上的实例。
<connectionStrings>
<add name="EquipamentoDal.Properties.Settings.ExtinguisherMngConnectionString"
connectionString="Data Source=192.168.1.66,49170;Initial Catalog=ExtinguisherMng;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
The server name is DESKTOP-HU51203\\EXPRESS
. 服务器名称为DESKTOP-HU51203\\EXPRESS
。 What i have done wrong to not be able to connect? 我做错了什么而无法连接?
Your connection string does not specify the Named Instance you're connecting to, it only specifies the IP address, which means any clients will connect to the default instance instead of a named instance. 您的连接字符串未指定您要连接的命名实例,而仅指定IP地址,这意味着任何客户端都将连接到默认实例,而不是命名实例。
By default SQL Server Express is configured differently to 'standard' versions of SQL Server (Standard, Workgroup, Developer, and Enterprise Editions) as follows: 默认情况下,SQL Server Express的配置与SQL Server的“标准”版本(Standard,Workgroup,Developer和Enterprise Edition)不同,如下所示:
SQLEXPRESS
instead of being configured as the Default Instance 使用名为SQLEXPRESS
的命名实例,而不是配置为默认实例 AttachDb
and LocalDb
- the other SKUs/Editions do not support the AttachDb
and LocalDb
features. SQL Server Express在支持AttachDb
和LocalDb
也很独特-其他SKU /版本不支持AttachDb
和LocalDb
功能。 In your case, you've already enabled Remote Connections and you're not using AttachDb
or LocalDb
, so you just need to configure your client to connect to a named instance: 在您的情况下,您已经启用了远程连接,并且没有使用AttachDb
或LocalDb
,因此只需要配置客户端以连接到命名实例:
You specify the named instance in your connection string using the format <host>\\<instance name>,<port>
in the Data Source=
or Server=
parameter, eg Data Source=foo\\SQLEXPRESS,1433
, or in your particular case: 您可以使用Data Source=
或Server=
参数中的格式<host>\\<instance name>,<port>
在连接字符串中指定命名实例,例如Data Source=foo\\SQLEXPRESS,1433
,或者在您的特定情况下:
Data Source=192.168.1.66\SQLEXPRESS,49170;Initial Catalog=ExtinguisherMng;Integrated Security=True
You mentioned that you're doing this on a Home network, which means it's unlikely you're using an Active Directory or Kerberos, and given SQL Server Express does not expose the passwords it uses for its Service Identity (nor can users authenticate as NT AUTHORITY\\NetworkService
over the network it means you cannot use Integrated Security=True
(or Integrated Security=SSPI
which is equivalent, but SSPI
is the preferred value), you will need to set an explicit SQL Server Login's username and password in your Connection String. 您提到要在家庭网络上执行此操作,这意味着您不太可能使用Active Directory或Kerberos,并且由于SQL Server Express不会公开用于其服务身份的密码(用户也不能通过NT AUTHORITY\\NetworkService
身份验证)通过网络的NT AUTHORITY\\NetworkService
,这意味着您不能使用Integrated Security=True
(或Integrated Security=SSPI
,这是等效的,但SSPI
是首选值),您将需要在连接字符串中设置显式SQL Server登录名的用户名和密码。
sa
account, if it exists) 在服务器中创建一个新的登录对象(您需要首先以某种方式(使用sa
帐户在本地或远程登录)以某种方式登录到服务器) Integrated Security=True
with User Id=<userName>;Password=<password>;
通过将Integrated Security=True
替换为User Id=<userName>;Password=<password>;
指定新的登录名的凭据User Id=<userName>;Password=<password>;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.