Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008: Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions

The complete error I am getting is this:

Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions.

I have used tried this with SQL Server Compact and it works fine, but the hosting provider only supports CE for dedicated servers an I am on a shared plan, so I am using SQL Server 2008. My connection string in the db is in the following format:

  <connectionStrings>
    <add name="DBContext"
         connectionString="Data Source=1.1.1.1;Initial Catalog=dbname;User Id=user;Password=pass;"
         providerName="System.Data.SqlClient"/>
  </connectionStrings>

I also have a DatabaseInitializer that runs in Application_Startup. If any further code is needed, just let me know? I also do not have edmx data model created, I am using the EF Code First.

I changed the initializer code Drop the database always, but now I get the error, CREATE DATABASE permission denied in database 'master'. I don't know why I get this when I telling it the Initial Catalog to use.

I am passing in null to the SetInitializer for now, but now I get the following error:

Cannot open database "dbname" requested by the login. The login failed. Login failed for user 'user'.

I am still using the connectionstring from above.

like image 460
Xaisoft Avatar asked Oct 09 '22 01:10

Xaisoft


1 Answers

I changed the initializer code Drop the database always, but now I get the error, CREATE DATABASE permission denied in database 'master'. I don't know why I get this when I telling it the Initial Catalog to use.

You must never do this in shared hosting because you almost never have permission to directly create database. Databases can be only created in special interface of hosting provider. SQL server allows you to delete database you owns but once you deleted it your permissions are gone and you cannot recreate it without permission to create databases (in shared hosting you never have this permission).

I am passing in null to the SetInitializer for now, but now I get the following error:

It is too late. Your database is deleted. You must create it through hosting provider interface or contact your hosting provider to recreate it.

I also have a DatabaseInitializer that runs in Application_Startup.

You cannot use any built-in database initializer in shared hosting because all of them expects that they will create database. You can use custom initializer to fill tables to existing database.

like image 69
Ladislav Mrnka Avatar answered Oct 13 '22 12:10

Ladislav Mrnka