ef 4.1 Code First cannot create database

Discussion in 'Site Programming, Development and Design' started by jmcfet, Oct 25, 2011.

  1. with the code first model of Entity Framework 4.1 the framework itself will create the data base the first time access is attempted to the database and this works great on my local setup where I run IIS and SQL Express. However when I deploy on inhost I receive the following exception:
    Create DATABASE permission denied in database 'master'

    Now I did run into this issue on my server and gave the AppPool userid database rights but do not see how to do this on Winhost. I saw another thread with kind of the same issue and u recommended giving full rights and I believe I have as shown in the following web.config

    <?xml version="1.0"?>
    <configuration>

    <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <securityPolicy>
    <trustLevel name="Full" policyFile="internal"/>
    </securityPolicy>

    </system.web>
    <system.serviceModel>
    <behaviors>
    <serviceBehaviors>
    <behavior>
    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
    <serviceMetadata httpGetEnabled="true"/>
    <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
    <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
    </serviceBehaviors>
    </behaviors>

    </system.serviceModel>
    <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
    <connectionStrings>
    <add name="CamAccess" connectionString="data Source=s03.Winhost.com;Initial Catalog=trafficcams;User ID=DB_3030_silvercl_user;Password=gogators;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

    </connectionStrings>
    </configuration>
     
    Last edited by a moderator: Oct 14, 2015
  2. Hello

    I have a similar issue it appears as when my classes are updated and I would like to create the database from inside the application start it gives an error


    is this a permission issue to create or drop the database remotely, can you please tell me what the solution was for this thread?

    ensure that the database referred to in the connection string does not exist the first time you run the service. is this possible on Winhost?

    Programming EF Code First
     
    Last edited by a moderator: Oct 14, 2015
  3. Elshadriel

    Elshadriel Winhost Staff

    Hello,

    I'm afraid the CREATE DATABASE function is not available to our customers. You will need to create the database locally first, and then restore it using the tools in the Control Panel.
     
  4. EF Code first

    I asked before creating this account if I am able to-do so!

    Can you please tell me before I waste any more time if I can use the Entity Framework on the shared hosting account? As this is my object to use the code first approach.. so no reason to have a context cursor to seed the database or such ... can you please tell me if you people support the EF Code First approach ? I saw earlyer a domain on your host it appears running RAZOR MVC 3 C# ? anybody using EF Code First approach ?
     
  5. just a follow up the only restriction I encountered in the above regards is only the drop and create db on application start
     
  6. The best thing to do would be to run your EF Code first code locally and then create a backup of the locally created database.

    Login to Winhost and create the database manually and then using SQL Management Studio or such-like, restore from your local backup.

    Then make the neccessary tweaks to your start-up code in EF so that it doesn't try to CREATE DATABASE on startup.

    Obviously this is a bit of a pain, but it's the only way as far as I know.
     
  7. Good advice, thanks.
     

Share This Page