Wednesday, July 27, 2022

The JSON request was too large to be deserialized.

 <appSettings>

  <add key="aspnet:MaxJsonDeserializerMembers" value="150000" />

</appSettings>


Wednesday, June 29, 2022

iis service manager - the process cannot access the file because it is being used by another process

if you are doing publish in local or local server.. if you change your port number application will work.. published code run in  your server or local machine

Monday, June 6, 2022

An error occurred while trying to restore packages.

 %appdata%\NuGet\NuGet.Config

 <?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="Package source" value="E:\Download" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>

  

Thursday, April 7, 2022

unable to check out the current file. the file may be read only or locked

 Goto tools > Options > Source Control > Current source control  plug- in select None and try to add service Or project run in admin mode and add.. it will work

Tuesday, November 2, 2021

Foreach entity framework query

 employee.ForEach(em=>
                    {
                        em.sal= (em.sal !=null ?em.sal:0);
                    });

Friday, August 6, 2021

How to Count Total Number of HIT in Asp.net MVC?

 Applicatin_start()

 Application.Lock();  

Application["Totaluser"] = (int)Application["Totaluser"] + 1;        

Application.UnLock(); 

Friday, July 23, 2021

How to add zeros after decimal point

 var a= 10.1;

var result  = a.ToString("f2");

result = 10.10;

Monday, February 1, 2021

Cannot drop database "abc" because it is currently in use.

We will face the problem:

USE TEstDb;
DROP DATABASE TEstDb;

Solution:

 Use Master

DROP DATABASE TEstDb

Tuesday, September 8, 2020

Reading Excel From C# using OLEDB Connection

 First, You need to add below name spaces to read Excel file in OLEDB


using System.Data.OleDb;
using System.Configuration;
using System.Data.SqlClient;

And we need establish a connection to the Database and OLEDB. Add below connection code in web.config file


<connectionStrings>
   <add name="AD_Phase2" connectionString="Data Source=localhost;Database=DatabaseName;User Id=sa;Password=Password" providerName="System.Data.SqlClient"/>
    <add name="ExcelConnection" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties='Excel 12.0;HDR=NO'\"/>
    <add name="Excel03ConString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=NO'"/>
    <add name="Excel07ConString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR=NO'"/>
  </connectionStrings>

Below is the code for read the Excel data and fill into datatable

//Read the Excel file and fill in datatable .
        public DataTable GetDataTable(string strSheetName)
        {
            try
            {
                string strComand;

                if (strSheetName.IndexOf("|") > 0)
                {
                    /* if Range is provided.*/
                    string SheetName = strSheetName.Substring(0, strSheetName.IndexOf("|"));
                    string Range = strSheetName.Substring(strSheetName.IndexOf("|") + 1);
                    strComand = "select * from [" + SheetName + "$" + Range + "]";
                }
                else
                {
                    //= Images_Path + "" + SaveStudentDetails.FileName;
                    strComand = "select * from [Sheet1$]";
                }
                //HttpPostedFile StudentPhotoFile = SaveStudentDetails.PostedFile;
                string excelConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FinalPath + ";Extended Properties='Excel 8.0;HDR=NO;'";
                OleDbConnection connection = new OleDbConnection(excelConnectionString);
                OleDbDataAdapter daAdapter = new OleDbDataAdapter(strComand, connection);
                DataTable dt = new DataTable("Datatable");

                DataColumn dc = new DataColumn();

                DataRow dr = dt.NewRow();
                dt.Rows.Add(dr);

                daAdapter.Fill(dt);

                return dt;

            }

            catch (Exception ex)
            {
                throw new Exception("Select location" + ex.Message);
            }
        }