Cannot open database error in Windows Server 2012 - asp.net

I'm trying to host my website in Windows Server 2012, I've configured everything and placed my site folder in wwwroot, when I launch from the IIS as a localhost I get this error at start,
Cannot open database "rental_db" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\mysitename.com'.
I've used Windows Authentication to login in sql server and I can access it properly. I'm not sure what is actually causing the problem. Here is the connection string code of web.config,
<add name="rental_dbEntities" connectionString="metadata=res://*/Models.rentalModel.csdl|res://*/Models.rentalModel.ssdl|res://*/Models.rentalModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MYSERVER2012\SQLINSTANCENAME;initial catalog=rental_db;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Note: I've shifted my published project folder from my desktop to server. Why is this happening?

You need create on your IIS App_Pool with the same name, and create in your SQL Server the user with all privileges.

Related

SQL login fail for user IIS

I have an ASP.NET application and it's working fine with Visual Studio IDE. I installed IIS and added a virtual directory. Now I get an error "login fail for user domain\computer name".
My connection string which is still working fine in ide run:
<add name="cricConnectionString"
connectionString="Data Source=AMDKLAPTOP031\RAMDEV;Initial Catalog=cric;Integrated Security=True"
providerName="System.Data.SqlClient" />
but I get an error when its run using IIS:
System.Data.SqlClient.SqlException: Login failed for user domain\computername$
When I tried to add new login in SQL Server, it can't find domain\computername shown in the error. domain\computername is not a valid name because it contains invalid characters. Error code is 15006
You need to add a login to SQL Server for IIS APPPOOL\ASP.NET v4.0 and grant permissions to the database.
In SSMS, under the server, expand Security, then right click Logins and select "New Login...".
Read more from here
Login failed for user 'IIS APPPOOL\ASP.NET v4.0'

IIS and SQL Server Windows authentication in a django application

I am trying to run a django website which connects to a SQL Server, using IIS with Windows authentication.
IIS server and SQL server are on different machines under the same domain i.e., iis_machine.example.com and sql_machine.example.com
What I'm trying to achieve:
Impersonate the remote user accessing the django website hosted on
IIS, so his Windows credentials are passed to SQL Server for
authentication.
What I tried so far:
Added this to my web.config file for impersonation
<system.web>
<identity impersonate="true" />
</system.web>
Enabled Windows authentication and set up Application Pool (django_web) for django website as shown below
This is what my Authentication for django website looks like in IIS
This is what my Application Pool for django website looks like in IIS
Added IIS APPPOOL\django_web to SQL Server Security\Logins
Result:
When I access the django website, IIS prompts the user for his
Windows credentials and I can successfully login
If user tries to access SQL Server after logging in
Case a. IIS, SQL Server are on the different machines: SQL server authentication fails with
"Login failed for user 'domain\MACHINENAME$'
Case b. IIS, SQL Server are on the same machine, SQL server authentication is successful but authentication credentials used are IIS APPPOOL\django_web not domain\remote_user
I understand that there is some Kerberos trickery involved with this setup. Unfortunately, I'm only a programmer and not very familiar with how Kerberos works. If someone experienced in this domain, could shed some light on how this setup would work, that'd be really appreciated. Thanks!
I am using:
IIS 10 SQL
Server 2014
django 2.0.7
Python 3.6.5
Windows 8/10

Asp.Net MVC 5 Project on IIS, Login failed DOMAIN\MACHINE$ for Sql

I am developing a website with the Asp.net MVC5 template. This website have obviously a database with some informations. This MS-Sql database runs on a remote VM. While coding I tested this site with the integrated IIS Express and the mentioned database.
Now I wanted to publish this website on a real IIS 10.0 Server, this IIS Server runs on the same VM as the database.
I published the website as follow:
Right click on project in VS15 > Publish > File System (Publish Method) > Copied the compiled data to the mentioned VM > In the IIS Manager I created a new website based on the compiled source data.
Now the problem:
When I try to run this website (localhost or via remote from my client) the following error occurs:
Login failed for user 'DOMAIN\MACHINENAME$'.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'DOMAIN\MACHINENAME$'.
This two connectionstrings are in my web.config, both are autogenerated from Asp.Net Frameork:
<connectionStrings>
<add name="InfoScreenContext" connectionString="data source=vsdev1972\;initial catalog=InfoScreen;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
<add name="UserProfile" connectionString="data source=vsdev1972\;initial catalog=InfoScreen;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
I was searching a whole day for a solution but none of these approaches worked for me:
Adding this DOMAIN\MACHINENAME$ user to the database users
Enabled Windows Authentication in IIS Manager
Tried to edit the connection string
Granted source access for everyone
Any ideas? If u need any further informations pls contact me!

Internet Explorer Cannot display the webpage when starting a silverlight app

I have a strange problem setting up my webapplications. I have a clean webserver machine where I have two web applications. One is a asp.net application while the other is a silverlight application. Both should use the same database hosted on an external db server.
My problem is that while my asp.net application is working as it should my silerlight application is not even loaded. Loads for about a minute (No silverlight loading indicator) before I get the Internet Explorer cannot display the webpage with following information:
•Internet connectivity has been lost.
•The website is temporarily unavailable.
•The Domain Name Server (DNS) is not reachable.
•The Domain Name Server (DNS) does not have a listing for the website's domain.
•There might be a typing error in the address.
•If this is an HTTPS (secure) address, click Tools, click Internet Options, click Advanced, and check to be sure the SSL and TLS protocols are enabled under the security section.
If I change my connectionstring in web.config for the silverlight application to connect to the test db server (also external) it works fine.
This tells me that the applications should be configured correctly?
connectionstring : <add name="myConn" connectionString="Data Source=prod_server;Initial Catalog=mydb;Persist Security Info=True;User ID=myusername;Password=mysecretpassword" providerName="System.Data.SqlClient"/>
They are running in the same application pool. I have also tried setting them up in separate applicationpools with no luck.
Fiddler reports an 504 error, but why does my web application work? This IIS 7.5
Hope someone can help
Solved it. Was a db update that timed out. Some developers should learn to use logging!

Very slow response for Visual Studio 2005 Web Site Administration Tool

I am working on an ASP.NET application and am trying to add user authentication. As a first step, I am using the Web Site Administration tool (Website | ASP.NET Configuration) to manage users and permissions.
Accessing this website is incredibly slow. To load the main page takes 30 seconds. When navigating to the Security page (also 30 seconds), I am presented with this error:
I have authentication mode set to "Forms" in the web.config file.
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.
The following message may help in diagnosing the problem: Unable to connect to SQL Server database.
It asks me to run "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regsql.exe", which also gives me an error message.
How do I fix these problems with speed and enabling security/users?
The issue that you are getting is due to an invalid SQL Server connection, you can setup the SQL Server connection in the web.config, once it is able to actually connect to the database, it will perform in the proper manner.
EDIT below is the code needed in web.config to setup the new connection
<connectionStrings>
<clear />
<add name="LocalSqlServer" connectionString="server=yourservername;database=somedatabasename;etc..." />
</connectionStrings>

Resources