Sometimes a collection or complex data structure needs to be delivered to a SQL database for storage. Strongly typed stored procedure schemas do not make it apparent what is required to pass XML data type parameter values (they are presented as xs:string types).
What you need to do is pass the XML parameter content as a CDATA section. The CDATA section is stripped by the adapter/binding and inserted as required.
Your BizTalk map needs to compose the request document using some XSL-T like this (where ContentParam is the parameter name and //SrcContent is a parent element containing a well-formed XML structure):
<ContentParam xmlns="http://schemas.microsoft.com/Sql/2008/05/TypedProcedures/dbo">
<xsl:variable name="CDATABegin" select="string('<![CDATA[')" />
<xsl:variable name="CDATAEnd" select="string(']]>')" />
<xsl:value-of select="$CDATABegin" disable-output-escaping="yes"/>
<xsl:copy-of select="//SrcContent/@*" />
<xsl:copy-of select="//SrcContent/*" />
<xsl:value-of select="$CDATAEnd" disable-output-escaping="yes"/>
</ContentParam>
Showing posts with label wcf. Show all posts
Showing posts with label wcf. Show all posts
Wednesday, November 6, 2013
Monday, November 22, 2010
WCF SQL Adapter Composite Operation Timeout
Microsoft.ServiceModel.Channels.Common.InvalidUriException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. ---> System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
This error occurs when using a WCF SQL adapter composite operation with more operations than maxConnectionPoolSize where each operation returns a record set. This is independent of whether useAmbientTransaction is enabled or not. The result set could be as simple as @@ROWCOUNT.
It seems there may be an IDataReader created for each result set. Each result stream retains an open connection until all the requests have been executed. If there are more requests than there are connections available in the connection pool the process will exhaust all available connections in the pool and subsequently fall over.
To fix the issue, redesign the solution or remove the result set from the equation.
[Update] A colleague of mine reworked his sproc to use output parameters to allow a simple response to be returned and avoided this timeout issue.
This error occurs when using a WCF SQL adapter composite operation with more operations than maxConnectionPoolSize where each operation returns a record set. This is independent of whether useAmbientTransaction is enabled or not. The result set could be as simple as @@ROWCOUNT.
It seems there may be an IDataReader created for each result set. Each result stream retains an open connection until all the requests have been executed. If there are more requests than there are connections available in the connection pool the process will exhaust all available connections in the pool and subsequently fall over.
To fix the issue, redesign the solution or remove the result set from the equation.
[Update] A colleague of mine reworked his sproc to use output parameters to allow a simple response to be returned and avoided this timeout issue.
Tuesday, April 20, 2010
WCF LOB Adapter Ambient Transaction Suppression
The WCF LOB Adapter SDK literature explains some considerations when developing your own LOB adapters. One of these considerations is performance when invoked by BizTalk because loading the channel and subsequent call to LOB adapters is done within a TransactionScope.
Like the other DAL LOB adapters, for example, the WCF SQL Adapter, it is likely you will want to execute some operations outside of the ambient transaction. This will improve performance and allow you to access target systems that do not support distributed transactions.
To suppress the ambient transaction you will need to:
bool useAmbientXact = this.Connection.ConnectionFactory.Adapter.UseAmbientTransaction;
TransactionScopeOption xactOption = (useAmbientXact ? TransactionScopeOption.Required : TransactionScopeOption.Suppress);
using (TransactionScope xactCoOrdinator = new TransactionScope(xactOption))
{
// Execute target system commands here...
}
Like the other DAL LOB adapters, for example, the WCF SQL Adapter, it is likely you will want to execute some operations outside of the ambient transaction. This will improve performance and allow you to access target systems that do not support distributed transactions.
To suppress the ambient transaction you will need to:
- Implement a UseAmbientTransaction binding property
- Wrap calls to target systems within a new transaction scope
bool useAmbientXact = this.Connection.ConnectionFactory.Adapter.UseAmbientTransaction;
TransactionScopeOption xactOption = (useAmbientXact ? TransactionScopeOption.Required : TransactionScopeOption.Suppress);
using (TransactionScope xactCoOrdinator = new TransactionScope(xactOption))
{
// Execute target system commands here...
}
Subscribe to:
Posts (Atom)