Wednesday, June 26, 2019

Visual Studio 2017 and SQL Server 2017 Installation issues

If you have decided to migrate to Visual Studio 2017 or later editions, there are few thing that will ensure a smooth installation and a working environment without much hassle.

Installing  SQL Server 2017 before installation of Visual Studio 2017 will ensure that SQL Server 2017 is install without an error..

If you have installed Visual Studio 2017 first  then the SQL Server 2017 setup will be failed with exit code 1638.

To resolve this uninstall the Microsoft Visual C++ 2017 redistributable as shown here.

In addition you will receive following error when trying to open SSMS.

Cannot find one or more components. Please re install the application

This can be resolved by

1. Reinstall the VS 2015 Shell (using Visual Studio 2017 setup)
2. Try to reopen SSMS. It if still fails try reinstalling SSMS.

Cheers,
Samitha

Monday, June 10, 2019

Resolving Maximum request length exceeded error

You might encounter Maximum request length exceeded error when you try to upload large files or perform web requests that fetch large chunks of data.


This error commonly raised by IIS as the default upload file size or request size is only 4MB.
There are two settings in the web.config that determined the request length. The following settings will increase the request  up to 100 MB.
 
<configuration>
    <system.web>
        <httpRuntime maxRequestLength="102400" />
   </system.web>
</configuration>
 
&lt;system.webServer>
   &lt;security>
      <requestFiltering>
         <requestLimits maxAllowedContentLength="104857600" />
      </requestFiltering>
   </security>
</system.webServer> 
 
Please note that maxRequestLength is measured in Kilobytes 
and maxAllowedContentLength is measured in bytes.
 
 
Also note that this can be configured for the URL 
that performs the file upload/ request.
 
e.g.
 
<location path="Documents/Uploads">
<system.web>
    
   <httpRuntime maxRequestLength="102400" />
  </system.web>
  <system.webServer>
   <security>
     <requestFiltering>
       
        <requestLimits maxAllowedContentLength="104857600" /> 
      </requestFiltering>
    </security>
  </system.webServer>
</location> 

Cheers,
Samitha 
 

Wednesday, May 22, 2019

Visual Studio compilation issue "Attempted to access an unloaded AppDomain"

When trying to compile  the project you might encounter following error.

Attempted to access an unloaded AppDomain

Follow these steps to solve this issue.
  • Delete all the temporary files.
  • Restart Visual studio.
  • Clean your project solution.
  • Rebuild  and run the project .


Cheers
Samitha

Monday, May 6, 2019

Preventing multiple button clicks

There are scenarios when we need to disable a button to prevent multiple form submits. There can be many other ways, but following one tested and working for me.
Even though it is a kind of hack, it the easy way to achieve what needs to be happened

HTML

<asp:Button ID="btnSave" class="btn btn-sm" runat="server" Text="Save"  OnClientClick="DisableBtn(this);"  UseSubmitBehavior="false" />

JavaScript

<script type="text/javascript">

 function DisableBtn(btn) {
    btn.setAttribute('disabled', 'disabled');
   
    btn.click();

  }

</script >

Regards,
Samitha

Wednesday, May 1, 2019

jQuery working with paste

Following jQuery code can be used to catch the paste on an input and do some manupulation to the data pasted.

<script type="javascript">
   function pageLoad(){ //or you can use DOM Ready
 
       $('textarea').bind('paste', function () {
               var this= $(this);
                var orig = self.val();

                setTimeout(function () {//to chech the diffetence between pasted and original text
                   
                    if(this[0].value!==orig  ){
                        //more code
                    }
               });


});

  }
</script>

Cheers,
Samitha

Thursday, April 25, 2019

document ready not fired after post back

jQuery DOM ready tends to break if you are still working with update panels and the actual reason for that can caused by many things.

For me, it was calling DOM ready in Sys.Application.add_load(function); as displayed below.

 <script type="text/javascript">
         
Sys.Application.add_load(DomLoad);

function DomLoad() {
        $(function() {
                   //more code
        });
 }

 </script>

This also can be useful if you want to add multiple page loads scripts.

Read the following stack overflow post for more discussion on the same topic.

Cheers,
Samitha

Tuesday, April 16, 2019

TLS 1.2 suport in .Net 4.5 or above

Even thought Net 4.5 or above supports TLS 1.2, .Net default protocol is TLS 1.0. It is recommended to set the SecurityProtocol before any WebRequest calls.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

var url = "https://www.gmail.com";
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";

Setting SecurityProtocol before any WebRequest calls will make sure that response will not get following error when getting the response.

"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."