Library Settings

本文关键字:Settings Library | 更新日期: 2023-09-27 18:34:55

  1. 我有一个库项目,可以访问在 app.config 中配置的数据库
  2. 我有一个访问 web.config 中配置的数据库的 Web 项目

两者都工作正常

现在我想使用 Web 项目中的库。在Visual Studio中工作正常。在生产服务器中,Web 项目访问数据库,但库无法从项目 Web 访问数据库。

app.config 和 web.config 中的 ConnectionString 是相同的。在生产服务器中不应该采用 web.config 设置吗?

谢谢,对不起我的英语

编辑

web.config 和 app.config connectionString

<connectionStrings> 
    <add name="IntranetConnectionString" 
         connectionString="Data Source=(local)'SQLExpress;Initial Catalog=Intranet;Integrated Security=True;" 
         providerName="System.Data.SqlClient" /> 
    <add name="Database.Properties.Settings.IntranetConnectionString" 
         connectionString="Data Source=(local)'SQLEXPRESS;Initial Catalog=Intranet;Integrated Security=True" 
         providerName="System.Data.SqlClient" /> 
</connectionStrings>

错误:

建立与 SQL Server 的连接时发生与网络相关或特定于实例的错误。找不到服务器或无法访问服务器。验证实例名称是否正确,以及 SQL Server 是否配置为允许远程连接。(提供程序:SQL 网络接口,错误: 26 - 查找指定的服务器/实例时出错(

Library Settings

如果我

理解正确,请尝试在本地复制库的引用,为此,right-click项目中的引用,然后在属性中,将True设置为 Copy Local ,现在您将在服务器中本地拥有库。

如果问题与库的引用有关,这应该有效,但如果是web.config/app.config问题,则无济于事

DLL 通常采用调用它的主机应用程序的 app.config,而不是它自己的配置。这里有肉吗?

解决方案:

在 DLL 中创建一个类,以使用接收连接字符串的构造函数访问数据表

public TestBLL(String ConnectionString)
{
    TestTableAdapter ta = new TestTableAdapter();
    ta.Connection = new System.Data.SqlClient.SqlConnection(ConnectionString);
}

在 Web 项目中:

String cs = System.Configuration.ConfigurationManager.ConnectionStrings["IntranetConnectionString"].ToString();
TestBLL taBLL = new TestBLL(cs);

在 taBLL 中具有访问每个查询的方法