<?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>Andreano Lanusse &#124; Technology and Software Development &#187; Featured</title>
	<atom:link href="http://www.andreanolanusse.com/en/tag/featured/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.andreanolanusse.com/en</link>
	<description>Where Andreano Lanusse talk about technology, software development, programming techniques, databases, games and more through articles, tutorials and videos</description>
	<lastBuildDate>Sat, 04 Feb 2012 01:01:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Sharing DB connection between multiples DataSnap Server Modules</title>
		<link>http://www.andreanolanusse.com/en/sharing-db-connection-between-multiples-datasnap-server-modules/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sharing-db-connection-between-multiples-datasnap-server-modules</link>
		<comments>http://www.andreanolanusse.com/en/sharing-db-connection-between-multiples-datasnap-server-modules/#comments</comments>
		<pubDate>Fri, 10 Dec 2010 19:12:54 +0000</pubDate>
		<dc:creator>Andreano Lanusse</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[DataSnap]]></category>
		<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://www.andreanolanusse.com/en/?p=396</guid>
		<description><![CDATA[<p>When developers starts creating Delphi DataSnap application it is very common to see the database connection defined per Data Module. Doing this will generate a lot of connections on the database, and depending on the situation it will became a problem. In Delphi XE, DataSnap introduce the Session Management that will make easy to implement [...]</p><p><a href="http://www.andreanolanusse.com/en">Andreano Lanusse | Technology and Software Development</a><br/>
Follow me on Twitter: <a href="http://twitter.com/andreanolanusse.com">@andreanolanusse</a></p>]]></description>
			<content:encoded><![CDATA[<p>When developers starts creating Delphi DataSnap application it is very common to see the database connection defined per Data Module. Doing this will generate a lot of connections on the database, and depending on the situation it will became a problem.</p>
<p>In <a href="www.embarcadero.com/products/delphi" target="_blank">Delphi XE</a>, DataSnap introduce the Session Management that will make easy to implement the control on the server side to manage the database connection for the clients. The client application won&#8217;t know anything about that, the server will do the magic.</p>
<p>When we create a DataSnap Server it is best practice to define a Server Container (Data Module), which contains the DataSnap Server component and registers all the server classes required by the application. In this container we will define the method responsible for dealing with the database connections for each Server Class.</p>
<p><!-- p.p1 {margin: 0.0px 0.0px 14.0px 0.0px; line-height: 22.0px; font: 14.0px Arial; color: #444444} -->As an example, I have implemented a GetConnection method on the Server Container. This method is responsible for assigning the connection looking in to the connection pool, which will a have list of connections per client.</p>
<pre class="brush: delphi">  private
    { Private declarations }
    ListofConnection : TDictionary;
  public
    function GetConnection : TSQLConnection;</pre>
<p><!-- p.p1 {margin: 0.0px 0.0px 14.0px 0.0px; line-height: 22.0px; font: 14.0px Arial; color: #444444} -->In case the server receives new requests from new clients the GetConnection will create a new connection and add to the pool list. If the client already have a connection associated, the GetConnection will just return a instance of SQLConnection. The pool uses the Thread ID to control the unique connection per client. If you use DataSnap 2010 you have to use the method GetThreadSession for this purpose.</p>
<pre class="brush: delphi">function TServerContainer1.GetConnection: TSQLConnection;
var
  dbconn : TSQLConnection;
begin

  if ListofConnection.ContainsKey(TDSSessionManager.GetThreadSession.Id) then
     Result := ListofConnection[TDSSessionManager.GetThreadSession.Id]
  else
  begin
    dbconn := TSQLConnection.Create(nil);
    dbconn.Params.Clear;
    dbconn.LoadParamsOnConnect := true;
    dbconn.ConnectionName := 'DS Employee';

    ListofConnection.Add(TDSSessionManager.GetThreadSession.Id, dbconn);
    Result := dbconn;
  end;

end;</pre>
<p>Since the connection is defined we need to update all datasets to use this connection, as well the server methods that create and execute SQL queries at run-time will have to invoke the GetConnection.</p>
<p>If you are using the VCL Data components (TSQLQuery, TSQLStoredProc, etc…) on your Server DataModules, the onCreate event is a good place to associate the DataSets with the connection, using the following code.</p>
<pre class="brush: delphi">procedure TServerContainer1.SetConnection(Conn: TSqlConnection);
var
  i: integer;
begin
  if Conn = nil then
     Conn := GetConnection;
  else
    Conn := Sender;

  for i := 0 to ComponentCount - 1 do
    if Components[i] is TSQLQuery then
       TSQLQuery(Components[i]).SQLConnection := Conn;
end;</pre>
<p>To avoid connection leaks on the database, we implement the onDisconnect event from DSServer. This will be executed when the client disconnects.</p>
<pre class="brush: delphi">  if GetConnection &lt;&gt; nil then
     GetConnection.Close;</pre>
<p>The source code is available for download at <a href="http://cc.embarcadero.com/item/28097" target="_blank">Code Central</a>.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.andreanolanusse.com/en/android-apps-connected-to-delphi-datasnap-server/" title="Android apps connected to Delphi DataSnap Server">Android apps connected to Delphi DataSnap Server</a></li><li><a href="http://www.andreanolanusse.com/en/copyreadertoclientdataset-blob-and-the-message-feature-not-implemented/" title="CopyReaderToClientDataSet, Blob and the message &#8220;Feature not implemented&#8221;">CopyReaderToClientDataSet, Blob and the message &#8220;Feature not implemented&#8221;</a></li><li><a href="http://www.andreanolanusse.com/en/publishing-providers-when-registering-datasnap-server-class-in-runtime/" title="Publishing providers when registering DataSnap Server Class in runtime">Publishing providers when registering DataSnap Server Class in runtime</a></li><li><a href="http://www.andreanolanusse.com/en/caching-data-on-datasnap-server/" title="Caching data on DataSnap Server">Caching data on DataSnap Server</a></li><li><a href="http://www.andreanolanusse.com/en/copying-data-from-clientdataset-to-dbxreader/" title="Copying data from ClientDataSet to DBXReader">Copying data from ClientDataSet to DBXReader</a></li><li><a href="http://www.andreanolanusse.com/en/video-connecting-android-applications-with-datasnap-server-delphi-conference-brazil-2010/" title="Video: Connecting Android applications with DataSnap Server – Delphi Conference Brazil 2010">Video: Connecting Android applications with DataSnap Server – Delphi Conference Brazil 2010</a></li></ul><p><a href="http://www.andreanolanusse.com/en">Andreano Lanusse | Technology and Software Development</a><br/>
Follow me on Twitter: <a href="http://twitter.com/andreanolanusse.com">@andreanolanusse</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.andreanolanusse.com/en/sharing-db-connection-between-multiples-datasnap-server-modules/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>White Paper: Reasons to Migrate to Delphi XE – What you might have missed since Delphi 7</title>
		<link>http://www.andreanolanusse.com/en/white-paper-reasons-to-migrate-to-delphi-xe-what-you-might-have-missed-since-delphi-7/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=white-paper-reasons-to-migrate-to-delphi-xe-what-you-might-have-missed-since-delphi-7</link>
		<comments>http://www.andreanolanusse.com/en/white-paper-reasons-to-migrate-to-delphi-xe-what-you-might-have-missed-since-delphi-7/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 05:45:45 +0000</pubDate>
		<dc:creator>Andreano Lanusse</dc:creator>
				<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Featured]]></category>

		<guid isPermaLink="false">http://www.andreanolanusse.com/en/?p=401</guid>
		<description><![CDATA[<p>Delphi community, many of you have been looking for compelling reasons to migrate to Delphi XE, each developer in a old version of Delphi. This article gives a few good reasons to migrate, along with an overview of the most important features added to Delphi product releases since version 7. If you already read my [...]</p><p><a href="http://www.andreanolanusse.com/en">Andreano Lanusse | Technology and Software Development</a><br/>
Follow me on Twitter: <a href="http://twitter.com/andreanolanusse.com">@andreanolanusse</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://cc.embarcadero.com/download.aspx?id=28119"><img class="alignleft size-medium wp-image-405" style="margin: 4px;" title="Download the White Paper: Reasons to Migrate to Delphi XE" src="http://www.andreanolanusse.com/en/wp-content/uploads/2010/11/Reasons_to_Migrate_to_Delphi_XE_Cover-232x300.png" alt="" width="232" height="300" /></a>Delphi community, many of you have been looking for compelling reasons to migrate to Delphi XE, each developer in a old version of Delphi.</p>
<p>This article gives a few good reasons to migrate, along with an overview of the most important features added to Delphi product releases since version 7. If you already read my article &#8220;Reasons to migrate from Delphi 7 to Delphi 2009&#8243;, this article include updates related with Delphi 2010 and XE.</p>
<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica} -->We understand that developers are busy creating software, and that spending time to migrate to a new version is not always possible since you always have to deliver new projects.</p>
<p>Possibly the best reason for you to migrate to Delphi XE, C++Builder XE or RAD Studio XE, is that buying those versions <a href="www.embarcadero.com/get-legal">gets you earlier versions</a> at no extra cost. For example buying Delphi XE also gets you Delphi 7, Delphi 2007, Delphi 2009 and Delphi 2010.</p>
<p>I hope this article answer all of your question, any additional question let us know how.</p>
<p>Article <a href="http://cc.embarcadero.com/download.aspx?id=28119" target="_blank"><strong>download</strong></a>.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.andreanolanusse.com/en/sharing-db-connection-between-multiples-datasnap-server-modules/" title="Sharing DB connection between multiples DataSnap Server Modules">Sharing DB connection between multiples DataSnap Server Modules</a></li><li><a href="http://www.andreanolanusse.com/en/firemonkey-3d-text-editor/" title="FireMonkey 3D Text Editor">FireMonkey 3D Text Editor</a></li><li><a href="http://www.andreanolanusse.com/en/android-apps-connected-to-delphi-datasnap-server/" title="Android apps connected to Delphi DataSnap Server">Android apps connected to Delphi DataSnap Server</a></li><li><a href="http://www.andreanolanusse.com/en/its-time-to-move-on/" title="It&#8217;s time to move on">It&#8217;s time to move on</a></li><li><a href="http://www.andreanolanusse.com/en/700-delphi-developers-at-delphi-conference-brazil/" title="700 Delphi Developers at Delphi Conference Brazil">700 Delphi Developers at Delphi Conference Brazil</a></li><li><a href="http://www.andreanolanusse.com/en/white-paper-reasons-to-migrate-to-delphi-xe2-what-you-might-have-missed-since-delphi-7/" title="White Paper: Reasons to Migrate to Delphi XE2 | What you might have missed since Delphi 7">White Paper: Reasons to Migrate to Delphi XE2 | What you might have missed since Delphi 7</a></li></ul><p><a href="http://www.andreanolanusse.com/en">Andreano Lanusse | Technology and Software Development</a><br/>
Follow me on Twitter: <a href="http://twitter.com/andreanolanusse.com">@andreanolanusse</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.andreanolanusse.com/en/white-paper-reasons-to-migrate-to-delphi-xe-what-you-might-have-missed-since-delphi-7/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>“Linq to Directories/Files” – Enumerating Directories and Files with Delphi Prism and .NET 4</title>
		<link>http://www.andreanolanusse.com/en/linq-to-directoriesfiles-enumerating-directories-and-files-with-delphi-prism-2011-and-net-4/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linq-to-directoriesfiles-enumerating-directories-and-files-with-delphi-prism-2011-and-net-4</link>
		<comments>http://www.andreanolanusse.com/en/linq-to-directoriesfiles-enumerating-directories-and-files-with-delphi-prism-2011-and-net-4/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 13:54:59 +0000</pubDate>
		<dc:creator>Andreano Lanusse</dc:creator>
				<category><![CDATA[Delphi Prism (.NET)]]></category>
		<category><![CDATA[Delphi Prism]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://www.andreanolanusse.com/en/?p=307</guid>
		<description><![CDATA[<p>.NET 4 allow you to enumerate directories and files by using methods that return an enumerable collection of strings of their names, also you can use methods that return an enumerable collection of DirectoryInfo, FileInfo, or FileSystemInfo objects, these objects are very powerfull and make easy the development. Before .NET 4 you could only obtain [...]</p><p><a href="http://www.andreanolanusse.com/en">Andreano Lanusse | Technology and Software Development</a><br/>
Follow me on Twitter: <a href="http://twitter.com/andreanolanusse.com">@andreanolanusse</a></p>]]></description>
			<content:encoded><![CDATA[<p>.NET 4 allow you to enumerate directories and files by using methods that return an enumerable collection of strings of their names, also you can use methods that return an enumerable collection  of DirectoryInfo, FileInfo, or FileSystemInfo objects, these objects are very powerfull and make easy the development. Before .NET 4 you could only obtain arrays of these collections. Enumerable collections provide better performance than arrays.</p>
<p>Delphi Prism XE provide full support for .NET 4. the follow examples shows how to enumerate Directories and Files.</p>
<p><strong>Enumareting directory names &#8211; this samples list all directories under &#8220;c:\Program Files\&#8221;</strong></p>
<pre class="brush: delphi">class method ConsoleApp.Main(args: array of System.String);
begin
  try
    var dirPath: System.String := 'c:\Program Files';

    // LINQ query.
    var dirs :=  from dir in Directory.EnumerateDirectories(dirPath) select dir;

    // Show results.
    for each dir in dirs do begin
      // Remove path information from string.
      Console.WriteLine('{0}', dir.Substring(dir.LastIndexOf('\') + 1))
    end;
    Console.WriteLine('{0} directories found.', dirs.Count().ToString());

    // Optionally create a List collection.
    var workDirs: List := new List(dirs)
  except
    on UAEx: UnauthorizedAccessException do begin
      Console.WriteLine(UAEx.Message)
    end;
    on PathEx: PathTooLongException do begin
      Console.WriteLine(PathEx.Message)
    end;
  end;
  Console.ReadKey;

end;</pre>
<p><strong>Enumerating file names in all directories &#8211; this sample search all TXT files which contains the word &#8220;license&#8221;</strong></p>
<pre class="brush: delphi">class method ConsoleApp.Main(args: array of System.String);
begin

  try

    var files :=  from sfile in Directory.EnumerateFiles('c:\', '*.txt', SearchOption.AllDirectories)
                  from line in File.ReadLines(sfile)
                  where line.Contains('license')
                  select new class( File := sfile, Line := line);

    for each f in files do begin
      Console.WriteLine('{0}'#9'{1}', f.File, f.Line)
    end;

    Console.WriteLine('{0} files found.', files.Count().ToString());
  except
    on UAEx: UnauthorizedAccessException do begin
      Console.WriteLine(UAEx.Message);
    end;
    on PathEx: PathTooLongException do begin
      Console.WriteLine(PathEx.Message);
    end;
  end;

  Console.ReadKey;

end;</pre>
<p><strong>Enumerating a collection of DirectoryInfo objects &#8211; this sample list all directories created before April of 2010</strong></p>
<pre class="brush: delphi">class method ConsoleApp.Main(args: array of string);
begin

  var dirPrograms: DirectoryInfo := new DirectoryInfo('c:\program files');
  var StartOf2010: DateTime := new DateTime(2010, 4, 1);

  // LINQ query for all directories created before April of 2010.
  var dirs :=  from dir in dirPrograms.EnumerateDirectories()
               where dir.CreationTimeUtc &lt; StartOf2010
               select new class (ProgDir := dir);
  // Show results.
  for each di in dirs do begin
    Console.WriteLine('{0}', di.ProgDir.Name)
  end;

  Console.ReadKey;
end;</pre>
<p>You can download the Delphi Prism 2011 Trial <a href="http://www.embarcadero.com/products/delphi-prism" target="_blank"><strong>here</strong></a>.</p>
<h2  class="related_post_title">Related Posts</h2><ul class="related_post"><li><a href="http://www.andreanolanusse.com/en/using-linq-to-objetcs-in-delphi-prism/" title="Using LINQ to Objetcs in Delphi Prism">Using LINQ to Objetcs in Delphi Prism</a></li><li><a href="http://www.andreanolanusse.com/en/trial-datasheet-feature-matrix-and-faq-for-xe2-release-available/" title="Trial, Datasheet, Feature Matrix and FAQ for XE2 release available">Trial, Datasheet, Feature Matrix and FAQ for XE2 release available</a></li><li><a href="http://www.andreanolanusse.com/en/rad-studio-xe2-a-new-era-for-delphi-and-cbuilder-developers/" title="RAD Studio XE2 a new era for Delphi and C++Builder Developers">RAD Studio XE2 a new era for Delphi and C++Builder Developers</a></li><li><a href="http://www.andreanolanusse.com/en/using-ios-mapkit-and-corelocation-with-delphi-prism-and-monotouch/" title="Using iOS MapKit and CoreLocation with Delphi Prism and MonoTouch">Using iOS MapKit and CoreLocation with Delphi Prism and MonoTouch</a></li><li><a href="http://www.andreanolanusse.com/en/sharing-db-connection-between-multiples-datasnap-server-modules/" title="Sharing DB connection between multiples DataSnap Server Modules">Sharing DB connection between multiples DataSnap Server Modules</a></li><li><a href="http://www.andreanolanusse.com/en/video-building-net-based-applications-for-linux-and-iphone-with-mono-and-monotouch/" title="Video: Building .NET based applications for Linux and iPhone with Mono and Monotouch">Video: Building .NET based applications for Linux and iPhone with Mono and Monotouch</a></li></ul><p><a href="http://www.andreanolanusse.com/en">Andreano Lanusse | Technology and Software Development</a><br/>
Follow me on Twitter: <a href="http://twitter.com/andreanolanusse.com">@andreanolanusse</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.andreanolanusse.com/en/linq-to-directoriesfiles-enumerating-directories-and-files-with-delphi-prism-2011-and-net-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

