<?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>Luigi Melisi &#187; HttpListener</title>
	<atom:link href="http://www.luigimelisi.com/tag/httplistener/feed" rel="self" type="application/rss+xml" />
	<link>http://www.luigimelisi.com</link>
	<description>Development Blog : C# Code Samples,.NET Tips and Tricks</description>
	<lastBuildDate>Thu, 03 Mar 2011 09:01:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Cache con dipendenza da SQL Server 2005 e ASP.NET 2.0</title>
		<link>http://www.luigimelisi.com/programmazione/net_framework/visual-c/cache-con-dipendenza-da-sql-server-2005-e-asp-net-2-0.html?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cache-con-dipendenza-da-sql-server-2005-e-asp-net-2-0</link>
		<comments>http://www.luigimelisi.com/programmazione/net_framework/visual-c/cache-con-dipendenza-da-sql-server-2005-e-asp-net-2-0.html#comments</comments>
		<pubDate>Wed, 26 Aug 2009 18:25:05 +0000</pubDate>
		<dc:creator>Luigi Melisi</dc:creator>
				<category><![CDATA[.Net Framework]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Visual C#]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Cache]]></category>
		<category><![CDATA[Code Samples]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[HttpListener]]></category>
		<category><![CDATA[Luigi Melisi]]></category>
		<category><![CDATA[Service Broker]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SqlCacheDependency]]></category>
		<category><![CDATA[Utils]]></category>

		<guid isPermaLink="false">http://www.luigimelisi.com/?p=140</guid>
		<description><![CDATA[SQL Server 2005 offre un supporto nativo alla dipendenza su database di oggetti salvati in Cache, una delle novità offerte dall&#8217;infrastruttura di cache di ASP.NET 2.0.
Questa possibilità consente di sfruttare gli HttpListener di ASP.NET, così che sia SQL Server ad inviare le notifiche sui cambi nei  [...]]]></description>
			<content:encoded><![CDATA[<p><strong>SQL Server 2005</strong> offre un supporto nativo alla dipendenza su database di oggetti salvati in Cache, una delle novità offerte dall&#8217;infrastruttura di <strong>cache</strong> di <strong>ASP.NET 2.0.<span id="more-140"></span></strong></p>
<p>Questa possibilità consente di sfruttare gli <strong>HttpListener di ASP.NET</strong>, così che sia <strong>SQL Server</strong> ad inviare le <strong>notifiche sui cambi nei risultati della query</strong>, anzichè essere ASP.NET a farne una ad intervalli regolari per verificare che i dati siano cambiati.</p>
<p>Tra l&#8217;altro questo consente di limitare di molto la fase di configurazione della dipendenza, che si limita ad abilitare il supporto del <strong>Service Broker</strong> sul database e dare l&#8217;accesso all&#8217;utente, il tutto eseguendo questi comandi:</p>
<pre>ALTER DATABASE mioDatabase SET ENABLE_BROKER</pre>
<pre>GRANT SUBSCRIBE QUERY NOTIFICATIONS TO mioNome</pre>
<p>Per tenere in <strong>cache</strong> il risultato di una query fino a che la stessa non avrà modificato i propri dati è sufficiente <strong>associare il SqlCommand utilizzato ad una nuova istanza di tipo SqlCacheDependency</strong>, così che il risultato venga monitorato e l&#8217;oggetto in cache venga poi invalidato e rimosso in automatico.</p>
<p><strong>C#</strong></p>
<pre><span style="color: #3366ff;">using</span> (<span style="color: #339966;">SqlConnection</span> conn = new <span style="color: #339966;">SqlConnection</span>(miaStringaConnessione))</pre>
<pre>{</pre>
<pre><span style="color: #008000;">// query da eseguire</span></pre>
<pre>SqlCommand cmd = new SqlCommand("SELECT campo1, campo2 FROM miaTabella", conn);</pre>
<pre>SqlDataAdapter da = new SqlDataAdapter();</pre>
<pre>da.SelectCommand = command;</pre>
<pre>// definizione della dipendenza</pre>
<pre>SqlCacheDependecy dep = new SqlCacheDependency(cmd);</pre>
<pre>// caricamento dei dati</pre>
<pre>DataTable mioDataTable = new DataTable("nomeDataTable");</pre>
<pre>da.Fill(mioDataTable);</pre>
<pre>// aggiunta in cache</pre>
<pre>Cache.Insert("nome", nomeDataTable, dep);</pre>
<pre>}</pre>
<p><strong>Fino alla modifica della tabella</strong> mia Tabella , <strong>i dati risultati dalla query rimarranno nella cache e pertanto l&#8217;elemento non verrà rimosso.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.luigimelisi.com/programmazione/net_framework/visual-c/cache-con-dipendenza-da-sql-server-2005-e-asp-net-2-0.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

