The underlying provider failed on Open - c#

I'm using EntityFramework with Windows Azure platform. It works so well in LOCAL mode, but when I'm trying to run my Silverlight application on Web. I get an error:
The underlying provider failed on Open.
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="DomainServiceModule" preCondition="managedHandler" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<add key="ValidationSettings:UnobtrusiveValidationMode" value="WebForms" />
</appSettings>
<system.web>
<httpModules>
<add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpModules>
<customErrors mode="Off" />
<compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<httpRuntime requestValidationMode="4.5" targetFramework="4.5" encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<pages controlRenderingCompatibilityVersion="4.5" />
<machineKey compatibilityMode="Framework45" />
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<connectionStrings>
<add name="DatabaseEntities" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="data source=lnqg2ulkjr.database.windows.net;initial catalog=BuilderDatabase;persist security info=True;user id=XXXXX;password=XXXXX;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
I was checking that this is a problem in the connection string with Integrated Security but in my case I don't have that property. What could be the error?

This error is from Entity - it has little to do with Silverlight. It happens when one of two things happen:
Entity tries to log in to the database you've pointed it to, and is denied permission/can't find the server/can't find the instance/has some other connection error
Entity successfully logs in, but can't find the data model it recognizes
The second should be very simple to check since you have a working local. If the data model on your local is the same as the data model in your 'production' environment, then that part is taken care of. If you have tables that are different, you could have some issues. This is doubly true if they are missing columns that you've coded in to Entity's data model. Entity will tolerate extra columns and extra tables in many cases, though this changes a lot based on the situation, so YMMV. However, if Entity expects something to be there and it's not, it'll crash with a quickness every time.
My larger suspicion would be that rather awesome connection string you have there. You should be able to check the InnerException on what you're getting to see the specific gripe that the database server is raising. If it isn't, I would rip that out into a console application and attempt to connect with a plain jane SqlConnection doing a simple Select count(Id) from dbo.SmallTable. This will allow you to isolate the connection problems and deal with them in a nice, restricted environment. After you've sorted through the connection issues, you can paste your connection string - now hopefully less confusing - back in and move on.

Related

ASP.NET application restarting for no apparent reason

I know this issue has been brought up a lot, but no matter what I try, it just doesn't seem to solve my issue.
My ASP.NET Web Forms application keeps restarting at what appears to be completely random time intervals, although they seem to normally range between 30 to 60 minutes. I most recently tried to run the application in ServerState instead of InProc, but this did nothing to solve the problem.
There does not seem to be any exceptions thrown, and neither the Error event nor the Shutdown event in Global.aspx are triggered when this happens. Instead, the Application_Start event is suddenly triggered and everything is reset to its initial state.
I read that changing certain files or changing files in critical directories would cause this to happen, but checking the modification date of each file when this occurs shows that not a single file in the application folder has been modified.
I have run the ANTS Memory Profiler to see if there are any memory leaks or other memory related issues that could lay ground to the issue, but memory usage seems completely stable, and never reaches any dramatic levels. At most the memory usage was at about 200 MB, where the CLR and ANTS itself stood for half of the usage. Either way, the issue seems to happen irregardless of the level of memory usage at the specific time.
I am deploying the application to a remote server. I do not have access to the server or any IIS configurations, so there is no way for me to actually adjust or monitor anything myself, although I can of course contact the people running the servers to help me do this. The restarts happen both when I run the application on my local IIS Express and on the remote server, but it does however seem to restart more often on the remote server.
I've added the contents of the Web.config file below. It's located in the root directory.
<configuration>
<appSettings>
<add key="ChartImageHandler" value="storage=file;timeout=20;url=~/VTT/Charts/;"/>
<add key="aspnet:MaxHttpCollectionKeys" value="100000"/>
</appSettings>
<connectionStrings>
<add name="DBConnString" providerName="System.Data.SqlClient"
connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=DBC;Connection Timeout=120;Integrated Security=true;Trusted_Connection=true;"/>
</connectionStrings>
<system.web>
<httpHandlers>
<add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false" />
</httpHandlers>
<sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" cookieless="false" timeout="60"></sessionState>
<compilation debug="true" optimizeCompilations="false" targetFramework="4.5">
<assemblies>
<add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<customErrors mode="Off"></customErrors>
<httpRuntime targetFramework="4.5.1" executionTimeout="3600" maxRequestLength="10240"/>
<globalization culture="" uiCulture=""/>
<authentication mode="Windows">
<forms loginUrl="Default.aspx" defaultUrl="Default.aspx" name="adAuthCookie" timeout="60" path="/"/>
</authentication>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
<pages maintainScrollPositionOnPostBack="true">
<controls>
<add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
</system.web>
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="Default.aspx" />
</files>
</defaultDocument>
<caching>
<profiles>
<add extension=".ico" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
</profiles>
</caching>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="ChartImageHandler" />
<add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
And the Web.Release.config transformation file. (I switched out the connection string parameters for obvious reasons; they are all in order.)
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="DBConnString"
connectionString="Data Source=<server>;Initial Catalog=<cat>;User ID=<userid>;Password=<password>"
xdt:Transform="Replace" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation debug="false" optimizeCompilations="true" xdt:Transform="SetAttributes(debug,optimizeCompilations)" />
</system.web>
</configuration>
Currently this issue is completely ruining my work, and my customer is extremely unhappy with constantly losing work due to application restarts. I'm at a complete loss on what to do. Any suggestions?

WIF Framework for .NET MVC in multiple environments?

I am new to Windows Identity Framework. My organization has multiple environments that make use of different 'authority' and 'endpoint' names. My application can detect the environment at runtime. I've looked through the WIF documentation and through stackoverflow and am not, thus far, able to find anything that I can use to help me with this problem.
The example below works in my localhost environment:
<add key="ida:FederationMetadataLocation" value="https://test.login.mycompany.com/FederationMetadata/2007- 06/FederationMetadata1.xml" />
<add key="ida:Realm" value="https://localhost/webapp" />
<add key="ida:AudienceUri" value="https://localhost/webapp/" />
In my development environment the same section needs to be:
<add key="ida:FederationMetadataLocation" value="https://dev.login.mycompany.com/FederationMetadata/2007-06/FederationMetadata1.xml" />
<add key="ida:Realm" value="https://dev.mycompany.com/webapp" />
<add key="ida:AudienceUri" value="https://dev.mycompany.com/webapp/" />
I also need to make similar changes to the AudienceURIs and the federationConfiguration.
Here is the full localhost web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!--Added for Windows Identity Framework -->
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<!--END: Added for Windows Identity Framework -->
</configSections>
<appSettings>
<!--Added for Windows Identity Framework -->
<add key="ida:FederationMetadataLocation" value="https://test.login.mycompany.com/FederationMetadata/2007-06/FederationMetadata1.xml" />
<add key="ida:Realm" value="https://localhost/webapp" />
<add key="ida:AudienceUri" value="https://localhost/webapp/" />
<!--END: Added for Windows Identity Framework -->
</appSettings>
<system.web>
...
</system.web>
<system.webServer>
<!--Added for Windows Identity Framework -->
<modules>
<add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
<add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />
</modules>
<!--END: Added for Windows Identity Framework -->
</system.webServer>
<runtime>
<assemblyBinding ...
</assemblyBinding>
</runtime>
<!--Added for Windows Identity Framework -->
<system.identityModel>
<identityConfiguration>
<audienceUris>
<add value="https://localhost/webapp" />
<add value="https://localhost/webapp/FederationResult/" />
</audienceUris>
<securityTokenHandlers>
...
</securityTokenHandlers>
<certificateValidation certificateValidationMode="None" />
<issuerNameRegistry type="System.IdentityModel.Tokens.ValidatingIssuerNameRegistry, System.IdentityModel.Tokens.ValidatingIssuerNameRegistry">
<authority name="http://test.login.mycompany.com/adfs/services/trust">
<keys>
<add thumbprint="123320493" />
</keys>
<validIssuers>
<add name="http://test.login.mycompany.com/adfs/services/trust" />
</validIssuers>
</authority>
</issuerNameRegistry>
</identityConfiguration>
</system.identityModel>
<system.identityModel.services>
<federationConfiguration>
<wsFederation
issuer="https://test.login.mycompany.com/adfs/ls/"
realm="https://localhost/webapp/"
reply="https://localhost/webapp/"
passiveRedirectEnabled="true"
requireHttps="true" />
<cookieHandler name="LocalFedAuthRounding" requireSsl="true" />
</federationConfiguration>
</system.identityModel.services>
<!--Added for Windows Identity Framework -->
</configuration>
Does the WIF provide methods to do this? I've looked through the documents and can't figure out how to make these changes.
Thanks,
Matt
The identity and access tool from Visual Studio only allows for one "authority" at a time. If you want a different authority per environment (say your site is deployed in TST, acceptance and production) then you will need to consider web config transforms at deploy time to configure the correct authority.
However, if you need to accept security tokens from multiple authorities in the same deployed website, then you need to manually merge the section for system.IdentityModel into one. WIF supports (It will try each option one by one) this but IDA doesn't. The system.identityModel.Services part is trickier since that is where you tell WIF how to do a redirect for a passive login scenario. That part you will need to do manually in code. It's not that hard. After all, you just need to redirect to a -cleverly composed - url.
You can also use something like Windows AZure ACS or Thinktecture Identity Server to shield the different identity providers from your application. Identity providers (authorities in your parlance) then get added at the STS level and your app just trusts the STS. Also, do not forget the signout which should be redirected to the same identity provider you used to log in in the first place.
I answered a very similar question just lately but since the answer hasn't been accepted, I can't make your question a duplicate of that one
Authentication against multiple identity providers using WSFederationAuthenticationModule for asp.net
Basically, you do everything in few lines of code instead of relying on the static configuration.

Could not install package 'Microsoft.Owin.Security 2.0.2'

i am trying to install SignalR on my Website ( Not a Web application ) (using visual studio 2012 ), when i created my website ( File--New Website ) i selected .net 4.5, my problem is when i am installing SignalR with Nuget Package this error happens
Install failed. Rolling back...
Could not install package 'Microsoft.Owin.Security 2.0.2'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references that are compatible with that framework. For more information, contact the package author.
on also in my web.config line <httpRuntime targetFramework="4.5"/> says
the targetFramework attribute is not allowed.
and my web.config is
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="KutSocialNetworkConnectionString" connectionString="Data Source=.;Initial Catalog=KutSocialNetwork;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<appSettings>
<add key="path" value=""/>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*"
path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>
</configuration>
So it was Easy , i downloaded directly from Nuget , and also delete my webconfig and created a new One

System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection

when I debug my project, there are 5 messages (example: Could not find schema information for the element 'entityFramework'. Web.config) and the application doesn't work (error: Unable to find the requested .Net Framework Data Provider. It may not be installed.).
Web.config:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.1.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<customErrors mode="Off" />
<authentication mode="None" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="Data Source=.\SQLEXPRESS ; Integrated Security=True; MultipleActiveResultSets=True" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<connectionStrings>
<add name="HistoryContainer" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="data source=|DataDirectory|\Database1.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
And the object 'System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection' doesn't exist.
What should I do? Thanks.
I had a similar error and I've got rid of it. My web config however referred to a version of 4.4 (not 4.3.1 as you have) which as far as I know doesn't exist. This arose after I grabbed a starter package for the WebAPI with MVC4 from somewhere or other.
V4.3.1 and now V5.0 pre-release do exist as of Aug 2012
I got the nuget package for 4.3.1 using the solution level "library package manager". This is an important step as I could choose which projects to apply it to.
During this process, my web config was changed (to ref 4.3.1) and the problem went away.
What bugs me is that reference to "System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection" cos I cant find where it exists but at least VS isn't complaining any more.

Getting Security Exception SQLCE 4, Code First CTP 5 & Shared Hosting

I've been trying to setup a webpage with MVC3 Razor, SQLCE 4 and Code First, the last two downloaded from Nuget, so it is EF Code First CTP5.
I've had a lot of trouble, but I manage to move forward by following this answer
However now I am getting this Security Exception
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.
I thought it should work without full trust so I don't know what is wrong now.
I am using GoDaddy shared hosting with .Net 4 and IIS7
What could be the issue?
EDIT:
I haven't modified the web.config, except for setting custom errors = false to be able to see the exceptions, otherwise I have the webconfig that was generated by using Nuget to get and configure SQLCE and Code first
This is how it is:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=152368
-->
<configuration>
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<system.web>
<customErrors
mode="Off"
/>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
</configuration>
It seems to be a bug with CTP5 that will be fixed in final release.
http://connect.microsoft.com/VisualStudio/feedback/details/641462/ef-code-first-issue-with-medium-trust
Hmmm as I said in the first comment on the question, it is an error with Code First CTP5, which uses full trust instead of medium trust. Source

Categories