我正在嘗試開發連接到sql server和Sql CE4的應用程序。 創建管理SQL CE 4.0的連接字符串動態SQL CE 4與DbContext的連接字符串仍然收到錯誤
public partial class ModelContainer : DbContext
{
public ModelContainer()
{
SqlCeConnection con = new SqlCeConnection("Data Source=D:\\Charities.sdf");
this.Database.Connection.ConnectionString = con.ConnectionString;
this.Database.Connection.Open();
}
public DbSet<Grant> Grants { get; set; }
public DbSet<GrantDetail> GrantDetails { get; set; }}
一個選項,但仍收到錯誤,當連接嘗試打開
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
我manged來創建的SqlConnection同樣的方式另一個SQL Server連接,它的工作,但這不會!
有什麼建議嗎?
最好的問候。
什麼是數據庫的密碼?你的連接字符串應該像Data Source = D:\\ Charities.sdf;密碼='pwd' – Ehsan
請參閱此處的答覆:http://stackoverflow.com/questions/7905076/sqlserverce-defaultconnectionfactory – ErikEJ
謝謝ErikEj: 我在這裏找到它 http://stackoverflow.com/questions/12490190/ef -5 -sql-ce-4-how-to-specify-custom-location-for-database-file 這與你的Idia相同 – Eiaddar