Skip to main content

Posts

Stored procedure slow when called from web, fast from Management Studio

Some time this problem occurs due to compiled query plan became corrupt, or invalid. Stored procedure slow when called from web, fast from Management Studio becuase Basically connections through Sql Server Management Studio (SSMS) by default have SET ARITHABORT ON. ADO.NET connections do not. The main difference when running with or without this setting, a different query plan is created for the both stored procedure calls. In case of ARITHABORT was OFF, the SSMS command would use the pre-compiled cached query plan that the ADO.NET connection was using (compiled query plan became corrupt, or invalid.), and therefore timeout. Use following Command to refresh the query Plans. DBCC DROPCLEANBUFFERS DBCC FREEPROCCACHE Query parameterization promotes the reuse of cached execution plans, thereby avoiding unnecessary compilations, and reducing the number of ad-hoc queries in the plan cache. This is called Parameter Snifting. Sql-server using Parameter Snifting (Default Enabled)...

C#, Read a file

C#, Code to read a file  String strHtmlMessage = String .Empty; String strFilePath = HttpContext.Current.Server.MapPath("~/Mails/Confirmationmaill.htm");   using (StreamReader sr = new StreamReader(strFilePath))   {     strHtmlMessage = sr.ReadToEnd();  }

Time on my EC2 windows instance changed automatically

Configure Windows time sync: First ensure that you can get time from a NTP server, otherwise the instructions below are not going to work. To test, get the current variance from an NTP server using the following Windows Time service command w32tm /stripchart /samples:5 /computer:pool.ntp.org /dataonly In a VPC we had to open UDP port 123 for inbound connections in the NAT security group. To configure NTP time sync in Windows 1. Registry edit - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\TimeProviders\NtpClient Set SpecialPollInterval to polling interval in seconds (we set ours to 60). 2. Registry edit - HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Parameters Set Type to NTP 3. Run the following commands to configure the time servers (can use other servers, we're using 4 time servers - 0.pool.ntp.org, time.nist.gov, 1.pool.ntp.org, and 2.pool.ntp.org) net stop w32time w32tm /config /syncfromflags:manual /manualpeerlist:"0....

How to increase Session Timeout?

We can set our custom session timeout in our applications by following Methods 1.     In  Web.config  file we can set session timeout like as shown below  < configuration > < system.web >  < sessionState   mode = " InProc "   timeout = " 120 " >  </ sessionState >  </ system.web > </ configuration > Note that if you are using Forms authentication, the Forms timeout setting will log the user out after the set timeout period so you will also have to adjust this attribute: < authentication mode = " Forms "  >  < forms   timeout = " 120 " >  </ authentication > 2.     In  Global.asax  file we can set session timeout in Session_Start  event like this void Session_Start( object sender, EventArgs e) { // Code that runs when a new session is started Session....

Get size of all tables in database

Determining space used for each table in a SQL Server SELECT t.NAME AS TableName,     s.Name AS SchemaName,     p.rows AS RowCounts,     SUM (a.total_pages) * 8 AS TotalSpaceKB,     SUM (a.used_pages) * 8 AS UsedSpaceKB,     ( SUM (a.total_pages) - SUM (a.used_pages)) * 8 AS UnusedSpaceKB FROM sys.tables t INNER JOIN sys.indexes i ON t. OBJECT_ID = i. object_id INNER JOIN sys.partitions p ON i. object_id = p. OBJECT_ID AND i.index_id = p.index_id INNER JOIN   sys.allocation_units a ON p.partition_id = a.container_id LEFT OUTER JOIN   sys.schemas s ON t. schema_id = s. schema_id WHERE t.NAME NOT LIKE 'dt%' AND t.is_ms_shipped = 0 AND i. OBJECT_ID > 255 GROUP BY t.Name, s.Name, p.Rows ORDER BY t.Name

AWS Multi-Factor Authentication (MFA):

MFA adds extra security by requiring users to enter a unique authentication code from their authentication device when accessing AWS websites or services. For MFA to work, you must assign an MFA device (hardware or virtual) to the IAM user or root account. The MFA device must be unique for each user; a user cannot enter a code from another user's device to authenticate. Virtual MFA device: A virtual MFA device uses a software application that generates six-digit authentication codes that are compatible with the Time-Based One-Time Password (TOTP) standard, as described in RFC 6238. The software application can run on mobile hardware devices, including Smartphone. Most virtual MFA applications allow you to host more than one virtual MFA device, which makes them more convenient than hardware MFA devices. However, you should be aware that because a virtual MFA might be run on a less secure device such as a Smartphone, a virtual MFA might not provide the same level of security as...

Amazon - AWS CloudTrail

1. AWS CloudTrail captures AWS API calls made by or on behalf of an AWS account and delivers log files to an Amazon S3 bucket that you specify. Using CloudTrail's console in the AWS Management Console, the AWS CLI, or the CloudTrail API, you create a trail, which specifies the bucket for log file delivery and storage. By default, your log files are encrypted using Amazon S3 server-side encryption (SSE). 2. You can identify which users and accounts called AWS APIs for services that support CloudTrail, the source IP address the calls were made from, and when the calls occurred. You can integrate CloudTrail into applications using the API, automate trail creation for your organization, check the status of your trails, and control how administrators turn CloudTrail logging on and off. 3. CloudTrail typically delivers log files within 15 minutes of an API call. These log files contain API calls from all of the account's services that support CloudTrail. 4. ...