0

I just installed SQL Server 2012 Express edition on my computer (Windows 8).

When I try to create a database from the Management studio, I'm getting the following error:

Create failed for Database 'TestDB'. (Microsoft.SqlServer.Smo)
CREATE DATABASE permission denied in database 'master'.
(Microsoft SQL Server, Error: 262)

When I try to access it from the visual studio, I'm getting the following similar error message:

CREATE DATABASE permission denied in database 'master'.

Is there any reason for that? I can't even access the engine from the management studio.

EDIT

Here's my connection string

<add name="DefaultConnection" 
     connectionString="Data Source=localhost\sqlexpress;Initial   
        Catalog=OptimumWeightDB;Integrated Security=True;
        Integrated Security=True;
        User Id=sa;Password=mypassword" " 
     providerName="System.Data.SqlClient" />

This is the context class

public class OWDbContext : DbContext
{
    public OWDbContext()
        : base("DefaultConnection") { }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Richard77
  • 20,343
  • 46
  • 150
  • 252
  • 1
    There might be some help here: http://stackoverflow.com/questions/7313103/create-table-permission-denied-in-database-master, although that's for SQL Server 2008 Express. – Robert Harvey Apr 04 '13 at 23:39
  • Thank you for the link you provided. I've been able to access the engine from the management studio. I still can't access Sql Server from visual studio. I still get the same error. – Richard77 Apr 04 '13 at 23:59
  • I'd check your connection string, and make sure it connects to a user on SQL Server with CREATE DATABASE permissions (usually the sa user). Failing that, this is a developer machine, right? You really ought to be logged in as an Administrator. – Robert Harvey Apr 05 '13 at 00:01
  • 2
    I think Integrated Security=True is going to disregard the username/password you have supplied. Explicitly run SSMS "as Administrator" and see how you go? – ta.speot.is Apr 05 '13 at 05:21
  • @ta.speot.is, I didn't really get what you meant. Do I need to replace Integrated Security=True with SSPI? In fact, when I run visual studio as administrator, I'm able to connect to sql server. – Richard77 Apr 06 '13 at 01:13
  • 1
    My point was that specifying a username and password is redundant with integrated security=true. "Here's a username and password, but use my Windows account." – ta.speot.is Apr 06 '13 at 02:39
  • @ta.speot.is I removed the integrated security and left only the username and password. Now it's working. Thank you. – Richard77 Apr 06 '13 at 16:47

1 Answers1

1

First of all. Try to log into SQL Management Studio on your SQL Server using Windows Authentication.

If you can create database / manipulate database using you windows account there maybe a problem on the security set up on your sa login account.

Then try to re create / create new login account and set its permission to db admin.

Other thing make sure that SQL server Authentication is Enabled on your SQL Server.

When you already connected to your SQL Server using Windows Authentication right click your SQL Server > Properties > Security > SQL server and Windows Authentication mode.

also change your connection string to

Data Source=localhost\sqlexpress; Initial Catalog=OptimumWeightDB; user=yourloginname; password=yourpassword;

Best Regards

BizApps
  • 6,048
  • 9
  • 40
  • 62