Connection string error between projects with EF

56 views Asked by At

My solution exits out of 3 Projects:

Solution

  • SP_Class_Library contains my EF model
  • SP_Control_Library is a class library that contains all my custom and user controls
  • SP_EF_TEST is my Form Application

I created a custom control cc_User_DropDown with the following code

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

The problem comes when I try and add the custom control to either u_Users or Form1 I get the error:

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

If I comment the code and build I can add the control, but as soon as I uncomment the code and build I get the following:

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

I have tried suggestions that say I must add the app.config to all the projects, Copy the connectionstring to all the .config files and remove the .config file from the dll and add it to the Form Application but it does not work.

Here is my app.config file:

<?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

There are 0 answers