Mark
Mark

Reputation: 7818

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.

Upvotes: 31

Views: 40947

Answers (11)

Rasoul FaCh
Rasoul FaCh

Reputation: 1

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.

Upvotes: -1

Titius Yusinyu
Titius Yusinyu

Reputation: 1

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

Upvotes: -1

Some guy
Some guy

Reputation: 567

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

Upvotes: 0

Bill Berlington
Bill Berlington

Reputation: 2414

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.

Upvotes: 0

İsmail DENİZ
İsmail DENİZ

Reputation: 41

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.

Upvotes: 3

Anup Shetty
Anup Shetty

Reputation: 571

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

Upvotes: 9

KrisG
KrisG

Reputation: 149

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

Upvotes: -1

user3429672
user3429672

Reputation: 237

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...

Upvotes: 13

Shashank Chaturvedi
Shashank Chaturvedi

Reputation: 2793

Try setting Persist Security Info = True in your connection string.

Hope this helps.

Upvotes: 47

Steve Terry
Steve Terry

Reputation: 256

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.

Upvotes: 17

rakeshyadvanshi
rakeshyadvanshi

Reputation: 293

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.

Upvotes: 3

Related Questions