Reputation:
After deploying my MVC 4 application, I try to register user, get such error:
CREATE DATABASE permission denied in database 'master'.
Connection string is :
<add name="Market" providerName="System.Data.SqlClient" connectionString="Data Source=endine.arvixe.com; Initial Catalog=Market; Uid=mylogin; Password=mypass; MultipleActiveResultSets=true; " />
And DbContext:
public class Market: DbContext
{
public Market()
{
Database.SetInitializer<Market>(new MarketInitializer());
}
}
public class MarketInitializer: DropCreateDatabaseIfModelChanges<Market>
{
protected override void Seed(Market context)
{
base.Seed(context);
}
}
I accessed to database with SQL Management Studio with same mylogin
and mypass
, created Market
database with script. But in site, can not access database.
How can I find it's reason?
Upvotes: 4
Views: 4739
Reputation: 11
Sometime it happens because you don't have sysadmin role on local SQL Server instance. I found useful article where you can download script command and install it. You will be ask for SQLEXPRESS name or instance name, just you can write 'SQLEXPRESS' and enter. Thats it. It will add you to sysadmin role of local server instance.
Download command from: http://archive.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=addselftosqlsysadmin&DownloadId=9198
Please let me know if it does not work for you.
Upvotes: 1
Reputation: 7941
the issue is this piece of code DropCreateDatabaseIfModelChanges<Market>
public class MarketInitializer: DropCreateDatabaseIfModelChanges<Market>
{
protected override void Seed(Market context)
{
base.Seed(context);
}
}
The model has changed at some point,so it is trying to drop the database and recreated it
Upvotes: 1