1

This is a bit of a weird one. I'm doing an MVC 3 code first development using the SQL compact 4 stuff. Its all running fine but I'm getting issues when I try to scaffold a new controller. I fire up the new controller dialog and select my entity and the datacontext (both of which are in a separate assembly in the same solution) and get the following error:

Unable to retrieve metadata for 'MyNamespace.MyClassName'. Access to the database file is not allowed. [ 1884,File name=C:\Program Files\Microsoft Visual Studio 10.0\Common7\EntityContext.sdf,SeCreateFile ]

That file does not exist on disk at the moment - the EntityContext.sdf file is sat in my App_Data folder. I'm not sure if its trying to create that file (and if so why?) but if it is I'm not logged in as admin so it won't have permissions. In that case do I need to define a difference working folder or something?

I've tried it running as admin now and it works, so it's definitely trying to create a file in my Program Files directory, there must be a setting for temp files somewhere?

Any help would be great :)

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Chris Surfleet
  • 2,462
  • 4
  • 28
  • 40

3 Answers3

0

I have also faced the same problem when tried to export SQL CE db script with number of utils. Got error "Access to the database file is not allowed". Then I have just connected to that db-file from VS2010, copied connection string and... it worked! :)

0

I ran into this issue when using the T4Scaffolding. I got around the problem by installing the MVCScaffolding nuget package and used the "MVCScaffolding: Controller with read/write action and views, using EF data access code" template. It produces similar controller actions and views. I was unable to uninstall and reinstall the T4Scaffolding nuget package to see if this was a bug or corrupt install.

VE3IMG
  • 1
0

Did you find an answer to the issue? I was having the same problem but handled it through the deployment transforms...

In Web.Config I used full path to the SDF:

<configuration>
    <connectionStrings>
        <add 
          name="DBContext" 
          connectionString="Data Source=C:\full-path\DBContext.sdf" 
          providerName="System.Data.SqlServerCe.4.0" />
...

In Web.Release.config I replace the connectionString attribute...

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add 
      name="DBContext" 
      connectionString="Data Source=\DBContext.sdf" 
      xdt:Transform="SetAttributes" 
      xdt:Locator="Match(name)"/>
  </connectionStrings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

After a release deploy the correct "|DataDirectory|" setting is made rather than "C:\full-path\".

I would like a fix to the original issue though!!

PK :-)

Paul Kohler
  • 2,684
  • 18
  • 31