[英]Connect string of SQL Server for localhost in Entity Framework
我正在使用SQL Server 2012作为我的系统,并使用Entity Framework,Code首先访问数据库,我的数据库是本地的,但我无法使用SERVER=localhost;
连接SERVER=localhost;
在ConnectString中
我的App.config
(工作)
<connectionStrings>
<add name="SystemContext" connectionString="Server=JOHN-PC\SQLEXPRESS;Database=PizzariaDB;user=sa;password=12345" providerName="System.Data.SqlClient"/>
</connectionStrings>
但是,如果我将我的系统安装在其他计算机,其他数据库,PC名称不是JOHN-PC,所以我需要更改它为通用ConnectString
但是当我为localhost
更改JOHN-PC\\SQLEXPRESS
,它不起作用
我该怎么做才能解决这个问题?
如果你有其他远程PC上的database
,你也可以使用dot
.
而不是硬编码机器名称。
在这里.
代表localmachine
。
尝试这个 :
<connectionStrings>
<add name="SystemContext" connectionString="Server=.\SQLEXPRESS;Database=PizzariaDB;user=sa;password=12345" providerName="System.Data.SqlClient"/>
</connectionStrings>
但是如果您想将您的计算机作为数据库服务器运行,并希望每台其他计算机与您的PC通信以进行数据库活动,您可以在connection string
使用计算机的IP address
。
尝试这个:
<connectionStrings>
<add name="SystemContext" connectionString="Server=.\SQLEXPRESS;Database=PizzariaDB;user=sa;password=12345" providerName="System.Data.SqlClient"/>
点指向本地计算机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.