<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>NET &#8211; Prologika</title>
	<atom:link href="https://prologika.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>https://prologika.com</link>
	<description>Business Intelligence Consulting and Training in Atlanta</description>
	<lastBuildDate>Tue, 16 Feb 2021 09:29:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Web API CORS Adventures</title>
		<link>https://prologika.com/web-api-cors-adventures/</link>
					<comments>https://prologika.com/web-api-cors-adventures/#respond</comments>
		
		<dc:creator><![CDATA[Prologika - Teo Lachev]]></dc:creator>
		<pubDate>Tue, 10 Sep 2013 02:30:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[NET]]></category>
		<guid isPermaLink="false">/CS/blogs/blog/archive/2013/09/09/web-api-cors-adventures.aspx</guid>

					<description><![CDATA[I&#8217;ve been doing some work with ASP.NET Web API and I&#8217;m setting a demo service in the cloud (more on this in a future post). The service could be potentially [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve been doing some work with ASP.NET <a href="http://www.asp.net/web-api">Web API</a> and I&#8217;m setting a demo service in the cloud (more on this in a future post). The service could be potentially accessed by any user. For demo purposes, I wanted to show how jQuery script in a web page can invoke the service. Of course, this requires a cross-domain Javascript call. If you have experience with web services programming, you might recall that a few years ago this scenario was notoriously difficult to implement because the browsers would just drop the call. However, with the recent interest in cloud deployments, things are getting much easier although traps await you.</p>
<p>I settled on ASP.NET Web API because of its invocation simplicity and gaining popularity. If you are new to Web API, check the Your First Web API <a href="http://www.asp.net/web-api">tutorial</a>. To execute safely, Javascript cross-domain calls need to adhere to the Cross-origin resource sharing (CORS) <a href="http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing">mechanism</a>. To update your Web API service to support CORS, you need to update your ASP.NET MVC 4 project as described here. This involves installing the Microsoft ASP.NET Cross-origin Support package (currently in a prerelease state) and its dependencies. You need also the latest version of System.Web.Helpers, System.Web.MVC, and other packages. Once all dependencies are updated, add the following line to the end of the Register method of WebApiConfig.cs</p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt;"><span style="background-color: white;">config.EnableCors(<span style="color: blue;">new<span style="color: black;"> <span style="color: #2b91af;">EnableCorsAttribute<span style="color: black;">(<span style="color: #a31515;">&#8220;*&#8221;<span style="color: black;">, <span style="color: #a31515;">&#8220;*&#8221;<span style="color: black;">, <span style="color: #a31515;">&#8220;*&#8221;<span style="color: black;">));</span></span></span></span></span></span></span></span></span></span></span> </span></p>
<p>After testing locally, I&#8217;ve deployed the service to a Virtual Machine running on Azure (no surprises here). For the client, I changed the index.cshtml view to use jQuery to make the call via HTTP POST. I decided on POST because I didn&#8217;t want to deal with JSONP complexity and because the payload of the complex object I&#8217;m passing might exceed 1,024 bytes. The most important code section in the client-side script is:</p>
<p><span style="color: blue; font-family: Consolas; font-size: 9pt; background-color: white;">var<span style="color: black;"> DTO = JSON.stringify(payload); </span></span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">jQuery.support.cors = <span style="color: blue;">true<span style="color: black;">; </span></span></span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">$.ajax({ </span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">url: <span style="color: #a31515;">&#8216;http://&lt;server URL&gt;&#8217;<span style="color: black;">, <span style="color: green;">//calling Web API controller </span></span></span></span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">cache: <span style="color: blue;">false<span style="color: black;">, </span></span></span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">crossDomain: <span style="color: blue;">true<span style="color: black;">, </span></span></span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">type: <span style="color: #a31515;">&#8216;POST&#8217;<span style="color: black;">, </span></span></span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">contentType: <span style="color: #a31515;">&#8216;application/json; charset=utf-8&#8217;<span style="color: black;">, </span></span></span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">data: DTO, </span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">dataType: <span style="color: #a31515;">&#8220;json&#8221;<span style="color: black;">, </span></span></span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt;"><span style="background-color: white;">success: <span style="color: blue;">function<span style="color: black;"> (payload) {</span></span></span>…} </span></p>
<p><span style="color: black; font-family: Consolas; font-size: 9pt; background-color: white;">.fail(function (xhr, textStatus, err) {..} </span></p>
<p>Now, this is where you might have some fun. As it turned out, Chrome would execute the call successfully right off the bat. On the other hand, IE 10 barked with Access Denied. This predicament and the ensuing research threw me in a wrong direction and let me to believe that IE doesn&#8217;t support CORS and I had to use a script, such as <a href="https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest">jQuery.XDomainRequest.js</a>, as a workaround. As a result, the call would now go out to the server but the server would return &#8220;415 Unsupported Media Type&#8221;. Many more hours lost in research…(Fiddler does wonders here). The reason was that the script delegates the call to the XDomainRequest object which doesn&#8217;t support custom request headers. Consequently, the POST request won&#8217;t include the Content-Type: &#8216;application/json&#8217; header and the server drops the call because it can&#8217;t find a formatter to deserialize the payload.</p>
<p>As it turns out, you don&#8217;t need scripts. The reason why IE drops the call with Access Denied is because its default security settings disallow cross-domain calls. To change this:</p>
<ol>
<li>Add the service URL to the Trusted Sites in IE. This is not needed but it&#8217;s a good idea anyway.</li>
<li>Open IE Internet Options and select the Security tab. Then, select Trusted Sites and click the Custom Level button.</li>
<li>
<div>In the Security Settings dialog box, scroll down to the Miscellaneous section and set &#8220;Access data sources across domains&#8221;. Restart your computer.</div>
</li>
</ol>
<p><img fetchpriority="high" decoding="async" class="alignnone wp-image-2011 size-full" src="/wp-content/uploads/2013/09/091013_0229_WebAPICORSA1.png" alt="091013_0229_WebAPICORSA1" width="303" height="345" srcset="https://prologika.com/wp-content/uploads/2013/09/091013_0229_WebAPICORSA1.png 303w, https://prologika.com/wp-content/uploads/2013/09/091013_0229_WebAPICORSA1-263x300.png 263w" sizes="(max-width: 303px) 100vw, 303px" /></p>
<p style="margin-left: 18pt;">Apparently, Microsoft learned their lesson from all the security exploits and decided to shut the cross-domain door. IMO, a better option that would have prevented many hours of debugging and tracing would have been to detect that Javascript attempts CORS (<span style="color: black; font-family: Consolas; font-size: 9pt;"><span style="background-color: white;">jQuery.support.cors</span>=true</span>) and explain the steps to change the default settings or, better yet, implement CORS <a href="http://www.w3.org/TR/cors/" target="_blank" rel="noopener noreferrer">preflight</a> as the other browsers do (Chrome submits OPTIONS to ask the server if the operation is allowed before the actual POST).</p>
<p style="margin-left: 18pt;"><strong>UPDATE 9/10/2013</strong><br />
When using the web server built in Visual Studio and you debug/test the browser opens the page with localhost:portnumber. However, the browser (I tested this with IE and Chrome) does not consider the port to be a part of the Security Identifier (origin) used for Same Origin Policy enforcement and the call will fail.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://prologika.com/web-api-cors-adventures/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Chasing Parameters</title>
		<link>https://prologika.com/chasing-parameters/</link>
					<comments>https://prologika.com/chasing-parameters/#respond</comments>
		
		<dc:creator><![CDATA[Prologika - Teo Lachev]]></dc:creator>
		<pubDate>Wed, 17 Mar 2010 01:47:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[NET]]></category>
		<category><![CDATA[Reporting Services]]></category>
		<guid isPermaLink="false">/CS/blogs/blog/archive/2010/03/16/chasing-parameters.aspx</guid>

					<description><![CDATA[Scenario: You use the Visual Studio ASP.NET ReportViewer and you can&#8217;t figure out how to get the parameter values when the page posts back. I couldn&#8217;t find a straightforward answer [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>Scenario</strong>: You use the Visual Studio ASP.NET ReportViewer and you can&#8217;t figure out how to get the parameter values when the page posts back. I couldn&#8217;t find a straightforward answer on the discussion list so I thought my findings could come useful.</p>
<p><strong>Solution</strong>: Depending on your scenario, you can choose one the following three approaches:</p>
<p>1. You can get the current parameter values <strong>after</strong> the ReportViewer.PreRender method completes. Use another event that fires after PreRender. Based on my testing, the only events I found out to work are ReportViewer.Unload or Page.Unload, e.g.:</p>
<p><span style="font-family: Courier New; font-size: 10pt;"><span style="color: blue;">protected</span> <span style="color: blue;">void</span> reportViewer_Unload(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e) </span><span style="font-family: Courier New; font-size: 10pt;">{ </span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">    ReportViewer.<span style="color: #2b91af;">ReportParameterInfoCollection</span> parameters = reportViewer.ServerReport.GetParameters(); </span></p>
<p><span style="font-family: Courier New; font-size: 10pt;">} </span></p>
<p>2. Subclass the control and override OnPreRender, calling the base method and then obtaining the parameter values.</p>
<p>3. If you are using Visual Studio 2010, the new ReportViewer exposes a new <a href="http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.reportviewer.submittingparametervalues(VS.100).aspx">SubmittingParameterValues event</a> for this purpose.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://prologika.com/chasing-parameters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Trying to Communicate</title>
		<link>https://prologika.com/trying-to-communicate/</link>
					<comments>https://prologika.com/trying-to-communicate/#respond</comments>
		
		<dc:creator><![CDATA[Prologika - Teo Lachev]]></dc:creator>
		<pubDate>Sun, 23 Dec 2007 03:07:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[NET]]></category>
		<category><![CDATA[Reporting Services]]></category>
		<guid isPermaLink="false">/CS/blogs/blog/archive/2007/12/22/trying-to-communicate.aspx</guid>

					<description><![CDATA[Visual Studio 2008 embraces the exciting new world of Windows Communication Foundation (WCF) for communicating with services. However, pitfalls await the unwary. I&#8217;ve recently tackled invoking the Reporting Services Web [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Visual Studio 2008 embraces the exciting new world of Windows Communication Foundation (WCF) for communicating with services. However, pitfalls await the unwary. I&#8217;ve recently tackled invoking the Reporting Services Web service with WCF and I want to share my findings.</p>
<ol>
<li>The Visual Studio Add Web Reference menu has been renamed to Add Service Reference to denote that WCF can communicate with much more than Web services, including probably my Zune device. Although the dialog has somewhat changed, you will be find your way to generate the proxy.</li>
<li>What&#8217;s more surprising is that the auto-generated proxy methods now have somewhat different signatures.</li>
</ol>
<p>For example, the SQL Server Books Online has the following signature of the Reporting Services GetExecution Options API.</p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">public ExecutionSettingEnum GetExecutionOptions (string Report,out ScheduleDefinitionOrReference Item);</span> </span></p>
<p style="margin-left: 18pt;">Yet, WCF generates the following signature:</p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">public ServerInfoHeader GetExecutionOptions(string Report, out ExecutionSettingEnum executionOption, out ScheduleDefinitionOrReference Item); </span></span></p>
<p style="margin-left: 18pt;">So, the returned value becomes an out parameter while ServerInfoHeader becomes a returned value. I am not sure how WCF figures this out. Does it mean that now the documentation should show both the 2.0 and WCF signatures?</p>
<ol>
<li>The second surprise wave hit me when I was trying to figure out a way to pass my credentials to the Web service. This, of course, will probably be one of the first things you need to do to invoke an Intranet service.</li>
</ol>
<p>In the good ol&#8217; 2.0 days, impersonating the user takes a single line of code.</p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">rs.Credentials = System.Net.CredentialCache.DefaultCredentials;</span> </span></p>
<p style="margin-left: 18pt;">How do we this in the shiny new WCF world? Strangely, the Visual Studio help says little about this. I came across some bizarre examples of declaring HTTP transports that made my head spin. In a sheer stroke of luck, I managed to figure out the right changes in the application config file (yes, now we have declarative settings).</p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; color: black; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">&lt;security mode=&#8221;<strong>TransportCredentialOnly</strong>&#8220;&gt; </span></span></p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; color: black; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">&lt;transport clientCredentialType=&#8221;<strong>Ntlm</strong>&#8221; proxyCredentialType=&#8221;None&#8221; realm=&#8221;&#8221; /&gt; </span></span></p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; color: black; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">&lt;message clientCredentialType=&#8221;UserName&#8221; algorithmSuite=&#8221;Default&#8221; /&gt; </span></span></p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; color: black; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">&lt;/security&gt;</span> </span></p>
<p style="margin-left: 18pt;">Wait! We need to tell WCF also that is OK to impersonate the user.</p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; color: black; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">ReportingService2005SoapClient rs = new ReportingService2005SoapClient(); </span></span></p>
<p style="margin-left: 18pt;"><span style="font-size: 7pt; color: black; font-family: Lucida Sans Typewriter;"><span style="font-size: xx-small;">rs.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; </span></span></p>
<p style="margin-left: 18pt;">At this point, I felt like upgrading my house only to find that I have to enter through the chimney. Upgrading to a new technology shouldn&#8217;t complicate things unnecessarily. I promptly switched back to the 2.0 style of programming. Luckily, they kept the old Add Web Reference button from the advanced settings of the Add Service Reference dialog.</p>
<p style="margin-left: 18pt;">I guess they were right. You can&#8217;t teach an old dog new tricks…</p>
<p style="margin-left: 18pt;">Happy holidays!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://prologika.com/trying-to-communicate/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Introducing LINQ</title>
		<link>https://prologika.com/introducing-linq/</link>
					<comments>https://prologika.com/introducing-linq/#respond</comments>
		
		<dc:creator><![CDATA[Prologika - Teo Lachev]]></dc:creator>
		<pubDate>Fri, 27 Apr 2007 12:05:20 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[NET]]></category>
		<guid isPermaLink="false">/CS/blogs/blog/archive/2007/04/27/introducing-linq.aspx</guid>

					<description><![CDATA[If you follow the Microsoft .NET roadmap, you have probably heard about the forthcoming Language Integrated Query (LINQ) in .NET 3.0. LINQ will add query capabilities directly into the CLR [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>If you follow the Microsoft .NET roadmap, you have probably heard about the forthcoming Language Integrated Query (LINQ) in .NET 3.0. LINQ will add query capabilities directly into the CLR and will be supported by both VB.Net and C#. This means that you will be able to use standard query operators directly from within your code!
</p>
<p>To help you get started with LINQ, Marco Russo and Paolo Pialorsi wrote a book<br />
		<em>Introducing Microsoft LINQ</em> published by Microsoft Press. The book is expected to be published in mid-May. Meanwhile, the authors have set up a public forum (http://introducinglinq.com/) and they are eagerly awaiting your LINQ-related questions.
</p>
<p>Oh, yes, I&#8217;ve made a tiny contribution to the book by reviewing a few chapters. I found the book to be a great introduction to LINQ. I particularly liked the code examples. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://prologika.com/introducing-linq/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Transcend T-SQL Limitations with SQL Server 2005 CLR Objects</title>
		<link>https://prologika.com/transcend-t-sql-shackles-with-sql-server-2005-clr-objects/</link>
					<comments>https://prologika.com/transcend-t-sql-shackles-with-sql-server-2005-clr-objects/#respond</comments>
		
		<dc:creator><![CDATA[Prologika - Teo Lachev]]></dc:creator>
		<pubDate>Sun, 01 Oct 2006 19:44:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[NET]]></category>
		<guid isPermaLink="false">/CS/blogs/blog/archive/2006/10/01/Transcend-T_2D00_SQL-Shackles-with-SQL-Server-2005-CLR-Objects.aspx</guid>

					<description><![CDATA[One of the coolest SQL Server 2005 feature is .NET CLR objects. When use wisely, CLR integration can solve many nagging problems with T-SQL. For example, you cannot pass columns [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>One of the coolest SQL Server 2005 feature is .NET CLR objects. When use wisely, CLR integration can solve many nagging problems with T-SQL. For example, you cannot pass columns from an outer SQL statement to a TBF even though it returns one row. Or, for some obscure reason, you cannot use dynamic execution (EXEC statement) inside a scalar &ndash;valued function. Yet, you may need to use the same scalar-valued function with an arbitrary column. </p>
<p>In comparison, the sky is the limit about what a CLR stored procedure or a CLR UDF can do. Here is an extract from a real-life CLR UDF written in C# that returns the YTD aggregated value for a given measure: </p>
<p><span style="font-size: 8pt; font-family: Courier New">[Microsoft.SqlServer.Server.<span style="color: teal">SqlFunction</span>(DataAccess = <span style="color: teal">DataAccessKind</span>.Read, SystemDataAccess = <span style="color: teal">SystemDataAccessKind</span>.Read)] </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: blue">public</span> <span style="color: blue">static</span> <span style="color: teal">SqlDecimal</span> YTD(<span style="color: blue">int</span> companyID, <span style="color: teal">DateTime</span> financialPeriod, <span style="color: blue">string</span> measure) </span><span style="font-size: 8pt; font-family: Courier New">{ </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: blue">&nbsp; using</span> (<span style="color: teal">SqlConnection</span> conn = <span style="color: blue">new</span> <span style="color: teal">SqlConnection</span>(<span style="color: maroon">&quot;context connection=true&quot;</span>)) </span><span style="font-size: 8pt; font-family: Courier New">{ </span></p>
<p><span style="font-size: 8pt; font-family: Courier New">&nbsp;&nbsp;&nbsp;&nbsp; conn.Open(); </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: teal">&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand</span> cmd = <span style="color: blue">new</span> <span style="color: teal">SqlCommand</span>(<span style="color: teal">String</span>.Format(<span style="color: maroon">&quot;SELECT SUM({0}) &quot;</span> + </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: maroon">&nbsp;&nbsp;&nbsp;&nbsp; &quot;FROM&nbsp;&nbsp;&nbsp;&nbsp;&lt;some table here&gt; (NOLOCK) &quot;</span> + </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: maroon">&nbsp;&nbsp;&nbsp;&nbsp; &quot;INNER JOIN &lt;some other table&gt; (NOLOCK) &quot;</span> + <span style="color: maroon">&quot;&hellip; &quot;</span> + </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: maroon">&nbsp;&nbsp;&nbsp;&nbsp; &quot;WHERE FinancialPeriod = @FinancialPeriod&quot; &quot;</span>, measure), conn); </span></p>
<p><span style="font-size: 8pt; font-family: Courier New">&nbsp;&nbsp;&nbsp;&nbsp; cmd.Parameters.Add(<span style="color: blue">new</span> <span style="color: teal">SqlParameter</span>(<span style="color: maroon">&quot;@CompanyID&quot;</span>, companyID)); </span></p>
<p><span style="font-size: 8pt; font-family: Courier New">&nbsp;&nbsp;&nbsp;&nbsp; cmd.Parameters.Add(<span style="color: blue">new</span> <span style="color: teal">SqlParameter</span>(<span style="color: maroon">&quot;@FinancialPeriod&quot;</span>, financialPeriod)); </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: blue">&nbsp;&nbsp;&nbsp;&nbsp; return</span> ToSqlDecimal(cmd.ExecuteScalar()); </span><span style="font-size: 8pt; font-family: Courier New">} </span></p>
<p><span style="font-size: 8pt; font-family: Courier New">} </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: teal">SqlDecimal</span> ToSqlDecimal(<span style="color: blue">object</span> value) </span><span style="font-size: 8pt; font-family: Courier New">{ </span></p>
<p><span style="font-size: 8pt; font-family: Courier New"><span style="color: blue">&nbsp;&nbsp; return</span> value <span style="color: blue">is</span> System.<span style="color: teal">DBNull</span> ? <span style="color: teal">SqlDecimal</span>.Null : <span style="color: teal">SqlDecimal</span>.Parse(value.ToString()); </span></p>
<p><span style="font-size: 8pt; font-family: Courier New">} </span></p>
<p>Here, the function takes a company identifier, financial period, and the name of the measure to be aggregated as input arguments. The ADO.NET SqlCommand object takes care of executing the query (a boiler-plate ADO.NET code). Note the <span style="font-size: 8pt; font-family: Courier New">SystemDataAccess = <span style="color: teal">SystemDataAccessKind</span>.Read</span> attribute that decorates the function. If you omit it, you will be greated with the following exception at runtime: </p>
<p><span style="font-size: 9pt; color: red; font-family: Courier New">This statement has attempted to access data whose access is restricted by the assembly. </span></p>
<p>Once deployed, the function can be called as a regular T-SQL UDF, e.g. </p>
<p><span style="font-size: 8pt; font-family: Courier New">SELECT &lt;FULLY QUALIFIED CLASS NAME&gt;.YTD(1, &#39;7/1/2006&#39;, &quot;Sales&quot;), </span></p>
<p>assuming you have a Sales decimal column in your table or view. </p>
<p>Who knows, perhaps one day, we will be able to ditch T-SQL whatsoever in favor of .NET languages. I know I will be the first one to jump. </p>
]]></content:encoded>
					
					<wfw:commentRss>https://prologika.com/transcend-t-sql-shackles-with-sql-server-2005-clr-objects/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>You’ve been Deadlocked</title>
		<link>https://prologika.com/youve-been-deadlocked/</link>
					<comments>https://prologika.com/youve-been-deadlocked/#respond</comments>
		
		<dc:creator><![CDATA[Prologika - Teo Lachev]]></dc:creator>
		<pubDate>Sat, 24 Jun 2006 01:04:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[NET]]></category>
		<guid isPermaLink="false">/CS/blogs/blog/archive/2006/06/24/1322.aspx</guid>

					<description><![CDATA[If you’ve been using VS.NET 2005 for a while chances are that your debugging session could have been spectacularly crashing just when you thought you were so close finding that [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><P>If you’ve been using VS.NET 2005 for a while chances are that your debugging session could have been spectacularly crashing just when you thought you were so close finding that elusive critical bug. This situation may have manifested with the following exception:</P><br />
<P><STRONG>ContextSwitchDeadlock was detected<BR></STRONG><FONT face="Courier New" size=2>Message: The CLR has been unable to transition from COM context &lt;some nasty hex number&gt; to COM context &lt;another nasty hex number&gt; for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.</FONT></P><br />
<P>Usually, you can’t recover from this exception and the only way to be able to debug again is to restart the debugger (that is until it crashes again). The bad news is that this is a bug with the ContextSwitchDeadlock managed debugging assistant which the VS.NET team couldn’t fix in time. The good news is that you can prevent this MDA from raising his ugly head by ever again by just going to the Exceptions dialog (doesn’t appear by default in the Debug menu but you could add it by customizing the Debug menu) and disable the <STRONG>ContextSwitchDeadlock</STRONG> MDA found under the Managed Debugging Assistants category.</P></p>
]]></content:encoded>
					
					<wfw:commentRss>https://prologika.com/youve-been-deadlocked/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>When the Host is not so Perfect</title>
		<link>https://prologika.com/when-the-host-is-not-so-perfect/</link>
					<comments>https://prologika.com/when-the-host-is-not-so-perfect/#respond</comments>
		
		<dc:creator><![CDATA[Prologika - Teo Lachev]]></dc:creator>
		<pubDate>Fri, 09 Jun 2006 02:02:00 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[NET]]></category>
		<guid isPermaLink="false">/CS/blogs/blog/archive/2006/06/09/1272.aspx</guid>

					<description><![CDATA[Here is something that has recently bit me really bad. Customer requirements called for implementing an in-house report designer to create report definitions. Expired by the VS.NET 2005 Report Designer, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><P>Here is something that has recently bit me really bad. Customer requirements called for implementing an in-house report designer to create report definitions. Expired by the VS.NET 2005 Report Designer, we decided to implement a part of the tool as a WYSWYG designer using the design-time infrastructure (IDesignerHost) in .NET 2.0. If you don’t know what I am talking about, read the excellent Dinesh Chandnani&#8217;s Perfect Host <A href="http://msdn.microsoft.com/msdnmag/issues/06/03/DesignerHosting/">article</A> to learn more about the .NET designer host support. </P><br />
<P>To spice up the user experience, we decided to use the Infragistics Windows Forms suite. At runtime, the end user could drag Infragistics UltraTextBox and UltraImage controls and drop them on the design canvas. Everything was working just fine during development (aka my machine). However, once the application was deployed to QA, the WYSWYG designer failed abysmally. After some digging, we realized that the Infragistics controls was performing the same license check as they do when dropped on a Windows Form in VS.NET 2005. Since the Infragistics controls fail to find a design-time license, they throw an exception once the user attempts to site the control and there wasn’t any workaround. We had no other choice but to yank out the Infragistics controls and replace them with the plain-vanilla Windows controls &#8211; TextBox and PictureBox. </P><br />
<P>The moral of this story is to avoid using third-party controls when implementing .NET custom designers to prevent licensing gotchas. </P></p>
]]></content:encoded>
					
					<wfw:commentRss>https://prologika.com/when-the-host-is-not-so-perfect/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
