Problem run web application asp.net mvc 3 under iis 7 - asp.net-mvc

I deployed my asp.net mvc 3 project under IIS 7 (Windows 7). Project contain attach *.mdf DB file in App_Data folder. First I got following error:
Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.
I removed it so change connection string in my web.config file - remove user instanse=true and in Application Pool -> Addvanced Setting -> Process Model -> Load User Profile set value TRUE and then I got next error:
CREATE DATABASE permission denied in database 'master'.
An attempt to attach an auto-named database for file C:\inetpub\wwwroot\assign\App_Data\AssignmentDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
my connection string is
<add name="AssignmentDBEntities" connectionString="metadata=res://*/Models.AssignmentDBModel.csdl|res://*/Models.AssignmentDBModel.ssdl|res://*/Models.AssignmentDBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\AssignmentDB.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I don't known how resolve this problem..((
someone can help me?

The account you're using to connect to the database (specified in the connection string) doesn't have a CREATE DATABASE permission. You need to grant this permission in order to be able to create database.
You can just execute sql command (http://msdn.microsoft.com/en-us/library/ms178569.aspx) or use Enterprise Manager to grant permission.
The user you need to grant the permission to is the one specified in the connection string or the account your website runs under if you're using integrated security.

Related

Publish Azure App With Database Connection String Using Active Directory Integrated Not Working

I have previously deployed an MVC application to Azure.
Under Publish -> Settings -> Databases, I include connection strings.
I have been using the following: Data Source=tcp:servername.database.windows.net,1433;Initial Catalog=dbname;User ID=username;Password=password;Encrypt=True;TrustServerCertificate=False
The problem with specifying a user is that stored procedures run as the user specified.
This results in CreatedBy/ModifiedBy values set to this same user, instead of the user that created/modified the record.
I previously tried the following: Data Source=tcp:servername.database.windows.net,1433;Initial Catalog=dbname;Persist Security Info=False;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Integrated"
However, I receive the error "The format of the specified domain name is invalid." after the application is deployed. Even though I test the connection with Active Directory Integrated in the Destination Connection String window, and it works.
As given in this MS Doc, if you’re using the AD Integrated type of Authentication in the Azure, then either you should have domain-joined device for accessing the Web Application linked with SQL Database or make the device as federations with ADFS.
So, if you are accessing the Azure Applications from other machines, use the AD-password type authentication mode and its connection string format is given in the same MS Document and this Doc2 for more relevant information on configuring the AD Integrated / Password Type of Authentication mode on Azure Data sources and applications.
AD Password Type Authentication Format: 
Server=demo.database.windows.net; Authentication=Active Directory Password; Encrypt=True; Database=sample_db; User Id=your_username#domain.com; Password=<Your__Password>

azure file share access via web application

C# ASP.NET MVC web application - I followed all the steps from https://blogs.iis.net/davidso/azurefile in order to be able to access my Azure location by unc.
My newly created local user is in the IISUSER Group and has the same username and pwd (storage key).
I then created an application in my website using a new APP Pool (integrated) w/said local user.
I ran the caspol command as well.
The issue I run into is when trying to do a file.SaveAs, I get an error
Incorrect username or password
Server.MapPath({application}) returns the correct unc path but doing a Directory.Exists won't locate the path.
When viewing the "connect as" with specified user in IIS I get no issues, additionally I can access the unc path directly from my local machine with same creds.
I tried going to the app pool of the application and set the user directly but no change there. Are there changes I need to make on the Website configuration that the application sits in? Prior to converting this to an application I initially had it configured as a virtual directory and got the same error.
Set the load user profile to "True" in the application pool:
try to set the azure user in iis anonymous authentication by clicking on the edit:

how to publish mvc 5 project in vs2017 to local iis

I want to publish a MVC5 project to local IIS, I need to correct set connection string, Permissions and application pool in IIS and every things that help me to do it.
When I publish, I see this error.
Cannot open database "MyProjectDB" requested by the login. The login failed.
Login failed for user 'WORKGROUP\DESKTOP-1O5A46C$'.
I solved this problem.
Create a text file (a.txt) in my pc desktop and chenge to (a.udl).
open (a.udl) and set Connection
and test connection
if success then close udl window.
then open with note pad (a.udl) and copy
Integrated Security=SSPI; Persist Security Info=False; Initial
Catalog=MyProjectDB; Data Source=.
and Replace to default connection string in Connection String to your Website in IIS.

Aspnet core deployment to IIS - HTTP Error 502.3

I have created the IIS site and pointed it at the deployment folder. I have enabled stdout logging and this is the error:
info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
User profile is available. Using 'C:\Users\No Managed Code\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
fail: Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler[1]
An exception occurred in the database while iterating the results of a query.
System.Data.SqlClient.SqlException: Cannot open database "KeyStoneDb" requested by the login. The login failed.
Login failed for user 'IIS APPPOOL\No Managed Code'.
So, I added the login to SQL with all the necessary rights. Retested in DEV - fine, but when running IIS I still get the issue. The Application Pool being used is 'No Managed Code'.
Why cant the app not connect to the database?
IIS AppPool accounts are virtual accounts, therefore, they don't actually exist as a normal user on the system.
You can not give access to networked resources using that identity. Shared\network resources like file shares and databases that need to communicate with these accounts need to have the 'domain\machinename$' with appropriate permissions.
Give 'domain\machinename$' appropriate permissions on your DB. That should do it.

Unable to login to Azure V12 Database from MVC EF6 app

I have an MVC, EF6 app using SQL Azure. I just upgraded my server on Azure to V12. I'm able to run my app successfully locally using connection strings that point to my SQL Azure database. Howerver, if I attempt to run my app from the Azure web host, I'm not able to. I get an error saying 'Unable to login for user Tour'. The name of my database is Tour, but I don't have a user account named tour. The only user I have is one named WAND.
Again, my apps connects to SQL Azure fine if I run it locally. But not if I access it from my Azure webhost.
I've also executed the following, which I read I had to do with V12: exec sp_set_firewall_rule N'Allow Windows Azure','0.0.0.0','0.0.0.0';
I don't know why it's trying to connect via a user named Tour (the name of my database).
My connection strings look as follows:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=---;Initial Catalog=Tour;User Id=WAND#ServerName;Password=---;" providerName="System.Data.SqlClient"/>
<add name="TourEntities" connectionString="metadata=res://*/Tour.csdl|res://*/Tour.ssdl|res://*/Tour.msl;provider=System.Data.SqlClient;provider connection string="data source=----; initial catalog=Tour; User Id=WAND#ServerName;Password=---;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"/>
</connectionStrings>
To me this seems as if you have connection string set on Azure itself which modifies your connection string in web.config after deployment.
You didn't state if you are using App Service - Web App or just VM, but I will assume the former.
Go to old portal, select your web app, go to Configure tab and check if you have any entries under "Connection strings" section. I've attached the sample image on how this section looks like if you aren't familiar with it.

Resources