6/29/11

Microsoft LightSwitch – Clinic Sample SQLExpress Database Errors

If you are working on the Microsoft LightSwitch sample, and you have SQL Express 2005 or you do not have a SQL Express instance at all, you will face a couple of problems running the sample.

The first problem is that the sample was implemented with version of Microsoft SQL Express 2008. If you have the SQL Express 2005 version you will get the following incompatibility error:

The database cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported.

To address this, you will need to upgrade that instance to SQL Express 2008. The latest at the time of this blog is the R2 version. Make sure to keep the SQLExpress instance name, otherwise you will face the next problem.

The LightSwitch sample projects have the SQL express instance name hardcoded in the project file. If you have a different instance name, and you try to update the data source to your instance name, you will soon discover that this does not work. When you compile the project you will continue to get the following error:

An error occurred while establishing a connection to SQL Server instance '.\SQLEXPRESS'

To address this error, you should edit the project file which has the extension lsproj and look for the property SqlExpressInstanceName. You should replace the SQLExpress instance name for the instance name from your environment.

Once you have made those changes, the sample application should run without a problem.

Hope it helps.

og-bit.com

6/21/11

WCF - Could not find a base address that matches scheme

This error indicates that there is no base address handling the request on that particular scheme (http/https) and base address (url).  For example, your WCF web service based address in the web.config may be this:

  • http://mysite.com/myservice.svc    (WCF allows a single based address per scheme http/https)



IIS may be configured to support multiple base addresses like these:

  • http://mysite.com
  • http://www.mysite.com
If you try to load the url http://www.mysite.com/myservice.svc IIS resolves the address, but the WCF setting is in conflict, and an error is shown. Using the web.config, we can add a setting to filter the IIS base address that does not mapped to the WCF based address (add the setting in the system.serviceModel node).

<serviceHostingEnvironment>
       <baseAddressPrefixFilters>
       <add prefix="http://www.mysite.com" />
      </baseAddressPrefixFilters>
</serviceHostingEnvironment>

This should eliminate the conflict, and the request should go to base address defined by the web.config. In addition, a common mistake is that the baseAddressPrefixFilters may be set to the same base address of the WCF service. This filters out the base address and causes the “Could not find base address error”. Following our previous scenario, if you add the setting below, the error will be recreated.

<serviceHostingEnvironment>
 <baseAddressPrefixFilters>
   <add prefix="http://mysite.com" /> (filters The wcf base address – error is shown)
   <add prefix="http://www.mysite.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>

I hope this helps.

6/14/11

TFS – How to Record Support Hours on an Iteration

In project management, there is always a need to record how much work is being done to troubleshoot and/or identify issues for a particular release.  To address this, we could set up a team project with the following settings:

Area and Iteration Path:
Create an area path specifically for support issues. For example, the area path could read the following:
Area Path
   Description
Support\Stage
Use this for the staging environment
Support\Production
Use this for the production environment

This allows us to track supporting tasks done in either the staging or production environment.
The iteration path should be set to your software iteration. For example, if in stage you are running version 2.13.0, and you need to create a support task to troubleshoot something in stage. You set the area path to stage and the iteration to version 2.13.0. The same can be applied when a task needs to be created on a production release. This allows us to track the number of tasks in each environment and for each release/iteration

Task Detail:
When you create a task, the task should be created with this additional information:
Property
   Value
   Description
Discipline
Analysis
This depends on the template you are using on TFS. You may create another entry that reads Support.
Type
Corrective or Mitigation
On stage you may use Corrective to correct problems before production. On production , you can use Mitigation because you need to minimize the impact of the problem
(Details tab)  Schedule Estimate
hours
The estimated hours
(Details tab)  Schedule Remaining work
hours
The work still remaining. This is important to update because a tasks may not be completed the same day, but you need to report the number of hours left.
(Details tab)  Completed  work
hours
The hours completed in the tasks

 It is important to add the completed work and remaining work to the correct Area and iteration path. This would be the only way that the reports can accurately show how much support effort is being done and in what iteration. This can lead to a better understanding of the development process and identify possible issues.
I hope this is useful.

og-bit.com

6/9/11

WCF Security token in the message could not be validated when using Custom authentication

The security token error is usually generated from a SecurityTokenValidation exception during the Username and password validation process.   This error is usually displayed as follows:

[MessageSecurityException: An unsecured or incorrectly secured fault was received from the other party. This fault may have been sent in response to an improperly secured request. See the inner FaultException for the fault code and detail.]

og-bit.com
The inner exception displays this error:

At least one security token in the message could not be validated.

This error does not tell us much about the problem, but we know there is a security problem. A way to troubleshoot this is to first enable logging on the web service. We enable the logging of the messages at the transport level by adding the following diagnostics settings in your web.config file inside the system.serviceModel node.
<system.serviceModel>
<diagnostics>
<messageLogging maxMessagesToLog="25000" logEntireMessage="true" logMessagesAtServiceLevel="false"  logMalformedMessages="true" logMessagesAtTransportLevel="true">
<filters><clear/></filters>
</messageLogging>
</diagnostics>
We now need to create a file that we can open with Microsoft Trace viewer by adding this setting under the system.diagnostic node: (notice the name and location of the log file)
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Warning, ActivityTracing" propagateActivity="true" >
<listeners> <add name="xml" /></listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Warning">
   <listeners><add name="xml" /></listeners>
</source>
</sources>
<sharedListeners>
   <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="C:\Temp\myService.svclog" />
</sharedListeners>
You can now deploy the web.config changes in your test environment and send a couple of request. If you do this on production, make sure to remove the settings after recreating the problem. Once you have recreated the problem, look for the log file (see initializeData attribute) and open it with trace viewer. We are looking for items highlighted in red under the Activity tab (left pane). Select one of those messages and on the right-top pane look for a message that reads "Throwing an exception". Select that message and inspect the details under the XML tab(see image below). There, we can find a detail stack dump of what is really causing the problem. You can look carefully for the class name in your project, and you would probably be able to identify exactly what may have gone wrong.
I hope this helps.



og-bit.com

6/7/11

WCF Service IIS specified authentication schemes error

If after deploying your WCF service, you are getting this error:
InvalidOperationException: IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme.


You are probably using an activation host factory that does not agree with the IIS settings. The error means that the IIS application configuration has been set to support multiple authentication schemes, but when the service is trying to get activated it does not know which authentication scheme to use (ambiguous). There is a good chance that your development environment is configured differently which may explain why the error was not generated during your unit test.

To solve this problem, we first need to identify the IIS settings on the server where the application is getting the error. Open IIS manager, select the web application node and select the authentication icon (IIS7, use directory security tab for IIS6). Most of the time, production environments will be configured to support the following schemes:

Anonymous and Windows authentication.








We should now match those settings in the development environment and try to recreate the error.  Once the error is recreated in the development environment, we need to identify why our service does not support the multiple authentication schemes. Open the SVC file and look for the Factory property.  This factory property makes it easy to auto configure our services when there are no configuration settings in the web.config.  This error is commonly created when the host factory is set to use WebScriptServiceHostFactory which adds an ASP.Net AJAX end point to the service. This dynamic endpoint is the one being used for the web service, and it is causing your application to generate the error.

<%@ ServiceHost Language="C#" Debug="true" Service="Web.MyService" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"%>

To address this problem, change the factory to use the ServiceHostFactory which supports multiple authentication schemes or just remove the factory attribute all together. By removing the factory attribute, the service uses the information from the web.config.

<%@ ServiceHost Language="C#" Debug="true" Service="Web.MyService" Factory="System.ServiceModel.Activation.ServiceHostFactory"%>

I hope this helps.

og-bit.com

6/2/11

LINQ to SQL Using Where in

In SQL, you can compare against multiple values by using the IN operator. A normal select statement with the IN operator looks as follows:

select * from AuditLog
where log_id in (1111,2222,3333)
What if we need to use LINQ to SQL to accomplish the same? The approach is to use an array and use the Contains method to compare against the columns values. This is what the SQL statement listed above looks in LINQ:
int[] ids = { 1111, 2222, 3333 };

from log in dbcontext.AuditLog
where ids.Contains(log.log_id)
select log
We first declare an integer array with the values we are looking for. We then use the Contains method to compare the values. If you add a SQL trace, you will be able to see how this LINQ statement is translated into a SQL statement that uses the IN operator.
*Note:  dbcontext is the data context class that is created when a dbml file is added to the project. This is what generates the LINQ classes that are used for the database access.
I hope this is useful.

og-bit.com