Showing posts with label Software Engineering. Show all posts
Showing posts with label Software Engineering. Show all posts

Sunday, February 16, 2014

HOW TO: Use ASP to Force SSL for Specific Pages

Forcing ASP page to use https can be done in couple of ways, here I’m sharing how we can do this using ASP.net code itself, rather than configuring IIS. Step 1: Create INC file with following code
<%
if(Request.ServerVariables["SERVER_PORT"]== "80")
            {
                string strSecureURL;
                strSecureURL = "https://";
                strSecureURL = strSecureURL + Request.ServerVariables["SERVER_NAME"];
                strSecureURL = strSecureURL + Request.ServerVariables["URL"];
                Response.Redirect(strSecureURL);
            }
%>
Then save it as “ForceSSL.inc” in web application root directory. Step 2: Add reference to INC file by adding below line:

Note: If you are using Master page, then you have to add this code inside




Step 3: Add https as new binding in IIS.
Reference: http://support.microsoft.com/kb/239875

Tuesday, June 25, 2013

Unable to start debugging. The Silverlight Developer Runtime is not installed. Please install a matching version.

Today I tried to run Silverlight sample project in my machine and I got below error.
“Unable to start debugging. The Silverlight Developer Runtime is not installed. Please install a matching version.”

I checked the Silverlight version I installed and it was version 4. Then I just did a Google search and found the below blog post, after installing Silverlight_Developer.exe I was able to run Sample Silverlight application successfully. 



Thanks

Monday, June 24, 2013

CRM 2011 Filtered sub grid

Filtered sub grid is very commonly used feature in CRM 2011.
As you may already know we can use CRM default feature to filter sub grid data by selecting different views for sub grid. But you may come across situations where system needs to filter sub grid data based on opening record field,
For example you need to filter Contact sub grid based on Account form City field. So sub grid should only Contacts which have same city as Account City:
In this kind of scenario we can use javascript to add filter to the sub grid.

Use advance find and generate fetch xml for filter contact

function setContactSubGrid() {
    var grid = $('#accountContactsGrid')[0];
    var accountCity = Xrm.Page.getAttribute("address1_city").getValue();
    if (grid == null || grid.readyState != "complete") {
        setTimeout('setContactSubGrid()', 2000);
    }
    else {

        var fetchXml = "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "" +
            "";
            
        grid.control.setParameter("fetchXml", fetchXml);

        grid.control.refresh();
    }
}
Call this function on Account onLoad event.

Thursday, March 29, 2012

Remove duplicate records from Generic List

Following code snippet give you a distinct values from the Generic int List. Here I'm using LINQ query to retrieve Distinct items

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
List listOfItems = new List();

listOfItems.Add(4);
listOfItems.Add(2);
listOfItems.Add(3);
listOfItems.Add(1);
listOfItems.Add(6);
listOfItems.Add(4);
listOfItems.Add(3);

var duplicates = listOfItems
.GroupBy(i => i)
.Select(g => g.Key);

foreach (var d in duplicates)
{
Console.WriteLine(d);
}
Console.ReadLine();
}
}
}

Out put :

4
2
3
1
6

Tuesday, March 20, 2012

CRM 2011 - Update user time zone from SQL query


Recently I wanted to find out users who are not in the correct time zone in CRM System. To change the time zone or user related settings we need to log in to the system by using that particular user's login details (see the below screen shot 1 and 2).


But if you system is up and running it is not possible to ask there login details. so here it the solution. login to the system as System admin, then go to the File , Option and "General" Tab Set the time zone and click "OK".

In CRM we have separate table "[UserSettingsBase] " , which contains all the user related setting information. for an example time zone, currency, language and ..... Use the following script to get the admin users time zone details from the database.


select TimeZoneBias, TimeZoneCode from [UserSettingsBase]
where SystemUserId In (select distinct SystemUserId from SystemUserBase where DomainName like '%DOMAIN\USERNAME%')

Find out which users are not in the correct time zone. use following script.
select FullName , CreatedByName, CreatedOn, DomainName, ModifiedByName from SystemUser
where SystemUserId In (
SELECT SystemUserId
FROM [UserSettingsBase]
where [TimeZoneBias] != -480
and [TimeZoneCode] != 215)
and IsDisabled = 0

If you want to update these users time zone with correct time zone you can simpy use following script. Don't forget to give an iisreset to view your changes.
update [UserSettingsBase]
set [TimeZoneBias] = -330, TimeZoneCode = 200
where SystemUserId IN (select SystemUserId from SystemUser
where SystemUserId In (select SystemUserId
from [PRM_MSCRM].[dbo].[UserSettingsBase]
where [TimeZoneBias] != -480
and [TimeZoneCode] != 215)
and IsDisabled = 0)

Tuesday, March 6, 2012

How to pass current view id to Custom web page through ribbon button in CRM 2011

In my recent project I wanted to get all the records which are in current view and do some processing and display those records in a custom web page.

My Approach

1. Get the selected View id
2. pass it to the custom web page as query string through ribbon button.
function LoadRecords() {
var selectedViewId = document.getElementsByTagName("span");

var el = getElementsByAttribute("span", "currentview");
var viewId = el[0].id;

var UserID = GetCurrentUserID();
var sUrl = '/ISV/myCustomPage.aspx?crmuserid=' + UserID + '&amp;viewid=' + viewId;
var sWin = window.open(sUrl, '', 'height=750 ,width=900, left=75, top=50 ,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,modal=yes');
}

function getElementsByAttribute(strTagName, strAttributeName) {
var arrElements = document.getElementsByTagName(strTagName);

var arrReturnElements = new Array();
var oCurrent;
var oAttribute;
for (var i = 0; i < arrElements.length; i++) {
oCurrent = arrElements[i];

oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
if (typeof oAttribute == "string" && oAttribute.length > 0) {
arrReturnElements.push(oAttribute);
}
}
return arrReturnElements;
}

3. get the selected view from SavedQuery table
public SavedQuery GetSavedQueryById(Guid viewId)
{
SavedQuery savedQuery = null;
if (!viewId.Equals(Guid.Empty))
{
savedQuery = (SavedQuery)service.Retrieve(SavedQuery.EntityLogicalName, viewId, new ColumnSet(true));
}
return savedQuery;
}

4. extract the conditions for selected view from FetchXml column

private Dictionary<string, string> getCoditionListForSelectedView(string selectedView)
{
try
{
Dictionary<string, string; condList = new Dictionary<string, string>();
commonFacadecs = new CommonFacade();
string fetchXML = commonFacadecs.GetSavedQueryById(viewId).FetchXml.ToString();

string formattedXML = XElement.Parse(fetchXML).ToString();

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(formattedXML);
XmlNodeList nodeList = xmlDoc.SelectNodes("/entity");
XmlNodeList nodeList2 = xmlDoc.GetElementsByTagName("condition");

for (int i = 0; i &lt; nodeList2.Count; i++)
{
XmlAttributeCollection xmlAttrc = nodeList2[i].Attributes;
string name = xmlAttrc[0].Value;
string oper = xmlAttrc[1].Value;
string Value = xmlAttrc[2].Value;
condList.Add(oper, Value);
}
return condList;
}
catch (Exception exception)
{
throw
}
}

5.Retrieve records according to the filter condition

Results

Above approach will give you the all the records which are coming from the selected view
then you can do whatever the processing and display it in custom web page.

Monday, February 27, 2012

Visual Ribbon Editor for MS CRM 2011

In CRM 2011 Editing ribbon is a very hard thing. because we have to change lot of xml files. But Visual Ribbon Editor is a wonderful tool which will enable you to edit CRM ribbon more easily, definitely it will make your life more easier .

You can download it from codeplex

Sunday, July 17, 2011

MVC Movie App tutorial : Unable to find the requested .Net Framework Data Provider. It may not be installed

I got another problem when I work with MVC Movie App tutorial provided by Microsoft Asp.Net site.
I just go through the step by step. But unfortunately I stuck at one point. Once I build the solution and press F5, and I tried to go to the following url. But it says “Unable to find the requested .Net Framework Data Provider. It may not be installed.”

I tried several options and found good solution at this url.

What I did was just replace the connection string given by that url with my connection string. It works perfectly now….

Friday, July 15, 2011

How to change debugging browser used in VS 2010 , MVC 3

Recently I have work with Asp MVC 3 and had a problem with changing my default Brower from Firefox to IE.

In Asp.NET it is possible with “browse with” option. See more details on ScottGu’s blog.
But in MVC project we don’t have any aspx files, so how to configure our solution to do it so?
There is a way to do this.

1. Right click on solution and go to the “Properties”
2. Go to “Web” Tab
3. Set the Start Action to use Start external program and then pass the Internet Explorer executable path and the url as Command line arguments.
4. Set the Servers’ specific port to the same port set in the url in step 3.
See the following image to get more info.

Thursday, July 14, 2011

VS2010 not opening CSS files : MVC 3

Hi all,

I am using Visual Studio 2010 as my development platform. Recently I have install MVC 3 with Web Standards Update for Microsoft Visual Studio 2010. But unfortunately when I try to work with MVC 3 applications I was unable to open CCS file with Visual Studio.

So I just Google it and found the solution. Here is the link .

Try to repair your installed Web Standards Update for Microsoft Visual Studio 2010 SP1 by using following path.

Got to Tools - Extension Manager - Online Gallery and search for/install the "Web Standards Update for Microsoft Visual Studio 2010 sp1"

Then click on repair link. And restart Visual Studio. Hop everything fine now ….

Friday, May 22, 2009

Web Hosting

If you want to take part in the internet as a business, information resource, directory, or as a hobbyist wanting to share data, information and knowledge with the many people and communities on the internet, you have to contain this in a central spot on the internet. You have to own a piece of space in cyberspace

Web hosting empowers you and anyone with a computer and internet connection to own a piece of cyberspace. In your space, you can have news, bulletins, documents, data, files (your web site) and your own post office (mail server) to accept mail, all in the context of you or your business. This is your space and to get this space you either have to own a piece of the physical internet with a network connection to the internet backbone and computer(s) operating as server(s) offering access to your files and post office, for people on the internet to view your web site or send and receive email with you.

The cost of owning a direct connection to the backbone and a server dedicated to a web site and email is out of reach for the average business and especially general members of the internet. Even running a web site and mail server on your own computer when it is connected to the internet requires a lot of technical ability and knowledge. The internet itself has to be your business for either of these options to be viable.

In a web-hosting environment, you are offered a web site to place your files, data, documents, and bulletins for people to access with their web browser and an email server for you to send and receive email messages. The web host will also provide you a means to get an address for people to get to your web site with a web browser and post email to you.

This is just a begin. I’ll write more about web hosting in my next post… cheers you all.

Tuesday, May 5, 2009

How to Order a SQL Server Database Hosting Plan

If you wish to add a SQL Server database option to your hosting account, simply add the option when you order your hosting account. If you only need a SQL Server database without a website, please contact our Sales Department and they will be happy to assist you.

Alentus SQL Backup Service

Alentus SQL Backup Service is our optional additional backup service that lets you determine how often you want accessible backup files created of your valuable information. See how you can go beyond emergency backups and be in control of your data protection.

SQL Server Hosting Technical Information

For information on using SQL Server Enterprise Manager, SQL Server Query Analyzer, DTS, ODBC/OLEDB database connections, SQL Server Management Studio and more, please see the following sections of our Technical Support Center:

SQL Server 2005 Information and Resources

SQL Server 2005 drives better decision-making with enterprise-grade reporting and data analysis. A highly reliable database platform for critical applications, SQL Server 2005 delivers high levels of availability, performance, and security. For more information and links to SQL Server 2005 resources, please visit:

Sunday, January 4, 2009

ODBC Vs OLEDB

Hi all, Hope this post will help for the DB beginners. :)
Back in the old days, database connectivity was difficult. Everybody had their own database formats, and developers had to know a low level API for each database they wished to develop for. There was a push for a universal API, an API which would work for numerous data stores. It was about this time that ODBC, or Open Database Connectivity, which was an early attempt at creating this universal API. A number of databases conformed to this standard, and became known as ODBC-compliant databases. ODBC-compliant databases consist of Access, MS-SQL Server, Oracle, Informix, etc.

ODBC is Open Data Base Connectivity, which is a connection method to data sources and other things. It requires that you set up a data source, or what's called a DSN using an SQL driver or other driver if connecting to other database types. Most database systems support ODBC

Well, ODBC wasn't perfect. It still contained a lot of low-level calls, and was difficult to develop with. Developers had to focus more on low-level communications with the database, as opposed to being able to concentrate on getting the data they needed and using it how they saw fit. Along came Microsoft's solution: DAO, or Data Access Objects.

.OLE is Object Linking and Embedding. OLEDB is partly distinguished from OLE itself, now called "automation". OLEDB is the successor to ODBC, a set of software components that allow a "front end" such as GUI based on VB, C++, Access or whatever to connect with a back end such as SQL Server, Oracle, DB2, mySQL etal. In many cases the OLEDB components offer much better performance than the older ODBC.OLEDB is a different type of data provider that came about with MS's Universal Data Access in 1996 and does not require that you set up a DSN. It is commonly used when building VB apps and is closely tied to ADO. It works with COM, and DCOM as of SQL 7.0.

OLEDB sits between the ODBC layer and the application. With your ASP pages, ADO is the "application" that sits above OLEDB. Your ADO calls are first sent to OLEDB, which are then sent to the ODBC layer. You can connect directly to the OLEDB layer, though, and if you do so, you'll see an increase in performance for server-side cursors (the default cursor type for recordsets, and the most common type of cursor used).

Sunday, December 7, 2008

Visual Studio Test Attributes

When we built our test in the previous section, we were required to use the following two attributes:
· [TestMethod] – Used to mark a method as a test method. Only methods marked with this attribute will run when you run your tests.
· [TestClass] – Used to mark a class as a test class. Only classes marked with this attribute will run when you run your tests.
When building tests, you always use the [TestMethod] and [TestClass] attributes. However, there are several other useful, but optional, test attributes. For example, you can use the following attribute pairs to setup and tear down tests:
· [AssemblyInitialize] and [AssemblyCleanup] – Used to mark methods that execute before and after all of the tests in an assembly are executed
· [ClassInitialize] and [ClassCleanup] – Used to mark methods that execute before and after all of the tests in a class are executed
· [TestInitialize] and [TestCleanup] – Used to mark methods that execute before and after each test method is executed
For example, you might want to create a fake HttpContext that you can use with all of your test methods. You can setup the fake HttpContext in a method marked with the [ClassInitialize] attribute and dispose of the fake HttpContext in a method marked with the [ClassCleanup] attribute.
There are several attributes that you can use to provide additional information about test methods. These attributes are useful when you are working with hundreds of unit tests and you need to manage the tests by sorting and filtering the tests:
· [Owner] – Enables you to specify the author of a test method
· [Description] – Enables you to provide a description of a test method
· [Priority] – Enables you to specify an integer priority for a test
· [TestProperty] – Enables you to specify an arbitrary test property
You can use these attributes when sorting and filtering tests in either the Test View window or the Test List Editor.
Finally, there is an attribute that you can use to cause a particular test method to be ignored when running a test. This attribute is useful when one of your tests has a problem and you just don’t want to deal with the problem at the moment:
· [Ignore] – Enables you to temporarily disable a test. You can use this attribute on either a test method or an entire test class

Monday, December 1, 2008

Unit test in VS 2005

If you didn't know it already, it is not a difficult one to learn.Tremendous progress is being made on several fronts: IDE integration, process integration, and new test fixtures. In here I will cover unit testing in Visual Studio 2005, including VSTS unit testing, NUnit and MBUnit--the Superman of unit testing. First post I’ll cover NUnit testing.

NUnit
NUnit is the unit testing framework that has the majority of the market share. It utilizes attributes to identify what a test is.
The TestFixture attribute is used to identify a class that will expose test methods.
The Test attribute is used to identify a method that will exercise a test subject.
Let's get down to business and look at some code. First we need something to test.
public class Subject
{
public Int32 Add(Int32 x, Int32 y)
{
return x + y;
}
}
That Subject class has one method: Add.
We will test the Subject class by exercising the Add method with different arguments.
[TestFixture]
public class tSubject
{
[Test]
public void tAdd()
{
Int32 Sum;
Subject Subject = new Subject();
Sum = Subject.Add(1,2);
Assert.AreEqual(3, Sum);
}
}
The class tSubject is decorated with the attribute TestFixture, and the method tAdd is decorated with the attribute Test.
You can compile this and run it in the NUnit GUI application. It will produce a successful test run.
That is the basics of what NUnit offers. There are attributes to help with setting up and tearing down your test environment:
SetUp, SetUpFixture, TearDown, and TearDownFixture. SetUpFixture is run once at the beginning when the fixture is first created; similarly,
TearDownFixture is run once after all tests have completed. SetUp and TearDown are run before and after each test.
NUnit tests can be run several different ways: from the GUI application, from the console's application, and from a NAnt task. NUnit has been integrated into Cruise Control .NET as well. In the last product review, you will see how it has been integrated into the VS.NET IDE as well.

Thursday, November 20, 2008

Measuring Performance of Stored Procedures

Database developers need to write stored procedures which are not only fully functional, but also which perform acceptably. As database servers use permanent storage media heavily (mainly because of ACID properties), which are known for slow performance, optimizing the stored procedures for performance is very important. In here I’ll describe on some of the counters used to measure performance and analyses methods of capturing these counters. This post is intended for database developers who write stored procedures and optimize for performance.
Currently there are three counters widely used for measuring performance of the system.
  • Execution time
  • CPU Cost
  • IO Cost

Execution Time
The most primitive method is to get the time taken to execute the query from SQL Server Management Studio (SSMS). The status bar displays the time taken in terms of hour, minute and second. This may be a measure used when a query takes a longer time (Usually more than 10 seconds, so that a 10% improvement to the query could be measured) and the time difference in sub seconds is insignificant. When a query executes within a second, SSMS rounds the value. Thus this value could not be used to get the value if the query executes within sub seconds.Another method is to get the system time before and after the execution of the stored procedure and analyze the difference. SQL Server management studio could be used for this purpose, simply by adding print statements before and after the stored procedure.


PRINT CONVERT(varchar, GETDATE(), 114)


The developer could also use variables to hold the values and calculate the time difference.The advantage over this method is it could be used within a query too. For a stored procedure to be executed multiple times with different parameter for each time, print statement could be injected between each execution to analyze the time difference. For a multi statement procedure, Developers need to modify the stored procedure adding print statement, but it gives better control over the data to the developers. On the disadvantages side, one of the major points is its disability over getting time taken for compilation. Instead of PRINT statements, the time could be inserted into a table for further analysis is required. As datetime data type as it allows the value to be accurate up to 3 milliseconds the results may have vary with actual up to 3 milliseconds, and better than the previous method.

SQL Server has some other methods too.

SQL Server has a Set option which could be used to display the time taken:


SET STATISTICS TIME ON

SET STATISTICS TIME OFF

When this set option is ON. SQL Server will return message which may look similar to:

SQL Server Execution Times:

CPU time = 109 ms, elapsed time = 164 ms.

Elapsed time is the execution time of the query.

However, there is another time involved in this query: The time taken to compile the query. To view that, the statement should be issued when SET STATISTICS TIME ON Statement is already executed. When a batch of statements is submitted, SQL Server goes through ALL of them but compiles one by one. As GO is considered as batch separator, inserting a GO statement between the SET command and the query will make SQL Server to consider each statement as a batch and compile and execute them separately. Executing the set command first and executing the query (i.e. in two batches) will also do the trick.

When done the messages may be different.

SQL Server parse and compile time:

CPU time = 62 ms, elapsed time = 72 ms.

(1139 row(s) affected)

SQL Server Execution Times:

CPU time = 109 ms, elapsed time = 167 ms.

In this case, the time taken by the server for execution is 167 milliseconds. In addition to this, 72 milliseconds have been taken for compilation. The unit of measurement is in milliseconds and smaller figures will be rounded. When a multi statement stored procedure is called, the total time may slightly differ from the calculation. For this reason, SQL Server provides a summary too. Additionally, some of the internal operations like creating worktables, statistics on temporary tables etc. may create additional load but not be captured as individual statements. However, they will be added to the final cost.

I'll explain the other topics in my next post.

Monday, November 10, 2008

Full Text Indexing in SQL Server

Sql Server’s Full-Text search can let a developer create some very slick features disturbingly easily. And, unlike many other Full-Text implementations, it is not limited to plain text fields. It can also search within binary fields with the proper setup considerations. Needless to say, there are a few protips to making Full-Text indexes work and taking advantage of them. In this post, I will tell you how to get Full-Tex.

Getting Started

First, you are going to need a copy of Sql Server 2000 or 2005 Standard edition. MSDE or Sql Express do not have Full-Text capabilities. In order to enable Full-Text search, you must do a few things.
  • Enable Full-Text search on the database.
  • Create a Full-Text catalog.
  • Enable Full-Text searching on specific columns in your data.

Full Text Indexing in SQL Server 2000

  • Create and populate a table.
  • Enable the pubs database for full-text searching
  • Create a full-text catalog.
  • Register the new table and certain columns in it for full-text search.
  • Populate the new full-text catalog with full-text index information from the new
  • tableExecute a full-text query against the new table.

USE Pubs

-- Create and populate a table.

IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES

WHERE TABLE_NAME = 'FulltextTest')

DROP TABLE FulltextTest

GO

CREATE TABLE FulltextTest

( article_id int IDENTITY(100,1)

CONSTRAINT PK_title_id PRIMARY KEY,article_title nvarchar(200))

INSERT FulltextTest (article_title) VALUES (N'Steven Buchanan has always enjoyed ice skating.')

INSERT FulltextTest (article_title) VALUES (N'Elvis Stoiko: The best male figure skater')

INSERT FulltextTest (article_title) VALUES (N'Steven Buchanan On Ice: Skating Reaches Tops in Public Opinion Poll')

INSERT FulltextTest (article_title) VALUES (N'Last night, Steven Buchanan skated on the ice!! Skating fans cheer!')

INSERT FulltextTest (article_title) VALUES (N'Ice-skating brings out the best in Steven. Buchanan exults in first victory...')

GO

-- Enable full-text searching in the database.

EXEC sp_fulltext_database 'enable'

GO

-- Create a new full-text catalog.

EXEC sp_fulltext_catalog 'StevenBCatalog', 'create' GO

-- Register the new table and column within it for full-text querying,

-- then activate the table.

EXEC sp_fulltext_table 'FulltextTest', 'create', 'StevenBCatalog', 'PK_title_id'

EXEC sp_fulltext_column 'FulltextTest', 'article_title', 'add'

EXEC sp_fulltext_table 'FulltextTest', 'activate'GO

-- Start full population of the full-text catalog. Note that it is

-- asynchronous, so delay must be built in if populating a

-- large index.

EXEC sp_fulltext_catalog 'StevenBCatalog', 'start_full'

WHILE (SELECT fulltextcatalogproperty('StevenBCatalog','populatestatus'))<>0

BEGINWAITFOR DELAY '00:00:02'

-- Check every 2 seconds to see if full-text index population is complete.

CONTINUE

END

-- Execute a full-text query against the new table.

SELECT article_title

FROM FulltextTest

WHERE CONTAINS(article_title, ' "Steven Buchanan" AND "ice skating" ')

GO

MS CRM 2011 KB Article customization Issue.

Recently I have encountered some issue while customizing Kb Article Entity. I was doing following configuration in Article form. 1. Add Ba...