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.
Try setting Persist Security Info = True in your connection string.
Hope this helps.
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.
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...
Add Integrated Security=True for windows authentication.This worked for me.
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.
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.
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.
For me the issue was that my password contained an & sign.
Make sure you aren't running Fiddler. Temporarily disabling traffic capture with F12 resolved the issue for me.
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
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.
Related
I've had an Azure WebJob running for at least two years without any problems. The app.config contains the following...
<connectionStrings>
<add name="UniversalModelEntities" connectionString="dummy - the actual connection string is specified in the portal but for some reason we need this element here" providerName="System.Data.EntityClient" />
</connectionStrings>
And in the portal's Application Settings I have...
This has run without any problems... until this morning when I found the error
The connection string 'UniversalModelEntities' in the application's configuration file does not contain the required providerName attribute."
Everything I've found regarding Entity Framework connection strings in the Azure portal says that I should set that drop-down to Custom.
So what's the problem?
Furthermore, I've found that even if declare the full connection string in the app.config, I still get the same error message, which suggests that the problem lies in the portal's setting.
I managed to solve this problem by setting the drop-down option for the connection string to SQLAzure...
...which obviously results in an error, then changing it back to Custom...
Now the WebJob picks up the connection string correctly.
New to Azure and have difficulty to connect DB with webapp. I am playing with a demo project using entityframework and code first mitigation. It works as expected in my local computer and localdb. But it does not work when I try to deploy it to Azure. I use the Webapp and a SQLDatabase in Azure. Then, I try to connect them using connection string in Webconfig.
<add name="DefaultConnection" connectionString="Server=tcp:dritor.database.windows.net,1433;Database=dritorDB;User ID=****#dritor;Password={****};Encrypt=True;TrustServerCertificate=False;Connection Timeout=30" providerName="System.Data.SqlClient" />
The homepage shows up as expected. But when I try to fetch data from DB (I put some data with seed), it returns something as follows:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Message>An error has occurred.</Message>
</Error>
I suspect that I made the connectionstring wrong but I am not sure. Any suggestions on how to debug in this situation would be appreciated.
The string looks correct except for the curly braces around the password. It should just be Password=****
I am using ASP.NET MVC4 deployed on WebApps, EF6, Azure SQL Database
I have two connectionstrings, one direct to the DB and one that is needed as I am using Entity Framework. If I setup the first via Azure and leave the EF string in web.config, all works fine. Once I try to move the EF connectionstring to Azure, it breaks.
I have tried to follow all the posts on how to setup an EF connection string in Azure Management Portal, and the advice seems to be to use the following:
In Management Portal:
Name:
EFConnectionString
Value:
metadata=res://MyModel/model.csdl|res://MyModel/model.ssdl|res://MyModel/model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=tcp:myserver.database.windows.net,1234;Initial Catalog=mydatabase;User ID=Admin#myserver.database.windows.net;Password=12345678"
SQL Database:
Custom
Note:
" is replaced by " in the Azure string.
In Web.config I still need the following:
<add name="EFConnectionString" connectionString="" providerName="System.Data.EntityClient"/>
I have changed certain details in the connectionstring for security reasons, but the true string does work fine in Web.config.
However when I do attempt the above, I get :
The page cannot be displayed because an internal server error has occurred.
Further Log error message:
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
Any help appreciated. I am trying to do this to enhance the security of stored passwords for accessing DB on Azures, as I understand that setting them up via the portal encrypts them.
Thanks.
First check your deployment. I've run in a similar problem, and after a couple of hours struggling I found out that I was deploying without actually sending connection strings, falling back to whatever was in the portal config... the others keys in the we.config were being sent over, but the conn strings weren't... after I properly set it up on the portal, everything went back to normal...
I keep getting this error on my server when I publish my site - even without changes in database model.
The site is running fine local.
I'm using the DB first approach.
If I delete all files in the site on the server, restore my local database on the server. Publish the site from VS. Sometime it will run fine after that.
If I then make a few changes in the database CONTENT I will get the error.
I don't whant to create any database/tables on the server - just disable the part of the code, that need to do it. In MVC3 we had this DropCreateDatabaseIfModelChanges but I can't see any of that in my current site.
What can I do?
My connectionstring:
<connectionStrings>
<add name="GoBagHomeComEntities" connectionString="metadata=res://*/Models.GoBagHomeModel.csdl|res://*/Models.GoBagHomeModel.ssdl|res://*/Models.GoBagHomeModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlexpress;initial catalog=GoBagHomeCom;Persist Security Info=True;User ID=xx;Password=xxxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
And my dbcontext
public partial class GoBagHomeComEntities : DbContext
{
public GoBagHomeComEntities()
: base("name=GoBagHomeComEntities")
{
}
Check dbo.__MigrationHistory if you have records means EF is trying to migrate, so truncate the table and try it again.
if the same thing repeated so you might need to check EF weather it migrates as settings.
have a look to this answer this, you need to have the connection string in web.config file, I think this is the only missed thing.
It seems like the problem is solved :)
I'm sure Owin was the bad guy - I was only using it for creating the authentication cookie. Nothing about tables.
After remove all Owin related code on the site it's running.
If your bring any change in your database you should follow the following steps:
Update the .edmx file. To update it double click on .edmx when it will open, please right click on a blank space of this file and select "update model from database".
Save and close the file.
Build the project.
Copy .dll file from bin folder and past it where you have hosted your application.
I tried to override connectionstring in Azure portal with this connection :
Server=tcp:server.database.windows.net,1433;Database=mydatabase;User ID=username#server;Password=xxxxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
It gives me an error Keyword not supported: 'server' and when I tried it as:
metadata=res://*/DataAccess.MyDataBase.csdl|res://*/DataAccess.MyDataBase.ssdl|res://*/DataAccess.MyDataBase.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:server.database.windows.net,1433;initial catalog=MyDataBase;persist security info=True;user id=username#server;password=xxxxxx;MultipleActiveResultSets=True;App=EntityFramework""
It gives "Keyword not supported: 'metadata'. !!
So what is the exact connectionstring should I write ??
Also I tried all of connection string types as provided in the screenshot.
Ok I found an answer relative to my issue, but also I figured out something
First of all the connection string should be like
metadata=res://*/DataAccess.MyDataBase.csdl|res://*/DataAccess.MyDataBase.ssdl|res://*/DataAccess.MyDataBase.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:server.database.windows.net,1433;Database=MyDataBase;User ID=username#server;Password=xxxxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
And notice the quotation should be " not " , Also as Nick said it should be Custom .
The first connection string ('Server=..') is used for connecting directly to the database, without passing through Entity Framework.
The second connection string ('metadata=..') is an Entity Framework connection string. If you're using EF, you should mark the connection string in the Azure Management portal as 'Custom' as opposed to 'SQL Database'.
In the control panel, there is a spot on the Database Panel that says "Show database connection strings" that gives you complete connection strings for your database for ADO.Net, PHP, Java and ODBC. These can be used as a starting point, from which I added MARS support and a different user/password to mine.
Here is my connection string to help you out. We use this one to override in the Azure WebApps Control Panel.
Server=tcp:[AZURE_DB_NAME].database.windows.net,1433;Database=[DATABASE_NAME];User ID=[USER_ID];Password=[PASSWORD];Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;MultipleActiveResultSets=True
As to the Drop Down, we have it set to SQL Database.
One thing that comes to mind. Have you tried using your connection string in VS Debug mode to see what happens? You just have to configure your AzureDB to allow a remote connection from your IP for that to work. It could provide some insight for you that your connection is correct but something else is failing.
I tried solution from Mohamed Farrag but got this error:
System.ArgumentException: Keyword not supported:
'.ssdl|res://*/dataaccess.MyDataBase.msl;provider'.
After removing DataAccess. from my connection string it worked:
metadata=res://*/MyDataBase.csdl|res://*/MyDataBase.ssdl|res://*/MyDataBase.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:server.database.windows.net,1433;Database=MyDataBase;User ID=username#server;Password=xxxxxx;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"