Monday, 11 April 2016

Default display format for date field in Oracle SQL Developer

For date fields, by default SQL Developer will display date only without the time.

To set it to display the time as well, do the following:

1. In SQL Developer, go to Tools >> Preferences.
2. In the Preferences dialog, select Database >> NLS Parameters from the left panel.
3. From the list of NLS parameters, enter DD-MON-RR HH24:MI:SS into the Date Format field.
4. Save and close the dialog.

Tuesday, 8 December 2015

MSDTC on server 'servername' is unavailable

By default, when a stand-alone instance of Microsoft SQL Server exists in a cluster environment, the SQL Server-based instance is set to start automatically. If the host node is rebooted, you may receive the following error message when you issue commands that are related to distributed transactions:

ERROR: MSDTC on server 'servername' is unavailable.

On the server where the trigger resides, you need to turn the MSDTC service on. You can this by clicking START > SETTINGS > CONTROL PANEL > ADMINISTRATIVE TOOLS > SERVICES. Find the service called 'Distributed Transaction Coordinator' and RIGHT CLICK (on it and select) > Start.

Context Has Changed Since the Database Was Created

This article describes and provides the solutions of a common error in Entity Framework: 
"Context has changed since the database was created, Model backing a DB Context has changed, Model backing the context has changed since the database was created."

This is the most frequent error in Entity Framework. This type of error occurred when the model and the database cannot be mapped correctly. That means there is a modification or changed in the database. We made any type of schema change on the table or database after including Entity Data Model in the project or solutions.

To solve this error write the following code in Application_Start() Method in Global.asax.cs file.
Database.SetInitializer<CustomerDBContext>(null);

That means we need to bind our DB context class with a null value. If the database schema is changed, it is mandatory to updates the .edmx file.

Wednesday, 25 February 2015

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode

To solve this issue go to Control Panel --> Administrative Tools --> IIS Manager and Change Application site's Managed Pipeline from Integrated to Classic.

The requested page cannot be accessed because the related configuration data for the page is invalid problem in IIS

We need to change the config section applicationHost file

First Open folder path based on this

C:\Windows\System32\inetsrv\config

After open this path we will find applicationHost file.

Now select applicationHost file and right click on applicationHost file and open with Notepad to modify config section.

After open applicationHost file with Notepad

Go to <configSections> under that go to <sectionGroup name="system.webServer">

<section name="handlers" overrideModeDefault="Deny" />
change this value from "Deny" to "Allow"
<section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
change this value from "Deny" to "Allow"

After change those values save your applicationhost file and run your application it will work for you.

Monday, 9 February 2015

How to change local folder for TFS

To change local folder path for TFS do the following steps:

1- Connect to your TFS
2- Go to File > Source Control > Workspaces
3- Click on Edit... the workspace which is causing the problem
4- Change the local folder and click on OK.

Sunday, 28 September 2014

CONVERT IP ADDRESS INTO URL IN C#

To convert an IP (Internet protocol) address into corresponding Url (Uniform Resource Locator)  in C#, ASP.NET you need a help of IPHostEntry and  IPAddress class. Make an object of this call and call the Dns.GetHostEntry() class to find the HostName against the Url.

IPAddress addr = IPAddress.Parse("195.175.254.2");
IPHostEntry entry = Dns.GetHostEntry(addr);
Response.Write(entry.HostName.ToString());

entry.HostName.ToString() will return the host name of the IP address.

Wednesday, 6 August 2014

Export the data in excel format

Below is the code.

private void Save(string detail)
    {
        Response.ContentType = "application/ms-excel";
        Response.AddHeader("content-disposition", "attachment; filename=Data.xls");
        Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
        Response.Write("<head>");
        Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=windows-1252\">");
        Response.Write("<!--[if gte mso 9]>");
        Response.Write("<xml>");
        Response.Write("<x:ExcelWorkbook>");
        Response.Write("<x:ExcelWorksheets>");
        Response.Write("<x:ExcelWorksheet>");      
        Response.Write("<x:Name>Personal Detail</x:Name>");
        Response.Write("<x:WorksheetOptions>");      
        Response.Write("<x:Panes>");
        Response.Write("</x:Panes>");
        Response.Write("</x:WorksheetOptions>");
        Response.Write("</x:ExcelWorksheet>");
        Response.Write("</x:ExcelWorksheets>");
        Response.Write("</x:ExcelWorkbook>");
        Response.Write("</xml>");
        Response.Write("<![endif]-->");
        Response.Write("</head>");
        Response.Write("<body>");
        Response.Write(detail);
        Response.Write("</body>");
        Response.Write("</html>");
        // --------------------------------  
        Response.End();
    }

Wednesday, 23 July 2014

Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on.

Set ConcurrencyMode to Reentrant as shown below above the class implemented the Service contract interface.
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]

Set the property of the Form/Page class in the client application as below.
[CallbackBehavior(UseSynchronizationContext = false)]

Set the text box property CheckForIllegalCrossThreadCalls to false like below in the method describing duplext contract.
TextBox.CheckForIllegalCrossThreadCalls = false;

Thursday, 10 July 2014

HTTP could not register URL http://+:8000/HelloWCF/. Your process does not have access rights to this namespace.

Most people are no longer going to be running with Administrator privileges by default like they were doing on earlier platforms. This impacts your ability to run HTTP web services because listening at a particular HTTP address is a restricted operation. By default, every HTTP path is reserved for use by the system administrator.

Your services will fail to start with an AddressAccessDeniedException if you aren't running the service from an elevated account. The account under which the Visual Studio and the debugger runs does not have the privilege (though the user account under which VS is runnig may be a part of Administrators group), and hence the error occurs. The plus sign in the URL just means that there's a wildcard being applied to the hostname.

Run application administration mode.

Right click on vs and run as administrator.

Tuesday, 20 May 2014

Click Jacking

Clickjacking (also known as user-interface or UI redressing and IFRAME overlay) is an exploit in which malicious coding is hidden beneath apparently legitimate buttons or other clickable content on a website.
Ex: A visitor to a site thinks he is clicking on a button to close a window; instead, the action of clicking the “X” button prompts the computer to download a Trojan Horse, transfer money from a bank account or turn on the computer’s built-in microphone. The host website may be a legitimate site that's been hacked or a spoofed version of some well-known site. The attacker tricks users into visiting the site through links online or in email messages.
Suppose I am using iframe in your for some reason. I want to give security so that no one can hack using click jacking technique by loading his content instead of mine.
Suppose in design I am using iframe and id of iframe is ifShowThen just copy paste below code to prevent click jack on the site.

<script type="text/javascript" language="Javascript">
        function Check() {           
            try{
                if (window.top !== window.self) {
                    window.top.location = window.self.location;
                    return;
                }

                if (window.top.location.host != window.self.location.host) {
                    //window.top.location = window.self.location;
                    window.top.location = window.self.location;
                    return;
                }               
                var domain = document.getElementById('ifShow').src.replace('http://', '').replace('https://', '').split(/[/?#]/)[0];
                if (window.self.location.host != domain) {
                    window.top.location = window.self.location;
                    return;
                }
            }
            catch (ex)
            { window.top.location = window.self.location; /* everyone else */ }
           
        }
        setInterval(Check, 1000);
        Check();

    </script>

Thursday, 13 March 2014

Disable/Enable all trigger in a database

To Disable All the Triggers
sp_MSforeachtable "ALTER TABLE ? DISABLE TRIGGER ALL"

To Enable All the Triggers
sp_MSforeachtable "ALTER TABLE ? ENABLE TRIGGER ALL"

Friday, 1 November 2013

How to identify when a SQL Server database was restored

To know when a database is restored run the below query in the database.

SELECT [rs].[destination_database_name],
[rs].[restore_date],
[bs].[backup_start_date],
[bs].[backup_finish_date],
[bs].[database_name] as [source_database_name],
[bmf].[physical_device_name] as [backup_file_used_for_restore]
FROM msdb..restorehistory rs
INNER JOIN msdb..backupset bs
ON [rs].[backup_set_id] = [bs].[backup_set_id]
INNER JOIN msdb..backupmediafamily bmf
ON [bs].[media_set_id] = [bmf].[media_set_id]
ORDER BY [rs].[restore_date] DESC

Meanings of the column

destination_database_name  -   The name of the database that has been restored.
restore_date   -    The time at which the restore command was started.
backup_start_date  -  The time at which the backup command was started.
backup_finish_date  -  The time at which the backup command completed.
source_database_name  -  The name of the database after it was restored.
backup_file_used_for_restore  -  The file(s) that the restore used in the RESTORE command.

Wednesday, 2 October 2013

Operation is not valid due to the current state of the object.

I am getting the below error while binding a gridview.

Operation is not valid due to the current state of the object.

[InvalidOperationException: Operation is not valid due to the current state of the object.]
   System.Web.HttpValueCollection.ThrowIfMaxHttpCollectionKeysExceeded() +2692482
   System.Web.HttpValueCollection.FillFromEncodedBytes(Byte[] bytes, Encoding encoding) +61
   System.Web.HttpRequest.FillInFormCollection() +148

[HttpException (0x80004005): The URL-encoded form data is not valid.]
   System.Web.HttpRequest.FillInFormCollection() +206
   System.Web.HttpRequest.get_Form() +68
   System.Web.HttpRequest.get_HasForm() +8743911
   System.Web.UI.Page.GetCollectionBasedOnMethod(Boolean dontReturnNull) +97
   System.Web.UI.Page.DeterminePostBackMode() +63
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +133

This error occurs when form fields are very large in numbers.By default, the maximum value of MaxHttpCollection is 1000.

To solve this error, increase MaxHttpCollection value in web.config.Add the following setting in your web.config's <appsettings> block.

<appSettings>
        <add key="aspnet:MaxHttpCollectionKeys" value="3000" />
 </appSettings>

You can change the value accordingly as per your need.

Tuesday, 10 September 2013

Fixed Header and Footer using CSS

If you want to create a header and footer part which will be fixed in their place then follow the below steps.

Place the below css in the page.
 <style type="text/css">
        #header
        {
            background: #eee;
            border: 1px solid #666;
            height: 60px;
            left: 0;
            position: fixed;
            width: 100%;
            top: 0;
            text-align: center;
        }
        #content
        {
            margin: 0 auto;
            overflow: auto;
            padding: 80px 0;
            width: 940px;
        }
        #footer
        {
            background: #eee;
            border: 1px solid #666;
            bottom: 0;
            height: 60px;
            left: 0;
            position: fixed;
            width: 100%;
            text-align: center;
        }
    </style>

Place the below content in the page.
<div id="header">
            Header Content
</div>
<div id="content">
           Text part will place here.
</div>
<div id="footer">
            Footer Content
</div>

Run the project by using F5 and see the output.

Wednesday, 17 July 2013

Handler "svc-Integrated" has a bad module "ManagedPipelineHandler" in its module list

If you  will get this error while running your wcf application then you didn't install the prerequistes for ASP.NET 4.

To install the prerequistes go to
Start --> All Programs --> Microsoft Visual Studio 2008 --> Visual Studio Tools --> Open Visual Studio Command Prompt.
Run Visual Studio 2008 Command Prompt as “Administrator”.

Type the following:
     aspnet_regiis.exe -i

Run your application.

Saturday, 13 July 2013

Windows could not start the SQL Server (MSSQLSERVER) service on Local Computer.Error 1069: The service did not start due to a logon failure.

I was getting the same error since I had changed the password of my computer. I have changed in the services after that it is working fine.

Go to Run-->services.msc--> SQl Server(MSSQLSERVER) . Right click --> Properties -->  Click on "Log on" tab. I have changes the password and retype the current windows password again. It works.

Thursday, 27 June 2013

Store Datatable Column Name in an Array Using LINQ

If you want to store datatable column values in an array using LINQ you can achieve this by the following ways.

string[] ColName = dt.Columns.Cast<DataColumn>().
                                   Select(x => x.ColumnName).ToArray();

Wednesday, 26 June 2013

Store Datatable Row Values in Jagged Array using LINQ

If you want to store values of a datatable in a jagged array using LINQ you can achieve in the following ways.

string[][] Value = dt.Rows.OfType<DataRow>().
                                Select(r => dt.Columns.OfType<DataColumn>().
                                Select( c => r[c.ColumnName].ToString()).ToArray()).
                           ToArray();

Thursday, 6 June 2013

Find System MAC Address using C#

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(GetMACAddress());
}

public string GetMACAddress()
{
        NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();        
        foreach (NetworkInterface adapter in nics)
        {
             if (sMacAddress == String.Empty)  // only return MAC Address from first card  
             {
                   IPInterfaceProperties properties = adapter.GetIPProperties();
                   return adapter.GetPhysicalAddress().ToString();
              }
        }
        return String.Empty;
}