开发者

Generate SQL Server Express database from Entity Framework 4 model

开发者 https://www.devze.com 2023-02-01 17:46 出处:网络
I am able to a开发者_如何学JAVAuto-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:

I am able to a开发者_如何学JAVAuto-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:

<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.".

<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

<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?


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

<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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消