嗨我在解決方案中有幾個項目。 在項目A中,我有名爲Ver3ConnectionString的連接字符串的app.config。但是當我進行調試時,連接字符串沒有在代碼中找到:)。調試連接字符串包含一個未在此app.config中定義的連接字符串,在我的應用程序:)。我使用VS2013 Express :)。app.config:ConnectionString的值在它定義的項目中不可見
此外,applicationSettings是在主項目:)中定義的應用程序設置,但不是正在被炫耀的應用程序設置。
魔法:)。
增加:
的解決方案是通過從現有的項目我的同事創建的,所以進出口尋找在溶液/項目文件錯誤。
MobileWalletContext類與EntityFramework 6.X連接。也許這是問題?
新增2: 這未知的連接字符串NAME = 「LocalSqlServer」 這個。也許這會有幫助嗎?
的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="Ver3ConnectionString"
connectionString="Data Source=PAZI-PRO2\SQLEXPRESS;Initial Catalog=MobileWalletVer3;Integrated Security=True"
providerName="System.Data.SqlClient" />
</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" />
</providers>
</entityFramework>
</configuration>
C#代碼,其中connsterionString被稱爲:
public MobileWalletContext() : base(string.Format("name={0}",ConfigurationManager.ConnectionStrings["Ver3ConnectionString"].ConnectionString))
{
Database.SetInitializer(new DropCreateDatabaseIfModelChanges<MobileWalletContext>());
}
我明白這個改變,但是我想徹底打消它:)。 –
編輯我的回答添加一些細節 –
我改變了基地構造函數調用:base(「name = XXX」)其中XXX被定義連接字符串名稱,但我有錯誤:在應用程序中找不到名爲'XXX'的連接字符串配置文件。魔術再次:) –