Cannot use SQL server (LocalDB) after moving from IIS Express to Local IIS - iis

When I run my website under local IIS instead of embedded IIS express I got the following error when accessing database (mdf file at app_data)
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified)
Here the connection string:
Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Sources\Local\WebApplication1\WebApplication1\App_Data\aspnet-WebApplication1-20140226022052.mdf;Integrated Security=True
From Visual Studio and IIS Express I could connect to that database:
https://db.tt/rBXiwyA5
But the issue is that I need to have access to deployed application from another computer and IIS Express doesn't allow remote connections. That is why I was forced to use Local IIS.
Thank you for any advises!

you may need to double escape the \
"Data Source=(LocalDB)\v11.0;Integrated Security=true"
Unable to connect to localDB in VS2012 – "A network-related or instance-specific error occurred while establishing a connection to SQL Server..."

If you are using EntityFramework, try put it on App.config, worked for me.
<?xml version="1.0" encoding="utf-8"?>
<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=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>

There are couple of things to try:
Provide the connection string in the format of, e.g.
Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-WebApplication;Integrated Security=SSPI
On IIS, right click on the related App Pool then go to Advanced Settings, then set "Load User Profile" to true.
In my experience this did not change anything, so I had to do this manually in the applicationHost.config file found in C:\Windows\System32\inetsrv\config. Specifically, make sure "loadUserProfile" and "setProfileEnvironment" properties are set to true:
<applicationPools>
..
<add name="MyAppPool" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
..
<applicationPools>
Alternatively you could try changing Identity under App Pool
Advanced Settings from ApplicationPoolIdentity to
LocalSystem.
After doing one of these things you will hopefully stop getting this error, yet you may find that the application behaves as if there is no data in the database. This is because unlike SQLExpress or SQL Server, LocalDB runs as a user-specific process. Hence you might need to seed the database for the current database user (depending on the Application Pool/Identity being used) .

these links might provide an answer:
http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-1-user-profile.aspx
http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-2-instance-ownership.aspx

Related

Cache Host config in Azure In-Role caching

Accordingly to this MSDN article (on AppFabric Caching, which is what Azure is run on), I should be able to find a DistributedCacheService.exe.config file located at \Windows\System32\AppFabric, but it doesn't exist on any of the instances.
When remoting into one of the instances and searching for configs, I find several cache-related config files in E:\plugins\Caching.
The CacheService.config.exe file looks very promising (similar to DistributedCacheService .exe.config), except that the dataCacheConfig is not initialized:
<dataCacheConfig cacheHostName="">
<!-- Comment/uncomment below line to disable/enable file sink logging.
Also location attribute is not honored. It is just specified since its mandatory. -->
<!--<log logLevel="3" location="" />-->
<clusterConfig connectionString="" />
</dataCacheConfig>
I need to confirm that certain data cache settings are being configured properly on the server side in order to solve a previous post of mine.
My client-side web.config looks something like this:
<dataCacheClients>
<dataCacheClient name="DataCache1">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="6400000" maxBufferSize="256" />
</dataCacheClient>
<dataCacheClient name="DataCache2">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="0" maxBufferSize="10485760" />
</dataCacheClient>
<dataCacheClient name="DataCache3">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="3276800" maxBufferSize="32768" />
</dataCacheClient>
</dataCacheClients>
Where do I find the cache host configuration file in Azure In-Role caching (colocated)?
The host property that you configure in on premise AppFabric cache is dynamically initialized in InRole Cache. You can check Caching.csplugin at Program Files\Microsoft SDKs\Windows Azure.NET SDK\v2.2\bin\plugins\Caching to see the endpoints for the cache server.

Azure project lost endpoints and uses default now?

A weird thing happened to my project. I have an Azure WCF project which basically consists of the WebRole and the Azure project. Azure Project contains ServiceDefinition.csdef which in turn contains stuff like endpoint information.
I was playing around in my WebRole and manually set an endpoint there. However, my original issue, due to a stupid user error, did not require this. After I removed the endpoint devinition from web.config, my webrole still gets bound to port 6627 instead of the two endpoints described in my Azure project (80 & 8080). I can't find that port being mentioned anywhere so I'm guessing it is the default.
Here's the part of the web.config that I edited (the removed part is in comments). How do I revert back to getting the configuration from the Azure project?
<system.serviceModel>
<!-- services>
<service name="MyWebRole.MyService" behaviorConfiguration="MyWebRole.BasicUserInformationBehavior">
<endpoint address="" binding="mexHttpBinding" contract="MyWebRole.IMyService"/>
</service>
</services -->
<extensions>
<behaviorExtensions>
<add name="userInformationProcessor" type="MyWebRole.BasicUserInformationBehaviorExtensionElement, MyWebRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<bindings />
<client />
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<userInformationProcessor />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
[Edit] More information on the subject! The problem is related to compute emulator no longer starting at all! I don't know why the service works then, but I guess it's running it IIS alone.
I think the solution as mentioned in the comment is that you have to set up the Windows Azure project as the startup project not the webrole.

IIS applicationHost 'setEnvironment' attribute

<add name="ASP.NET v4.0" autoStart="true" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
I'm adding that in appliationHost config of IIS to solve localDb problem in IIS what I see in this article
http://blogs.msdn.com/b/sqlexpress/archive/2011/12/09/using-localdb-with-full-iis-part-1-user-profile.aspx
Can you guys help me to avoid this error?
Unrecognized attribute 'setProfileEnvironment'
It looks like you are attempting to place the value inside of an actual application pool. That attribute lives outside of a defined application pool, and lives in appicationpooldefaults.
<applicationPoolDefaults>
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
<applicationPoolDefaults>
Quick search for the error you provided points to outdated or broken IIS (the assembly that implements setProfileEnvironment attribute, or one of its dependencies, is either missing or broken). At least that's best guess based on the data provided.

Get .net to handle all requests in IIS7

I had an application that was running on IIS 6. All requests went through aspnet_isapi.dll. This was achieved via a wildcard application mapping (which did not verify the file existed).
I have copied said application to a machine running IIS7, and would like to get it working again.
In the application, any request with an extension of .aspx (or .ashx) are handled in the normal way. Other requests with different extensions (such as .html and .xml) are handled by a custom http module. Some requests have no extension, and are dynamically redirect to a file with an extension (e.g. visiting …/item/1 might redirect to …/item/1.html or …/item/1.xml, depending on values in the accept header).
The new location probably does not exist, but a response is generated dynamically.
Currently, the application pool is in “classic” mode, and is using .NET v4.0 (it was previously using .NET 3.5, but that doesn’t seem to be related to the problem). The custom http module is set only in the web.config.
The redirect (from …/item/1 to …/item/1.html) seems to work, which suggests that extension less requests are indeed being processed by the application (that redirect is written in the application itself). I think that means that the custom module is working.
Requests with extensions (.html, .xml etc) are failing however. The error I get is:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Module: IIS Web Core
Notification: MapRequestHandler
Handler: StaticFile
Error Code: 0x80070002
I have tried:
Adding a wildcard script mapping that mapped * to aspnet_isapi.dll
Tried adding a specific mapping for *.html to aspnet_isapi.dll
These still result in the same error message, and still seem to go to the handler "StaticFile".
I tried modifying "StaticFile" so that it uses the aspnet_isapi.dll executable, and this results in a new error:
HTTP Error 404.4 - Not Found
The resource you are looking for does not have a handler associated with it.
Handler: Not yet determined
Any help would be greatly appreciated.
Set application pool in integrated mode and set that all request run all managed modules
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
...
</modules>
...
</system.webServer>
Use this config in service config it worked for me.
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfService.Service1">
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureHttpBinding"
contract="WcfService.IService1"/>
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>

SubSonic deployment and changing connectionstrings

I used Subsonic to build the DAL for one of my web applications. When I move it from my test server to the production server I change the connectionstring to point to the production datasource but the app still runs against the test DB. Is the connection information stored someplace else in addition to the Web.config?
What are the best practices for deploying web apps built using Subsonic?
TIA
John
In your SubSonicService configuration section, does the connectionStringName attribute point to the correct connection string?
Here is an example of my config.
<!--########################## Connection Strings ###############################-->
<connectionStrings>
<clear/>
<add name="Ajax"
connectionString="Data Source=Ajax1;Initial Catalog=AjaxExample_test;User ID=Webuser;Password=Pinecone!"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<!--########################## SubSonic ###############################-->
<SubSonicService defaultProvider="AjaxProv">
<providers>
<clear/>
<add name="AjaxProv" type="SubSonic.SqlDataProvider, SubSonic"
connectionStringName="Ajax"
generatedNamespace="ICBA.Web.SalesForce.StagingDAL"
appendWith=""
stripColumnText=""
relatedTableLoadPrefix=""
enableTrace="false"
extractClassNameFromSPName="false"
fixDatabaseObjectCasing="true"
fixPluralClassNames="true"
generateLazyLoads="false"
generateNullableProperties="true"
generateODSControllers="true"
generateRelatedTablesAsProperties="false"
includeProcedureList="*"
excludeTableList=""
includeTableList="*"
regexDictionaryReplace="TypeCode,typecode"
regexIgnoreCase="true"
removeUnderscores="true"
setPropertyDefaultsFromDatabase="false"
useExtendedProperties="false"
useSPs="true"/>
</providers>
</SubSonicService>

Resources