从Entity Framework 4模型生成SQL Server Express数据库

时间:2021-04-19 09:46:22

I am able to auto-generate a SQL Server CE 4.0 *.sdf file using code-first generation as explained by Scott Guthrie here. The connection string for the same is as follows:

我可以使用代码优先生成自动生成SQL Server CE 4.0 * .sdf文件,如Scott Guthrie所述。它的连接字符串如下:

<add name="NerdDinners" providerName="System.Data.SqlServerCe.4.0" 
connectionString="data  source=|DataDirectory|NerdDinner.sdf"/>

However if I try to generate an mdf instead using the following connection string, it fails to do so with the following error - "The provider did not return a ProviderManifestToken string.".

但是,如果我尝试使用以下连接字符串生成mdf,则无法执行此操作,并出现以下错误 - “提供程序未返回ProviderManifestToken字符串。”。

<add name="NerdDinners" providerName="System.Data.SqlClient" connectionString="data 
source=|DataDirectory|NerdDinner.mdf"/>

Even directly hooking into a SQLEXPRESS instance using the following connection string fails

即使使用以下连接字符串直接挂钩到SQLEXPRESS实例也会失败

<add name="NerdDinners" providerName="System.Data.SqlClient" connectionString="Data 
 Source=.\SQLEXPRESS;Initial Catalog=NerdDinner;Integrated Security=True"/>

Does EF 4 only support SQL CE 4.0 for database creation from a model for now or am I doing something wrong here?

EF 4目前是否仅支持SQL CE 4.0从模型创建数据库,或者我在这里做错了什么?

2 个解决方案

#1


4  

I was able to get this connection string to work with SQL Express on the same tutorial.

我能够在同一个教程中使用SQL Express获取此连接字符串。

<add name="NerdDinners" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=NerdDinners; AttachDbFilename=|DataDirectory|NerdDinners.mdf; Integrated Security=True; User Instance=True" providerName="System.Data.SqlClient" />

Hope this helps someone in the future.

希望这可以帮助将来的某个人。

#2


1  

As a side note. If you're struggling to get the database to auto-create, it could well be because the database user you are using hasn't been given sufficient permissions. I was able to simply go the Security of the SQL Instance (not the database) and amend the Securables of the specific login so that it had the permission to Create Any Database (I didn't Grant any additional rights) and it allows EF4 to do its thing.

作为旁注。如果您正在努力让数据库自动创建,那很可能是因为您使用的数据库用户没有获得足够的权限。我能够简单地转到SQL实例的安全性(而不是数据库)并修改特定登录的Securables,以便它具有创建任何数据库的权限(我没有授予任何其他权限)并允许EF4做它的事。

#1


4  

I was able to get this connection string to work with SQL Express on the same tutorial.

我能够在同一个教程中使用SQL Express获取此连接字符串。

<add name="NerdDinners" connectionString="Data Source=.\SQLEXPRESS; Initial Catalog=NerdDinners; AttachDbFilename=|DataDirectory|NerdDinners.mdf; Integrated Security=True; User Instance=True" providerName="System.Data.SqlClient" />

Hope this helps someone in the future.

希望这可以帮助将来的某个人。

#2


1  

As a side note. If you're struggling to get the database to auto-create, it could well be because the database user you are using hasn't been given sufficient permissions. I was able to simply go the Security of the SQL Instance (not the database) and amend the Securables of the specific login so that it had the permission to Create Any Database (I didn't Grant any additional rights) and it allows EF4 to do its thing.

作为旁注。如果您正在努力让数据库自动创建,那很可能是因为您使用的数据库用户没有获得足够的权限。我能够简单地转到SQL实例的安全性(而不是数据库)并修改特定登录的Securables,以便它具有创建任何数据库的权限(我没有授予任何其他权限)并允许EF4做它的事。