如何配置app.config文件。 [英] how to configure app.config file.
本文介绍了如何配置app.config文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码在下面
My code is below
<configuration>
<configsections>
</configsections>
<connectionstrings>
<add name="LatTejDB" connectionstring="Data Source=RAJ;Initial Catalog=NewMilkSupply;Integrated Security=True" providername="System.Data.SqlClient" />
</connectionstrings>
<startup>
<supportedruntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
使用此代码,我的应用程序仅在我的计算机上运行。
我想让它在另一台计算机上运行。
Using this code, my application runs only on my computer.
I want it to run on another computer.
推荐答案
不要将安装特定的东西(如连接字符串)放入应用程序。配置。
把它放在其他地方。在存储在运行用户AppData(或等效)文件夹中的新配置文件中,或者将其作为启动参数。
如果您的应用程序有如果没有配置连接字符串,您可以请求连接字符串,然后将其写入下次应用程序启动时使用的用户特定配置文件。
希望这有助于,
Fredrik
Don't put installation specific things (like connection strings) into the app.config.
Put it somewhere else. Either in a new config file that is stored in the running users AppData (or equivalent) folder or take it as a start-up argument.
If your application has a UI you can ask for the connection string if none is configured and then write it to a user specific config file that is used next time the application starts.
Hope this helps,
Fredrik
<add name="LatTejDB" connectionstring="Data Source=RAJ;Initial Catalog=NewMilkSupply;Integrated Security=True" providername="System.Data.SqlClient" />
来自 ConnectionString
,很明显你正在尝试连接某个服务器 RAJ
。
为此,您需要在 SQL Server配置管理器中启用TCP / IP和 命名管道
。
参考 - 启用命名管道和TCP / IP连接 [ ^ ]知道如何启用
它。
我只是从那里采取步骤并在下面列出。
From the ConnectionString
, it is clear that you are trying to connect to some Server RAJ
.
For that, you need to Enable TCP/IP and Named Pipes
in SQL Server Configuration Manager.
Refer - Enable Named Pipes and TCP/IP Connections[^] to know how to Enable
it.
I am just taking the steps from there and listing them below.
- 选择开始,并在您的程序列表中,选择 SQL Server配置管理器。
- 导航到 SQL Server配置管理器> SQL Server网络配置> <机器实例>的协议。
- 双击命名管道。将出现命名管道属性屏幕。
- 从启用,选择
是
。然后单击确定
。 - 双击 TCP / IP 。将出现 TCP / IP 属性屏幕。
- 在协议选项卡上,确保为
是
>已启用。在IP
地址选项卡上,确保为相应的IP $选择
是
C $ C>地址。此外,请确保指示相应的TCP
端口。 - 单击确定。
- 从 SQL Server Management Studio ,重新启动服务器实例。
- Select Start, and in your list of programs, select SQL Server Configuration Manager.
- Navigate to SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for <machine instance>.
- Double-click Named Pipes. The Named Pipes Properties screen appears.
- From Enabled, select
Yes
. Then clickOK
. - Double-click TCP/IP. The TCP/IP Properties screen appears.
- On the Protocol tab, ensure
Yes
is selected forEnabled
. On theIP
Addresses tab, ensure thatYes
is selected for the appropriateIP
Address. Also, ensure that the appropriateTCP
Port is indicated. - Click OK.
- From SQL Server Management Studio, restart the server instance.
这篇关于如何配置app.config文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文