I’m deploying an ASP.NET MVC application and I’m having difficulty with the web.config. The application will be deployed to our server, but will be accessing a database on a different, off-site server. I’m getting the following error when trying to load a page that accesses the database:
Server Error in ‘/’ Application.
Login failed for user ‘LOCALSERVERNAME$’.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Data.SqlClient.SqlException: Login failed for user ‘LOCALSERVERNAME$’.
The connection strings in web.config look like this:
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
<add name="AppEntities" connectionString="metadata=res://*/Models.Model.csdl|res://*/Models.Model.ssdl|res://*/Models.Model.msl;provider=System.Data.SqlClient;provider connection string="Data Source=EXTERNALSERVERNAME;Password=****;User ID=****;Initial Catalog=AppData;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
So the error is for authentication the local server, which is just hosting the files. Plain ASP pages within the application which don’t interact with the database are being served properly. The problem only seems to appear when trying to access the database, which is on a completely different server. I also know the connection string for the off-site server to be correct, it works in other applications.
I rarely handle config stuff, and I work in an extremely restricted environment, so this has been difficult to troubleshoot. Any help is very much appreciated.
This usually means that the server accessing the database resides on another machine that does not have permissions to the database it is trying to access. More information can be found here