EF

时间:2015-06-09 11:57:05

标签: vb.net entity-framework connection-string

我的解决方案退出3个项目:

Solution

  • SP_Class_Library包含我的EF模型
  • SP_Control_Library是一个包含我所有自定义和的自定义的类库 用户控件
  • SP_EF_TEST是我的表格申请

我使用以下代码

创建了一个自定义控件cc_User_DropDown
Protected Overrides Sub OnCreateControl()
    MyBase.OnCreateControl()

    LoadUsers()

End Sub

Private Sub LoadUsers()
    Dim UserList As List(Of SP_User) = Nothing


    UserList = (From c In ent.SP_User
                Where c.usr_Active = True
                             Select c
                             Order By c.usr_Name).ToList


    Dim blank As New SP_User
    blank.usr_ID = 0
    blank.usr_Name = "Please select a user..."

    UserList.Insert(0, blank)

    Me.DisplayMember = "usr_Name"
    Me.ValueMember = "usr_ID"
    Me.DataSource = UserList
End Sub

当我尝试将自定义控件添加到u_Users或Form1时出现问题我收到错误:

No connection string named could be found in the application config file

如果我评论代码和构建我可以添加控件,但是一旦我取消注释代码并构建我得到以下内容:

No connection string named could be found in the application config file 2

我已经尝试了一些建议,说我必须将app.config添加到所有项目中,将connectionstring复制到所有.config文件并从dll中删除.config文件并将其添加到Form Application但它不会工作

这是我的app.config文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog" />
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
  </system.diagnostics>
  <connectionStrings>
    <add name="SPEntities" connectionString="metadata=res://*/SP_Model1.csdl|res://*/SP_Model1.ssdl|res://*/SP_Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\SPDEV;initial catalog=SP;persist security info=True;user id=sa;password=xxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v12.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

0 个答案:

没有答案