scv
scv

Reputation: 363

CREATE DATABASE permission denied in database 'master'

This is for an existing database with a View table. Trying to list a View table, but came across this err msg in my Action:

CREATE DATABASE permission denied in database 'master'.

The view table to access is called: SomeTable

and if you run this on the database (ServerA_dev_alpha_custom):

sp_helptext 'SomeTable'

You'll get this:

 CREATE VIEW dbo.[SomeTable] AS  SELECT * FROM ServerA_dev_alpha.dbo.[SomeTable]

Here's the model:

public class SomeTable
{
    [Key]
    public virtual string SomeTableid  { set; get; }
    public virtual string name  { set; get; }
    public virtual string formvalue  { set; get; }
    public virtual string status  { set; get; }
    public virtual DateTime CreateDate { set; get; }    
}

The class name:

public class SomeDB: DbContext

Matches exactly to the connection string name:

    <add name ="SomeDB"
         connectionString ="data source=ServerA\DBSome; integrated Security=SSPI; initial catalog=ServerA_dev_alpha_custom"
         providerName="System.Data.SqlClient"/>

The err is found in creating the model:

SomeDB _db = new SomeDB();

var model = (from c in _db.SomeTable
  orderby c.CreateDate descending
  select c).Take(20);

When i change the connection string to point to where the table is defined: ServerA_dev_alpha (database) it works.

Any ideas?

Upvotes: 2

Views: 7544

Answers (2)

cheny
cheny

Reputation: 2735

I resolved this problem by using a sql server authorized account, sa, instead of windows arthorized ones.

You can find sa by logining the SqlServer management tool by windows authoration first and then in the left partial window ( called "Object Explorer" ) -> You Server\SQLEXPRESS(10.xxx) -> Security -> Logins

Double click sa and then set password and default database for it. The default database should be your database rather than the "master". Then, switch to "status" page, enable the sa account.

If your database is not listed in the dropdown list yet, in the left partial window mentioned above, right click and choose "attach" to attach it.

And, the connection string should be:

connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MFC.mdf;Initial Catalog=MFC;Integrated Security=false; User Id=sa; Password=your_password_here;"

It works for me.

Upvotes: 1

scv
scv

Reputation: 363

Even if you've an existing database setting the initializer to null works:

Database.SetInitializer<SomeDB>(null);

Second; forcing a mapping to the table name did the trick:

modelBuilder.Entity<SomeTable>()
.ToTable("SomeTable");

Upvotes: 1

Related Questions