'This operation requires a connection to the 'master' database

I have suddenly started getting an error in my application.

The error is:

This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.

Nothing has changed in the code - and database access is fine throughout the rest of the code.

It stops on this line:

var filteredContacts = dc.EAContactLists.Where(o => teams.Contains(o.Team)).ToList();

I am lost on this one.



Solution 1:[1]

I had this issue and in my case resolved it by adding "Integrated Security=True" to the connection string. This only applies if you're connecting to the DB using Windows Authentication. Hope it helps.

Solution 2:[2]

This error happened to me and none of the above worked. Embarrassingly, I realised that I had missed out a semi-colon from the connection string. Might be useful...

Solution 3:[3]

Add Integrated Security=True for windows authentication.This worked for me.

Solution 4:[4]

Hello actually this problem persist if you are trying to make changes in the schema like creating the table or altering some object...

And you don't have privileges to do that..

If you are working with MVC and your database already exit in the server than this problem can be solved with the code

Database.SetInitializer<EmployeeContext>(null);

just add this code in the Global.asax file in the application_start Event method.

Solution 5:[5]

If you are working on windows authentication :

  • You can add "Integrated Security=True" to your connectionString.

For user authentication:

  • You must add sql server authentication informations ("uid=YourUserName; Password=yourpassword;") to your connectionString.

Solution 6:[6]

I am so stupid. I faced the same error and then I realized that I was running the update-database -verbose command in Package Manager Console in Release mode when I hadn't configured the transformations for release mode.

Here is the connectionstring format that worked for me in Debug mode.

Password=dumbeldore;Persist Security Info=True;User ID=johnmcclain;Initial Catalog=DB_diehard400;Data Source=killthatbill;

  • sensitive info in the connectionstring edited for security reasons. Please follow only the format.

Solution 7:[7]

For me the issue was that my password contained an & sign.

Solution 8:[8]

Make sure you aren't running Fiddler. Temporarily disabling traffic capture with F12 resolved the issue for me.

Solution 9:[9]

Had this same issue. Found out that in my connection string, where it says "Persist Security Info = True;", I was missing the semi-colon at the end. Added the semi-colon and everything worked

Solution 10:[10]

I Used this config in my code: Integrated Security=true;

as this:

<connectionStrings>
    <add name="MyContext" connectionString="Data Source=.;Initial Catalog = MyDatabase_DB; Integrated Security=true; MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
  </connectionStrings>

and it worked.