Question: I have a local *ASP.NET MVC 3 Windows Azure Project* where I use a local instance of *MSSQL Express* for my emulator.

In my **web.config** I have the following connection string:

`<add name="ExampleDb" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ExampleDb;User Instance=true;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />`

For debugging purposes I have the following in my **WebRole.cs** file:

```
public override bool OnStart() 
{
    ExampleDb context = new ExampleDb();
    context.ExampleItemEntries.Add(new ExampleItem() { ExampleItemId = 1, Att1 = "1", Att2 = "2" });
    context.SaveChanges();     
    return base.OnStart();
}

```

When I perform this action I can actually see the content in my code-first generated database (using Entity Framework). Database: ExampleDb, Table: ExampleItem. 

However, doing the exact same thing in *ExampleController* **does NOT** update the database. Instead this data goes somewhere else (I have no idea where). When I visit my controller via the browser I can upload data and look at it but it is not stored in my ExampleDb database, only data sent from WebRole.cs is in the database.

*Any ideas what's causing this behaviour?*

**ExampleDb.cs** looks like this:

```
public class ExampleDb : DbContext
{
    public ExampleDb() : base("ExampleDb") { }
    public DbSet<ExampleItem> ExampleItemEntries { get; set; }     
}

```

Answer: 
Your connection string contains 'User Instance=True'. This means that SQLEXPRESS uses a user instance to store your data. This is a completely different instance of SQL Server that contains a new set of databases.

I assume the code in WebRole.cs is run in a different user account than the code in ExampleController. When the ExampleController is run under a user account that is not an administrator, a user instance is used...

So when you remove 'User Instance=True' from your connectionstring and assign the proper access rights to your SQLEXPRESS database instance, that would solve the problem.
In CodeFirst Model you should define the connection string in the web.config first as below:

```
<connectionStrings>
 <add name="ExampleDbConnection"
      connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;
                   database=ExampleDb;
                   AttachDBFilename=|YouDataDirectory|yourdb.mdf;
                   User Instance=true"
       providerName="System.Data.SqlClient" />
<connectionStrings/>

```

The DbContext class constructor accepts a name-value pair specifiying connection-string name in web.config. So you can reference this connection string in your context:

```
class ExampleDb : DbContext
{
  public ExampleDb() : base("name=ExampleDbConnection") { }
  ...
}

```

This code does work fine in a ASP.NET MVC Web Role so you can try as above.