LightSwitch v1 shows red X and unable to load data

2020-03-25 11:16发布

问题:

I have made an application using Visual Studio LightSwitch 2011 (v1) running on Visual Studio 2010 Professional. It is a desktop application, and I use SQL Server Authentication to connect to the database. (Same username/password for all clients).

The application works perfectly for most users, but for 4-5 users, it is showing a red X and says that it is unable to load data. This is the most vague error message ever, and I have no idea what could cause it. The users are all able to access our database from their PCs because some other non-lightswitch applications are working fine. This rules out any network/connectivity issues.

After days of searching and trying to figure this out, I haven't found an easy way to determine what the cause of the red-X error is. Also, the users are located in a different country so I don't have physical access to their machines. The only thing I have to go on is that these users are all running Windows 7 (no firewalls installed). One of them finally did a clean-install of Windows 7, and on installing the application, he got the red-X (unable to load data) error.

Is there any easy way to figure out why lightswitch is unable to load data from our database? (Database = SQL Server 2005)

Thanks for the help.

回答1:

Check out Eric Erhardt's article. Here's a quote:

When your application fails to load data successfully, the screen will display a red X and the tool tip will say “Unable to load data. Please check your network connection and try loading again.”

A little known secret about LightSwitch is that the server has a Diagnostics subsystem integrated with ASP.NET tracing. LightSwitch’s Diagnostics subsystem is a lot more powerful than just telling you what exception was thrown when issuing a query. You can use it to trace through the actions that were requested of the server, and what steps the server took in response to each action. So even if things seem to be working, you can get more information about what your application was actually doing.

So you can enable diagnostics then open the trace at: your-lightswitch-application-address/trace.axd. You can then check the error details (screenshot taken from the blog article):

Another alternative way is to use Fiddler. It is also explained in the same article.



回答2:

Thanks to Bryan Hong for pointing me in the right direction. I just want to put my findings in one place for others to refer to if they find themselves in the same situation.

The following is based off Eric Erhardt's article, which is meant for Lightswitch Web Applications. The steps I list below should apply to Lightswitch Desktop Applications instead.

Enable tracing in your lightswitch application. To do this, I had to modify the Web.config file located in the release/publish folder (not the file located in the Source folder for your project - LightSwitch will override that web.config -- this was the tricky part). Use a plain text editor to make changes to this: modify the following keys in configuration>>appSettings:

    <!-- A value of true will enable diagnostic logging on the server -->
    <add key="Microsoft.LightSwitch.Trace.Enabled" value="true" />
    <!-- A value of true only lets local access to Trace.axd -->
    <add key="Microsoft.LightSwitch.Trace.LocalOnly" value="false" />
    <!-- The valid values for the trace level are: None, Error, Warning, Information, Verbose -->
    <add key="Microsoft.LightSwitch.Trace.Level" value="Verbose" />

And under configuration>>system.web, make sure trace is enabled:

    <!-- LightSwitch trace.axd handler -->
    <trace enabled="true" localOnly="false" requestLimit="40" writeToDiagnosticsTrace="false" traceMode="SortByTime" mostRecent="true" />

And the last change that you need to make is to set the customErrors mode to Off under configuration>>system.web

Add the following key (or modify it if it already exists):

    <customErrors mode="Off" />

Now, to view the errors, install Fiddler and then run Fiddler, and the run the silverlight Application. Click on the session on the left, then click on Inspectors, and Web Inspectors on the right. This should show the error message in detail.

For more information, please refer to Bryan's answer above, or to Eric Erhardt's article.



回答3:

It happened to me when I tried to add a reference that didn't have portable support into the common (it came up with a warning when I added it, but I didn't listen at first). If you've done that, uncheck the reference and it should be fine



回答4:

I had same issue after updating my MDF and LDF it's started working. Meaning if you make any changes in database and the entity framework schema is not updated equally than you see this error. it's worked in my case