Thursday, May 17, 2012

Deployment GOTCHA's

Over the past several days I've been deploying two Visual Studio LightSwitch 2011 applications to my company's intranet server. I may revise this for Visual Studio 11 at a later time.

The 1st application was a packaged application, meaning I developed it on my personal computer zipped it and then gave it to my employers admin to install (namely Me, I'm the admin)

The 2nd application was deployed directly to the server from my work laptop. Needless to say neither went as smooth as I had hoped but I did learn some valuable lessons along the way.

NOTE: In this article I'm going to talk about what I did to deploy the 2nd application, a "WEB application", directly to the server, I'll be pointing out some issues I came across. The environment is restricted access to the application using Windows Authentication on my company's Intranet server. I'll talk about deploying a package at a little later time.

Disclaimer: Every scenario will not be discussed here, I can only comment on what worked best for me. I'm not a server administrator so please keep reading with that in mind.

I hope you find what I've learned useful.

Guides

First and foremost keep these two references handy:

 1. Beth Massi's Deployment Guide: How to Configure a Web Server to Host LightSwitch Applications She goes over in detail on how to setup your server.

2. Eric Erhardt's Diagnosing Problems in a Deployed 3-Tier LightSwitch Application (Eric Erhardt)

Also I highly recommend installing Fiddler2 to debug your browsers traffic. It's proved to be valuable resource for me.


 If using DevExpress XtraReports

The DevExpress XtraReports Suite is fantastic, but I've come across some GOTCHAS when it comes to deploying.

 1st you need to ensure that under the Server and Server Generated - References folders that all the DevExpress libraries property Copy Local is set to true. Thank you Supreet Tare for this tip.

One of the things that kept happening to me was that for some reason when I did a Release build  some of the libraries were changing back to false (will troubleshoot that later).

 If you receive the error message "Load operation failed for query 'GetAuthenticationInfo'" on your deployed application, this message is really misleading a lot of times so check that the libraries have not been set to false.

GOTCHA Update 5/18/12 - XtraReports running under Authentication mode ASP.Net Impersonation is not supported at this time, this prevents XtraReports from accessing the database. 
DevExpress has provided a workaround on their Support Forum (90% down the page) - 
http://www.devexpress.com/Support/Center/Question/Details/Q385592


Deployment Checklist

ON THE APPLICATION HOST

I followed Beth Massi's Deployment Guide: How to Configure a Web Server to Host LightSwitch Applications to install all the LightSwitch pre requisites on the server.

Ask your server admin to assist with these if you don't have access:
  1.  Install the Windows Platform Installer on the server as well as on your development machine - makes life a lot easier, trust me.
  2. Install the Web Deployment tool on both the server and development machine I used version 1.1
  3. Get the credentials of an account that can connect to the server and has appropriate permissions to install your app - i.e. server admin.
  4. Get the credentials of the SQL Server user that will perform read / write functions to the database on the behalf of your users -Publishing Wizard-Database Connection-Specify the user connection: is where this goes. Or you can click the Create Database Login button and LightSwitch will take care of this.
  5. Get the credentials of the SQL Server Application Administrator - this is the user that will be allowed to create roles, assign privileges to roles, create user accounts and assign users to roles for your application. Or you can select the Yes, create the Application Administrator at this time radio button, fill in the details and LightSwitch will take care of this.
  6. I created ahead of time an APPPOOL with .NET 4.0 and Integrated management. I'm going to assign my application to this APPPOOL.
  7. If supporting multiple users a maintenance time saver is to create a host server group and add all your users to this group, Once the application database is created, add the group to the database server logins and assign db_dataread and db_datawrite privileges for your applications database to this group. Now everyone is updated in one place Woo!Hoo!
    
NOTE: I will update this once I get into controlling access through Active Directory groups.


ON THE DEVELOPMENT MACHINE

Manually Copy your database files to the server. 
Open SQL Server Express Management Studio right click your database and select Tasks-Generate Scripts


Then make sure that the radio button for "Script entire database and all database objects" is selected. PLEASE NOTE: This tool does not script any Triggers - this was a GOTCHA. But we can remedy this by copying and pasting the trigger into the appropriate location on the production server.

Save the output to a convenient location then copy the zip file over to the production server.

Switch to the Production Server
 Open the zip file you just copied in the SQL Server Management Studio and execute the scripts to create the production database, then create the appropriate triggers on your tables.

Once the database is set up go to the SQL Server Security folder and right click the user you created in step 4 above and select properties


 Select User Mappings and then the database you just created

Assign aspnet_Memebership_BasicAccess, aspnet_Memebership_FullAccess, aspnet_Memebership_ReportingAccess, aspnet_Roles_BasicAccess, aspnet_Roles_FullAccess,
aspnet_Roles_ReportingAccess, db_datareader, and db_datawriter to this account. Public is selected by default. Click OK
Open the database Security-Users folder and you will see that this user has been added.


Switch back to your development machine

Publishing:

 In the Publishing Wizard Dialog Box under DataBase Connections and Other Connections, change the Data Source to the Server that will be hosting the application and the user credentials to the appropriate users you specified above.

In Other Connections, for DevEpress.XtraReports and my WCF Ria Services I put bin for location.

Switch to the Production Server  
Open IIS Manager, if icon is not available, click Start and in Search Programs and files box, type in inetmgr.

Select your new virtual directory then in the Actions panel Select Basic Settings...
In the dialog box select the Select Button and then choose the APPPOOL you created in step 6 above. Click OK and OK again.
Make sure your on the /project Home page.


NOTE: If you need to Trace the application please refer to
Eric Erhardt's Diagnosing Problems in a Deployed 3-Tier LightSwitch Application (Eric Erhardt)

Under IIS select Authentication, again you can just double click this icon or in the Actions panel select Open Feature

I enabled Windows Authentication and ASP.NET Impersonation, all other settings are disabled.
Ok this is one other GOTCHA I ran across.

Revision 5/17/12 - You can set these settings before deploying, in Visual Studio - Select your projects top node and click File View then select All Files, navigate to the ServerGenerated folder and open the Web.config file and make your changes.

With the project selected, in the Actions panel select Explore open your web.config file by right clicking and choosing Edit(you may have to give yourself read / write privs first).

Scroll down to your connection strings, make sure that all of the data sources are set to the production server and not the development machine, I had an issue where one of my WCF Ria Services still pointed to my development machine.

Save your changes and close this file, you may even want to revoke the write privs for your account.

Now if you have Fiddler installed you may want to run this first, but it's not required.
If you enabled Tracing,  just navigate to http://{your server}/{your project}/trace.axd

Back on the /project Home page, in the Actions pane under Manage Application click Browse *.80(http) or Browse *.443(https) if your running under SSL.
I chose the Browse *.80(http) link, run your application step through your screens, give it a thorough thrashing to make sure everything is working as it should from the server.

Now all I have to do is troubleshoot an issue with one of my WCF Ria Services,  hopefully by the end of today I'll have that resolved.


Once resolved I can re-publish to the server and I'll invite my co-workers to test out my application and once everything has been tested, debugged and if necessary fixed and tested again. I'll be ready to release it to my users.

Hope this helps.
- Keith


GOTCHA UPDATES

- 5/30/2012
1. Make sure your database compatibility mode is set to at least SQL Server 2008, SysAdmin or DBO roles can set this in the Options panel of the database properties.

.NetCore 2.0, AzureAD and OpenIdConnect

.NetCore 2.0, AzureAD and OpenIdConnect If you develop with .NetCore you probably already know that there are some significant changes fr...