最近我改寫了我公司用來開展業務的大型計劃。我很早就更改爲實體框架。大多數情況下它一直工作得很好。已經惹惱了我很長一段時間,現在我有時間去看看是實體框架,自定義控制,沒有任何連接字符串名爲x,仍然運行
一個問題,從數據庫中拉一個問題自定義控件導致一個奇怪的錯誤。
當自定義控制使用SQL它實際上會顯示在設計形式顯示的問題。起初這很酷,我喜歡它。切換爲使用實體框架6,當我在設計裝載形式後,我得到的錯誤
名爲「wotcDB」沒有連接字符串可以在應用程序 配置文件中找到。
它完全在app.config文件中。事實上,該程序沒有問題編譯和運行沒有問題。最長的時間,我會推動忽略,並在窗體上工作。設計師當然不再出現這個問題。
用戶控件是應用程序的一部分。 app.config文件在那裏,程序都運行並部署良好。這是什麼造成的?
這是我的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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="webDB" connectionString="metadata=res://*/Data.webDB.csdl|res://*/Data.webDB.ssdl|res://*/Data.webDB.msl;provider=MySql.Data.MySqlClient;provider connection string="user id=#######;password=#######;server=#######;database=#######;persistsecurityinfo=True""
providerName="System.Data.EntityClient" />
<add name="wotcDB" connectionString="metadata=res://*/Data.wotcDB.csdl|res://*/Data.wotcDB.ssdl|res://*/Data.wotcDB.msl;provider=System.Data.SqlClient;provider connection string="data source=#######;initial catalog=#######;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>
內置於控制數據訪問代碼?控件類是否與它所在的表單在同一個項目中聲明? – jmcilhinney
它嵌入到控件中。控件類在同一個項目中。 – Kayot