连接字符串真的很烦人。
我在一个解决方案中有两个项目。一个充当表示层的 Web 表单应用程序,以及一个支持它的类库,它将从数据库发送和接收数据。
-- 类库项目中的员工类 --
Friend Class Employee
Public Function GetEmployees() As DataSet
    Dim DBConnection As New SqlConnection(My_ConnectionString)
    Dim MyAdapter As New SqlDataAdapter("exec getEmployees", DBConnection)
    Dim EmployeeInfo As DataSet
    MyAdapter.Fill(EmployeeInfo, "EmployeeInfo")
    Return EmployeeInfo
End Function
End Class
目前,应用程序告诉我它无法访问我试图存储在配置文件中以便快速重复访问的“My_ConnectionString”:
<configuration>
<system.web>
  <compilation debug="true" strict="false" explicit="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5"  />
</system.web>
 <connectionStrings>
   <add name="My_ConnectionString" connectionString="Data Source=.\sqlexpress;Initial Catalog=My_DB;Integrated Security=True;"/>
 </connectionStrings>
</configuration>
web.config 是 web 表单项目的一部分,而不是类库,这些项目是否无法相互“对话”?我是否需要将 web / app 配置文件添加到类库以在该项目中存储连接字符串?