不支持关键字:“attachdbfilename' - MDF数据库文件(C#) [英] Keyword not supported: 'attachdbfilename' - MDF Database File (C#)
问题描述
我试图连接到我的 .MDF
文件,但我不能完成它。我试图连接字符串的各种变化,但仍然收到此相同的错误。
I trying connect to my .MDF
file but I am not able to accomplish it. I tried various variations of connection strings but still getting this same error.
这的app.config
This my connection string from app.config
<connectionStrings>
<add name="DBConnection"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\iseo-db.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
这就是我如何把这个连接字符串
and this is how I call this connection string
private string connection = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ToString();
SqlCeConnection con = new SqlCeConnection(connection);
当每一次我尝试执行我得到一个异常说
When every I try execute I get a exception saying
关键字不支持:attachdbfilename
Keyword not supported: 'attachdbfilename'
我会很感激在这个问题上的任何帮助
I would really appreciate any help on this problem.
推荐答案
据我所知,SQL-Server CE中不使用 MDF
的文件,而不是 SDF
文件。 Futhermore你不必使用属性 AttachDbFilename
,然后只需使用属性数据源= ...
。
As far as i know, SQL-Server CE does not use mdf
files, rather than sdf
files. Futhermore you don't have to use the property AttachDbFilename
, then simply use the property Data Source=...
.
<add name="DBConnection"
connectionString="Data Source=|DataDirectory|/iseo-db.sdf;Integrated Security=True"
providerName="System.Data.SqlServerCe.4.0" />
一些这样的事应该做的伎俩。
Some thing like this should do the trick.
修改
据@marc_s,数据提供者也必须更改为: System.Data这.SqlServerCe.4.0
According to @marc_s, the data provider also has to be changed to: System.Data.SqlServerCe.4.0
这篇关于不支持关键字:“attachdbfilename' - MDF数据库文件(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!