<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by Optimizely Forms Custom MSSQL Storage</title> <link>https://world.optimizely.com/blogs/optimizely-forms-custom-mssql-storage/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>Optimizely Forms Custom Submission Storage System (MSSQL)</title>            <link>https://world.optimizely.com/blogs/optimizely-forms-custom-mssql-storage/dates/2022/1/optimizely-forms-custom-submission-storage-system-mssql/</link>            <description>&lt;p&gt;Optimizely Forms uses DDS as its default storage mechanism. Which may cause performance-related issues in special cases. To solve this performance-related issue we can create an alternate data storage mechanism using MSSQL data storage system. We can use any data storage system and also there is an article on how to use MongoDb as alternate storage mechanism, but sometimes we dont need an additional database for storage and want to use the existing one, In that case we can use MSSQL data storage system.&lt;br /&gt;&lt;br /&gt;MSSQL data storage system will be a lot faster than default storage mechanism (DDS). The data that we need to store in tables is of such a type that NoSQL data storage system is best suited for it, but in some circumstances many developers are bound to use Microsoft SQL Server (MSSQL) for some reasons such as saving cost of having an additional database.&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size:&amp;#32;18pt;&quot;&gt;Here are step by step guide for how to use MSSQL as alternate data storage system for storing Optimizely Forms submission data:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style=&quot;font-size:&amp;#32;14pt;&quot;&gt;Step 1:&lt;/span&gt;&lt;/strong&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Add NuGet package :-&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;EPiServer.Forms.Core&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style=&quot;font-size:&amp;#32;14pt;&quot;&gt;&lt;strong&gt;Step 2:&lt;/strong&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Create a class which implements or say inherits&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;PermanentStorage&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;class, add&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;ServiceConfiguration&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;attribute on class. I have chosen the name &lt;code&gt;MsSqlPermanentStorage&lt;/code&gt;&lt;span&gt; of class, you can choose any name. You can find the code file here &lt;a href=&quot;https://github.com/sandeep1102/Optimizely-forms-custom-submission-storage/blob/main/MsSqlPermanentStorage.cs&quot;&gt;MsSqlPermanentStorage.cs&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-size:&amp;#32;14pt;&quot;&gt;&lt;strong&gt;Step 3:&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style=&quot;font-size:&amp;#32;12pt;&quot;&gt;Override the five functions below.&lt;/span&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;classLib&quot;&gt;SaveToStorage(FormIdentity formIden, Submission submission)&lt;/span&gt;&lt;/strong&gt;. This function saves data at the first step of a form. This may also be the last step, if a form only has one step. Using this method, based on these two parameters, you can save data into database::
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;classLib&quot;&gt;formIden&lt;/span&gt;. Contains form information, such as form id or language.&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;classLib&quot;&gt;submission&lt;/span&gt;. Contains form submission data.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;classLib&quot;&gt;UpdateToStorage(Guid formSubmissionId, FormIdentity formIden, Submission submission)&lt;/span&gt;.&lt;/strong&gt; This function is for saving data at the next steps or updating data at previous ones. Within this method, based on these two parameters, you can update data in the database.
&lt;ul&gt;
&lt;li&gt;&lt;span class=&quot;classLib&quot;&gt;submission&lt;/span&gt;. Contains form submission data.&lt;/li&gt;
&lt;li&gt;&lt;span class=&quot;classLib&quot;&gt;formIden&lt;/span&gt;. Contains form information, such as form id or language.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;classLib&quot;&gt;LoadSubmissionFromStorage(FormIdentity formIden, DateTime beginDate, DateTime endDate, bool finalizedOnly = false)&lt;/span&gt;.&lt;/strong&gt; This function loads form submission data from the database within a specific time period and the status finalized.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;classLib&quot;&gt;LoadSubmissionFromStorage(FormIdentity formIden, string[] submissionIds)&lt;/span&gt;.&lt;/strong&gt; Loads form submission data only based on the ids of the submission.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class=&quot;classLib&quot;&gt;Delete(FormIdentity formIden, string submissionId)&lt;/span&gt;.&lt;/strong&gt; Deletes a form submission based on submission Id.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Note: -&amp;nbsp;&lt;/strong&gt;&lt;code&gt;ADO.Net&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;is used for communication between C# and database. Which is faster than any ORM because at base every object relational mapper uses&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;ADO.Net&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span style=&quot;font-size:&amp;#32;14pt;&quot;&gt;&lt;strong&gt;Step 4:&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style=&quot;font-size:&amp;#32;12pt;&quot;&gt;&lt;strong&gt;Configuring new database provider:-&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now at last we need to add this custom storage provider in&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;Forms.config&lt;/code&gt;&amp;nbsp;and default provider is changed from&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;DdsPermanentStorage&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;to&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code&gt;MsSqlPermanentStorage&lt;/code&gt; or whatever name you have given to the provider, according to the example code I used name &lt;code&gt;MsSqlPermanentStorage&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;language-markup&quot;&gt;&lt;code&gt;&amp;lt;storage defaultProvider=&quot;MsSqlPermanentStorage&quot;&amp;gt;
            &amp;lt;providers&amp;gt;
	            &amp;lt;add name=&quot;MsSqlPermanentStorage&quot; type=&quot;CustomStorage.Web.React.MsSqlPermanentStorage, CustomStorage.Web.React&quot; /&amp;gt;
				&amp;lt;add name=&quot;DdsPermanentStorage&quot; type=&quot;EPiServer.Forms.Core.Data.DdsPermanentStorage, EPiServer.Forms.Core&quot; /&amp;gt;
              &lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You can find the code that need to be changed in &lt;a href=&quot;https://github.com/sandeep1102/Optimizely-forms-custom-submission-storage/tree/main&quot;&gt;Git Hub Repository.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Please comment if you need the whole sample project or have any issues implementing it.&lt;/p&gt;</description>            <guid>https://world.optimizely.com/blogs/optimizely-forms-custom-mssql-storage/dates/2022/1/optimizely-forms-custom-submission-storage-system-mssql/</guid>            <pubDate>Tue, 19 Jul 2022 06:09:12 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>