riseres riseres - 3 months ago 15
C# Question

CodeFirst cannot create database on shared hosting

I want to deploy Entity Framework 5.0 to Shared Hosting.

Now I have the problem with database. I cannot create database.

<add name="ResContext"
connectionString="Data Source=XXXX5.db.10232343.hostedresource.com;
Initial Catalog=XXXX5; User ID=XXXX5;
Password=XXXXXXXXX!;Integrated Security=false"
providerName="System.Data.SqlClient"></add>


First
providerName="System.Data.SqlClient"

I got the problem


Cannot drop the database 'XXXX5', because it does not exist or you do not have permission.


But when I change provideName to

providerName="System.Data.EntityClient"


Keyword not supported: 'data source'.

Answer

Typically GoDaddy does not give you permission to create or drop databases programmatically. They only allow you to create those databases through their user interface. This is because they don't want people creating databases all over the place, and they want to ensure that only you have the rights to access the database in a shared user environment.

So you cannot use the default generation method that EF uses. Instead, you would use the Database initializer:

Database.SetInitializer<YourContextType>(null);
Comments