如何配置app.config文件。 [英] how to configure app.config file.

查看:146
本文介绍了如何配置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.

  1. 选择开始,并在您的程序列表中,选择 SQL Server配置管理器
  2. 导航到 SQL Server配置管理器> SQL Server网络配置> <机器实例>的协议。
  3. 双击命名管道。将出现命名管道属性屏幕。
  4. 从启用,选择。然后单击确定
  5. 双击 TCP / IP 。将出现 TCP / IP 属性屏幕。
  6. 在协议选项卡上,确保为是 >已启用。在 IP 地址选项卡上,确保为相应的 IP C $ C>地址。此外,请确保指示相应的 TCP 端口。
  7. 单击确定。
  8. SQL Server Management Studio ,重新启动服务器实例。
  1. Select Start, and in your list of programs, select SQL Server Configuration Manager.
  2. Navigate to SQL Server Configuration Manager > SQL Server Network Configuration > Protocols for <machine instance>.
  3. Double-click Named Pipes. The Named Pipes Properties screen appears.
  4. From Enabled, select Yes. Then click OK.
  5. Double-click TCP/IP. The TCP/IP Properties screen appears.
  6. On the Protocol tab, ensure Yes is selected for Enabled. On the IP Addresses tab, ensure that Yes is selected for the appropriate IP Address. Also, ensure that the appropriate TCP Port is indicated.
  7. Click OK.
  8. From SQL Server Management Studio, restart the server instance.


这篇关于如何配置app.config文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆