How to pass ADO.NET Entity Data Model password at runtime? I can't work it out after searching for question, forum, blog. I select code-first from database which I want to connect to an existing .SDF
database file.
At defining the connection and name in app.config
, I have selected not to store sensitive password into config file. As I have see in some tutorial, they not advise to store password in config.
How to pass the password at runtime after SetData? I have 3 database in same folder. I have add all 3 database to EF.
Just learning how to use magnificent EF technique. Need some advise.
EF is setup in a WPF application.
App.config
<connectionStrings>
<add name="AppUI"
connectionString="Data Source=|DataDirectory|AppUI.sdf"
providerName="System.Data.SqlServerCe.4.0" />
<add name="AppSystem"
connectionString="Data Source=|DataDirectory|AppSystem.sdf"
providerName="System.Data.SqlServerCe.4.0" />
<add name="AppConfig"
connectionString="Data Source=|DataDirectory|AppConfig.sdf"
providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>
I set the data directory at Application_Startup
:
AppDomain.CurrentDomain.SetData("DataDirectory", GlobVars.strLogStartPath + "Database");
The EF main class
public partial class AppConfig : DbContext
{
public AppConfig()
: base("name=AppConfig")
{
}
public AppConfig(string ConnectionString)
: base(ConnectionString)
{
}
public virtual DbSet<HardwareConfig> HardwareConfigs { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
}
}
I'm getting the value from configuration database
using (var context = new AppConfig())
{
IQueryable<HardwareConfig> qTable = from t in context.HardwareConfigs
select t;
foreach (var t in qTable)
{
string devicename = t.Model;
}
}
Currently the problem occurs at IQueryable<HardwareConfig>
where it throws an exception:
The underlying provider failed on Open. The specified password does not match the database password. [ Data Source = AppConfig.sdf ]