Deploying an ASP.net application - asp.net-mvc

What is the correct proceedure when deploying an ASP.net MVC application? I am using the built in forms based authentication and deploying using the publish function in VS2008 but when deploying it doesn't seem to deploy the ASPNETDB to the server and I end up with errors like
An error occurred during the execution of the SQL file 'InstallCommon.sql'. The SQL error number is 1802 and the SqlException message is: CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\INETPUB\WWWROOT\HOURS3\APP_DATA\ASPNETDB_TMP.MDF'.
I looked this up and attempted to change the sql server to run under the local system account as per
http://forums.asp.net/t/984436.aspx
but that doesn't seem to have helped.

When you try to publish this way, I believe you're going to overwrite your database with the one you are currently developing with. This means if you had any changes in your web environment, such as new users, you would lose them when you overwrote them in a publish. Additionally the reason you're probably getting permission denied, is because the file is already in use by the website, and Windows doesn't like it if you try deleting a file that is in use.
Typically I set my databases to publish in a different methodology than the ASP.net files. I often generate an upgrade script using a tool such as RedGate SQL Compare. This allows me to upgrade the one live on the server instead of copying a new file.

Related

How to update remote database using FTP or File System publishing method using code first migration

I have deployed my ASP.NET MVC application using FTP publishing method, application was working fine until i republished it after making some changes, i used code first migration to update database locally and it was working fine. When i published it again i am getting the error saying:"Model backing a DB Context has changed; Consider Code First Migrations". When using web deploy publishing method there is no problem database is updated, problem is when using FTP or File System publishing.
I would like to know how can remote database be updated when using FTP or File System publishing method. My current host doesn't offer web deploy publishing, is either i use FTP or File system.
Can anyone assist?
If you are using the File System publishing method and happen to make changes to your Models, then you will have to re-publish your project and just replace it with the one existing on the Server.
I found solution, all i have to do was to add the following code in DbContext like:
public InvoiceContext()
: base("InvoiceContext")
{
System.Data.Entity.Database.SetInitializer(new
MigrateDatabaseToLatestVersion<InvoiceContext,
Identity2Example.Migrations.InvoiceContext.Configuration>());
}
I hope it will also help somebody.

Deploying Website with Migration using FTP

I have an asp.net MVC website making extensive use of ef and migrations.
i have tried deploying it to a system running windows 10 on a local network but seems like ms has removed that options from the latest release and now deployment using web deploy is only possible on server os's.
No trying to do the same using FTP.
whats the ay to deploy using ftp on a local server. I have already setup FTP publishing but cant seem to figure out how to deploy the db and configure the app to run code first migration after every deploy.
The accepted answer in this forum post helped me out with this exact issue. I added the code given there to Application_Start in my Global.asax.cs
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyObjectContext, MyObjextContextMigration>());
MyObjectContext contexttest= new MyObjectContext();
contexttest.Database.Initialize(true);
Just be aware that this will run your seed method every time you visit your site (at least it did for me). In my configuration.cs I put in a check to see if data existed in my tables, if that data was null then it was ok to seed that table, etc.

ASP.NET MVC3 Aspnetdb Sql Production Server

I created a fully functioning web application (MVC MusicStore, downloaded from here: http://mvcmusicstore.codeplex.com/).
The application created an ASPNETDB.MDF file, and a MusicStoreDB.mdf file.
I used SQL Server Management 2008 R2.
The problem is that after I deploy the application on a host server,
when clicking on "Register" link, the default error page is displayed.
When trying to log in, the default error page is displayed yet again.
It appears that the host server (which is SQL 2008 compatible) can read data from the MusicStoreDB.mdf file, but has no access to the ASPNETDB.MDF file. It is not possible to log in or register users.
I did change the connection string in the web.config file to the host server address, it works fine.
I also created the ASPNETDB tables in the MusicStoreDB by using aspnet_regsql, but the errors persist.
Also, the MusicStoreDB file contained no data after Publish (though there is sample data in a cs file). I know the host server can read data from this file because I manually added data through a local SQL server.
I have two questions:
a. What are the steps to correctly deploy the application and databases so that it would be possible to register and log in? How can the both mdf files work in consort?
b. How can the data in the SampleData.cs file be recreated in the MusicStoreDB.mdf file?
I haven't been able to find an answer over the web, though I've been searching for a week...

Trying to call svn.exe from batch file called by .NET webpage - odd results

The situation: I have a mvc.net web page which, when called, runs a batch file on my server using System.Diagnostics.Process.Start and cmd.exe. The batch file contains a line that runs "svn.exe update myfilepath" and should therefore update the files on the server.
What's happening?
- the batch file is running, but the call to svn.exe does nothing, nor produces any error messages.
- if I run the batch file by double clicking, the svn command DOES run successfully.
I guess this is a security issue, but I'm no expert on this and I cannot make any headway.
The site is hosted on Windows Server 2008 R2 and the app pool is using the ApplicationPoolIdentity system. I have tried running the app pool as Network Service and also adding Network Service as a user that can Read/Execute to svn.exe.
Please help!
This could be proxy related. It's possible that you access the Internet via a proxy, but that the user profile for the app pool identity isn't configured like this. You may need to use a domain account that you can log on as in order to create a suitable user profile. You will also need to make sure IIS is loading the profile by ticking the appropriate option.
(Another possibility is that the working directory for the process you are starting is not set correctly to the root of your Subversion working copy. We've established this wasn't the problem in your case.)

How can I create a local user profile for the anonymous user of an ASP.Net MVC application under IIS 7?

I've been experimenting with ASP.Net MVC, and have come across a problem that is probably not specifically MVC related. But I cannot get the authentication in the default MVC application (the one created by the wizard when you create a new MVC project) to work properly under IIS 7 on Windows 7.
If I run under the Visual Studio environment, it works, but if I switch the settings to run under IIS instead, I get the following exception trying to submit the login or registration:
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 believe that this is because the website runs under my own account in Visual Studio, but under the IUSR account in IIS. Google searches on the exception message have been unhelpful so far.
So, can one create a local user profile for the IUSR account? If so, how? Is there something else I should be doing to get the SQLExpress engine to work under the anonymous account in IIS 7?
I also tried configuring the IIS website to use my account, but since this is my home machine, my account doesn't have a password, and it appears that IIS won't let a website be configured to use an account without a password. Or, since this is my first experience with IIS 7, and configuration feels very different than IIS 5/6, I am just missing the right setting that will let me configure the account to use for anonymous access.
EDIT: Some additional information. If I empty the App_Data folder and try again from IIS, SQLExpress attempts to create my database and fails, but the exception message has further information with the following suggestions.
SQLExpress database file auto-creation
error:
The connection string specifies a
local Sql Server Express instance
using a database location within the
applications App_Data directory. The
provider attempted to automatically
create the application services
database because the provider
determined that the database does not
exist. The following configuration
requirements are necessary to
successfully check for existence of
the application services database and
automatically create the application
services database:
If the applications App_Data directory does not already exist, the
web server account must have read and
write access to the applications
directory. This is necessary because
the web server account will
automatically create the App_Data
directory if it does not already
exist.
If the applications App_Data directory already exists, the web
server account only requires read and
write access to the applications
App_Data directory. This is necessary
because the web server account will
attempt to verify that the Sql Server
Express database already exists within
the applications App_Data directory.
Revoking read access on the App_Data
directory from the web server account
will prevent the provider from
correctly determining if the Sql
Server Express database already
exists. This will cause an error when
the provider attempts to create a
duplicate of an already existing
database. Write access is required
because the web server accounts
credentials are used when creating the
new database.
Sql Server Express must be installed on the machine.
The process identity for the web server account must have a local user
profile. See the readme document for
details on how to create a local user
profile for both machine and domain
accounts.
I've pretty extensively confirmed that the first three suggestions have been satisfied. The fourth seems to be the cause of my problems, but I can't figure out how to do that. And although the suggestion claims there is a readme document that describes it, I have not been able to find that document.
I got this problem as well running under medium trust. The process that creates the database requires at least High trust. You can check this by looking in your Web.Config for
<trust level="TrustLevel" />
If there is no trust specified in your Web.Config, try adding it and set it to either Full or High. If this doesn't work, there is a machine.config in your IIS which you would need to modify.
That being said, the best route I have found to solve this is to just use aspnet_regsql.exe to create the necessary tables and then change the connection string in your Web.Config to look at it directly.
I solved "The directory 'LocalApplicationData' does not exist." error when running an SSIS package through an SQL Job by ensuring the SQL SSIS service and SQL Server Agent service were running under the same account as the swql job was set to use!
This in my case was a domain account.
Solution: Try UNINSTALLING any updates before you started experiencing the issue. I spent countless hours - wasted hours that I will never get back in my life - reading and following every solution possible without success. I uninstalled all SQL Server updates and now everything works fine.

Resources