Advanced LightSwitch debugging (part 3 of N): debug a production app locally with production database connection


A challenge for the reader walking through this post on LightSwitch debugging is to understand the slight variations in debugging scenario’s I’m presenting here.

The problem

Ok, so let’s try to give the concrete setting for this case: you have an application in production (with of course a connection to a production database). Imagine there is a problem that you can’t reproduce, you suspect it has to do with the database. Mhmm.. that sounds like the very article in this series: Getting production data in your localdb. Well, sort of but not completely. This time we don’t copy any data to the local db. We try to debug the application locally in the IIS but we keep (in the web.config), the connection to the production database.  Why would you not simply use scenario 1 here? Well, in the first place because this scenario is, from a practical perspective, simpler than scenario 1. But, more important this scenario has the big advantage that you use not only the production data (like in scenario 1), but also that you use the real production database connection and furthermore the connection to this database is established by a real IIS.

Disclaimer: for simplicity I use here the word production app and production database. Obviously, you should always be careful with production material. It’s better to speak about “production-alike”. In most enterprises, there are apart from the production environment also staging or acceptance environments, which are from infrastructural perspective similar to each other. You should use those !


Don’t expect here now a large description as in scenario 2. This is really very simple:

Step 1: deploy your app to the local IIS

I presume here that you are familiar with deploying to IIS.

  • start visual studio as local admin
  • make sure to deploy the debug version and not the release version.
  • Make sure to NOT publish the database scheme: so UNCHECK “publish database schema”. Provide the correct connection string (to the production alike database):


Step 2: Start the application in your browser (http://localhost/myapp)

So, first check if you can log in.

Step 3: Attach the debugger and start reproducing any problems

Attaching a debugger is already explained in my previous post.



A simple but very powerful debugging scenario.