我在系统上使用SQL Server 2012,并且在使用Entity Framework,代码优先访问数据库时,我的数据库是本地的,但是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
但是当我更改JOHN-PC\SQLEXPRESS
为时localhost
,它将无法正常工作
我该怎么办才能解决此问题?
如果您database
在其他远程PC上也有,则可以使用dot
.
代替硬编码计算机名称。
这里.
代表localmachine
。
尝试这个 :
<connectionStrings>
<add name="SystemContext" connectionString="Server=.\SQLEXPRESS;Database=PizzariaDB;user=sa;password=12345" providerName="System.Data.SqlClient"/>
</connectionStrings>
但是如果您想将机器作为数据库服务器运行,并且希望每台PC与另一台PC进行通信以进行数据库活动,则可以在您的PC中使用IP address
您的机器connection string
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句