Lai*_*290 3 c# sql-server entity-framework connection-string localhost
我正在为我的系统使用SQL Server 2012,并使用Entity Framework,Code首先访问数据库,我的数据库是本地的,但我无法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>
Run Code Online (Sandbox Code Playgroud)
但是,如果我将我的系统安装在另一台计算机上,其他数据库,PC名称不是JOHN-PC,所以我需要更改它为通用ConnectString
但是当我改变JOHN-PC\SQLEXPRESS时localhost,它不起作用
我该怎么做才能解决这个问题?
Sud*_*udi 12
如果您database在其他远程PC上也可以使用dot .而不是硬编码机器名称.
这里.代表了localmachine.
试试这个 :
<connectionStrings>
<add name="SystemContext" connectionString="Server=.\SQLEXPRESS;Database=PizzariaDB;user=sa;password=12345" providerName="System.Data.SqlClient"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
但是如果你想把你的机器作为数据库服务器来运行,并希望每台其他的PC都可以与你的PC进行数据库活动的通信,你可以IP address在你的机器上使用你的机器connection string.
| 归档时间: |
|
| 查看次数: |
12908 次 |
| 最近记录: |