Saturday, December 22, 2007

Collection was modified; enumeration operation may not execute

I got the above error when doing some specific step of operation in the foreach loop. One of that operation is to modify the content of the enumerations. Pls note that I'm not removing any entry just changing its value.
The only way to get around this problem is to use the classic for loop. The resultant code is not as elegant as foreach but anyway works so np :)
Just 1 question doesn't foreach internally execute the classic for loop, then why is classic for loop possible but not foreach

Create SQL Query for all SPs


This is something that everybody knows but I dono.

How to take the backup of all the SPs in your DB and create it as a single query.

I know how to generate queries for individual SP but dint know how to do it for all.

This is how it should be done:

Open the Object Explorer and click on the Stored Procedure folder.

Then you should see a tab listing all the SPs in the right.

Click on all the SPs and right click then and save in a file.

The Screenshot above is not accurate this is taken from System Stored Procedures just to give an Idea.

Tuesday, December 18, 2007

Get the URL of the host from the UserControl

this.Parent.Parent.Page.AppRelativeVirtualPath gives the URL
another way is:

public static string GetLocalPath
{
get
{
string path = "~" + HttpContext.Current.Request.Url.LocalPath;
path = path.ToLower();
return path
}

This query can be placed in Global.asax.cs and can be used by both the UserControl and any page.

Saturday, December 15, 2007

IE7 Internet Explorer has stopped working issue

I bought a new laptop loaded with IE7 and I've been facing the IE stopping issue from day 1. I did many things but it dint work. I got a simple solution from the below blog and it helped.
http://petesbloggerama.blogspot.com/2007/02/ie7-vista-internet-explorer-has-stopped.html

Sunday, November 25, 2007

Enable Tracing


Requestlimit = 50 that is it will stop tracing if 50 is over.
The default request limit is 10

Sort a List of Generics using anonymous method

I bumped across a code in my project where they use anonymous method to do sorting which was pretty difficult to understand. So I decided to write my own piece of code to understand how this stuff works:
******************************************************************************
using System;
using System.Collections.Generic;
using System.Text;

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

Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);

dinosaurs.Add("Tyrannosaurus");
dinosaurs.Add("aAmargasaurus");
dinosaurs.Add("Mamenchisaurs");
dinosaurs.Add("Deinonychus");
dinosaurs.Add("Compsognathus");

Console.WriteLine("\nCapacity: {0}", dinosaurs.Capacity);
Console.WriteLine("Count: {0}", dinosaurs.Count);
foreach(string dinosaur in dinosaurs)
{
Console.WriteLine("dinosaur before Sort"+dinosaur);
}

dinosaurs.Sort(delegate(string r1, string r2)
{
if(r1.Length == r2.Length)
{
return r1.CompareTo(r2);
}
else{
return r1.Length.CompareTo(r2.Length);
}
});

foreach(string dinosaur in dinosaurs)
{
Console.WriteLine("dinosaur after Sort"+dinosaur);
}


}
}
}
******************************************************************************The most difficult portion to understand was
dinosaurs.Sort(delegate(string r1, string r2)
I really dint understand how r1 and r2 picks up the correct values. The issue is its so randomly picks up values and sometimes r1 == r2

Visual Studio Website and Ajax

WebSite also has Ajax Tool Kit and Extension Toolbox but it will not work. Ajax works only in Ajax Enabled website but what is frustrating is there are no warning signals in ordinary web-site. In Website project we are able to drag the Ajax control, code it and also execute. When we execute we are asking for a partial render but is not happening and we’ve to later find out that we’ve to use the Ajax Enabled one.

Should ASP.NET use Parallel Class?

Scott Hanselman: Cool. Cool. My second question was if I'm imagining kind of a typical web application scenario where one client hits a website and when in the past that single thread would then go to an ASP.NET server, which would then call to a database, maybe I started doing parallelism and then one person hitting my web server now ends up being four connections to my database and that becomes a standard thing because I started being very familiar with these technologies, it seems to be like that would dramatically change the scale signature of the entire application and would potentially get me then diskbound quicker. If I'm ultimately not going to become CPU-bound as much, I'm going to become diskbound, but people are saying already that machines are fast and then CPUs are barely working and then ultimately we are IO-bound. So, what does this kind of parallelism mean when it comes to IO-intensive operations?
Stephen Toub: That's sort of two different questions and I'd like to address the first one, which is basically, what does this parallelism stuff have to do with the server? In general, server apps today like ASP.NET, they already have enough parallelism to satisfy the CPUs. So, you take a typical ASP.NET application, it's getting thousands of requests per second, if each of those requests can be isolated, if it's n ot accessing shared state or anything like that, you're already introducing a thousand different asynchronous pieces of work. So, unless you're expecting very few requests into your web server and unless each of those very few requests is doing a ton of computation w o r k , using parallel class, for example, in your server application might not buy you all that much, which ties into your second question. Because, like you say, a lot of stuff is IO-bound in server world and so you take something like asynchronous pages in ASP.NET, it's basically meant to limit the number of thread pool resources you're consuming and maximize your throughput while at the same time basically making sure that you're not blocking other people from requesting your server resources just because you're waiting for the database to come back or you're waiting for a web service call to return or something like that. So, a lot of the technologies that we're working on right now, we're focusing largely at desktop or at backend data processing, not so much at the web server world because for the most part your frontend web applications have enough concurrency to go around.
Taken from Parallel Programming with .net Hanselminutes

Amdah's Law

Amdahl's Law that talks about the relative speedups you can expect in your application based on how much the application is serial and how much of it is parallel. So, if a very small portion of your application is parallel, even if we were to increase by 100X, the speed at which that parallel section runs, if it's still dominated by the serial portion, you're not going to overall see monstrous speedups. However, if that small portion of your application is working on data and over time you expect the amount of data your application is processing to grow exponentially, well, then the benefits of parallelizing that small portion is going to make a significant impact or theoretically could.
Taken from Parallel Programming with .net Hanselminutes

Optimal Threads in one Processor is one assuming that its is a CPU operation
Taken from Parallel Programming with .net Hanselminutes

Process and Processor

Scott Hanselman: Help me understand when we say multi-core machines, if I have a single process that's running on a machine with four processors, is there agility? If I have multiple threads, are those threads jumping between? I don't quite understand how the hardware works. I always used to think it was one process gets pinned to a processor.
Stephen Toub: Only if you want it to. You'd actually have to express that either as the user in, for example, Task Manager or as a developing setting thread affinity and process affinity for particular processors, but by default, no. There is no affinity. If you have a process that uses only one thread, by default, that process will ever only be running on one processor at a time, but it can certainly move around from processor to processor. Ideally, it won't for a lot
of subtle reasons like making sure that caches aren't invalidated and the memory that the -- well, that
caches aren't invalidated is good enough, but if the process has in it multiple threads and let's say in your case it has four threads, each of those four threads can be running one on each processor at the same time.
Scott Hanselman: Who decides that?
Stephen Toub: For the most part, it's t h e operating system unless as a developer you go ahead and say, "This thread here, I really want to tie to processor 3," in which case you can set an affinity mask that says, "Never let the operating system only allow this thread to run on processor 3 and if processor 4 is available and there's absolutely nothing happening on it, sorry, you can't run this thread until processor 3 is available."
Taken from Parallel Programming with .net Hanselminutes

Control State in GridView

Here's the list of properties that are saved into control state in GridView:
edit index, page index, selected index, sort expression, sort direction and data key names and values. So here even if you clear the ViewState these states still persist

Serializable is non-inherited

Even if a class inherits from a Serializable class is still not serializable. We need to explicitly specify [Serializable] for this class also. In other words Serializable is not inherited or can I say attributes are not inherited.

Issue with inline sql

Everybody knows that there is a performance overhead with in line sql statements.
There is yet another issue which is maintainability a DB guy changes some schema and he usually looks into all the DB Objects like SPs and functions but will never look into the .NET code. Everybody will come to know abut the issue only when the code breaks.

adv of Clone in .net

When u copy an object it actually copies the reference.
So if Obj A is copied by Obj B and say after sometime some values in Obj A changes then Obj B also changes.
If we clone its called “shallow copying” and the above issue will not occur.

Back Button and SessionSate

Usage of Go.History(-1) so when u click back button kills the session state of the page.
So it’s always worthwhile to load the page again using some means (like have a session state from the current page to the prev page and then loading the prev page afresh)

Tuesday, November 6, 2007

Cannot use SQLServer Destination when the SQLServer is not Local

Cannot use SQL Server as destination when the System does not have the DB Server locally.
In other words if we are trying to run SSIS remotely then use OLE DB as destination even if
The destination is SQL Server.

Thursday, October 18, 2007

Into a Dev Project

By divine grace I'vemoved to a Dev project in another location in US.
But I somehow dont like this S/W job.
ShouldI become a lecturer?

Wednesday, September 26, 2007

Into a Support Project

I’m in US and I’m into a Support Project. I was never told abt this project in offshore.
I am an ASP.NET developer and now I’m put in a support project which has nothing to do with .net.
I’m fighting hard with my managers but in vain, I may end up my next 6 months here L
Need to think what to make out of this opportunity (/threat)
I’ve to rethink what I really want in my life and have to have the action plan for that

Saturday, September 8, 2007

Get the previous page name:

if (Request.UrlReferrer != null)
{
string sPageName = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
Response.Write("sPageName"+sPageName); }

Properties and OOPS

Properties are used to make the object look more real to client and there is no performance overhead since JIT and IL optimizes it

How to check whether the coding is really oops oriented?
Check whether all the methods created in the class can exist as static, if yes then the coding is not in oops methodology.

Manipulate DataTable in a GridView

The Best way to manipulate an entry in DataTable which is made editable using GridView which implements sorting and paging is by adding a primary key(dummy) to the DataTable

GridVIew make Column Invisible

u mostly make a column invisible in GridView so that u can use it internally in ur code for other purpose like this:

but when u access it in C# the Text of this cell will be empty.
The Text can be accessed only when the Cell is Visible

To get around this problem make the cell as Visible = false in Row_Created event in C#
Even this does not work I get index out of bound exception
The way out is the following code:
listtaskGridView.DataSource = ListTaskDS;
listtaskGridView.DataBind();
listtaskGridView.Columns[0].Visible = false;
listtaskGridView.Columns[7].Visible = false; listtaskGridView.Columns[8].Visible = false;

GridView accessing Columns Issue

GridView Columns seems to be hopeless when u do DataBound
When u bind the DataSource the only way to access GridView is thru its row only
Also I don’t like the way Cells are behaving in Row
I cannot give ColumnName in the cell
i.e., e.Row.Cells["AssignedAdm"] will not work
u even don’t have the facility to lookup the cell’s header like
e.Rows.Cells[0].Caption or e.Rows.Cells[0].HeaderText
The only way to get around the problem is remembering the cell index. The other way out is to get the GridView’s 1st row and get the Cell.Text which is the header and remember the index.

Dynamic Controls in GridView

It seems Button Event is not getting fired when is generated dynamically in Grid
The Below Link has the details:
http://community.strongcoders.com/blogs/ryan/archive/2005/12/01/gridview-dynamic-button-frustrations.aspx

I faced similar issue as well and have to content with a Button in the aspx page to get around this problem
After sometime I understand the issue is u add anything dynamically to GridView’s Footer (or any other rows) after DataBound then u deem to loose it.

A heavy solution is available in the following url need to fully understand the code.http://www.codeproject.com/useritems/GridView_with_insert_line.asp

Change in strategy

My office has blocked BlogSpot and hence I'm unable to update regularly.
I've taken some notes in my work which I'm going to paste here.
Many of these posts will be abstract and would not be complete.
But anyway if I don't do this then I would not be able to record anything.
So the Strategy is changed now:
Log all the things which u wish to log (even if they are incoherent)

Thursday, July 26, 2007

Table Valued Split Function

During the initial phase of development of our project one of my colleague stumbled upon a table-valued Split function (from the net ofcource J )
I thoroughly enjoyed using this Split function throughout my SPs and functions.
Dynamic Query cannot be used in Functions and I’d a requirement to write a table valued function which has to parse a variable number of Items.
I got around the problem by using the Split function in it.
This is what I did:
Send the list of ItemIds as a comma separated string
Parse it using the Split function inside the Table Valued function.

The Split Function code goes like this:

CREATE FUNCTION [dbo].[Split](@List nvarchar(2000), @SplitOn
nvarchar(5))
RETURNS @RtnValue TABLE (Id INT
IDENTITY(1,1), Value NVARCHAR(100))
AS
BEGIN
WHILE (CHARINDEX(@SplitOn,@List)>0)
BEGIN
INSERT INTO @RtnValue
(value)
SELECT Value =
LTRIM(RTRIM(SUBSTRING(@List,1,CHARINDEX(@SplitOn,@List)-1)));

SET @List =
SUBSTRING(@List,CHARINDEX(@SplitOn,@List)+LEN(@SplitOn),LEN(@List));
END
INSERT INTO @RtnValue (Value) SELECT Value =
LTRIM(RTRIM(@List));

RETURN;
END


Courtesy: to the unknown Internet site that hosted it and to the unknown developer who created it.

Agreed that this function has limitation like you cannot parse a very big string since the Value column’s limit is 100.
But still this Split function is very useful!!

Tuesday, July 24, 2007

Grouping in Infragistics Excel

The below code shows how to group using Infragistics Excel

using System;
using System.Collections.Generic;
using System.Text;
using Infragistics.Excel;
namespace ConsoleApplication1{
class Program
{
static void Main(string[] args)
{
Workbook theWorkBook = new
Workbook();
Worksheet
theWorkSheet;
theWorkSheet =
theWorkBook.Worksheets.Add("Customers");
theWorkSheet.Rows[0].OutlineLevel =
0;
//the outline property is the key to Grouping
theWorkSheet.Rows[0].Cells[0].Value =
"hello";
theWorkSheet.Rows[1].OutlineLevel = 1;

theWorkSheet.Rows[1].Cells[0].Value =
"hello1";
theWorkSheet.Rows[2].OutlineLevel =
2;
theWorkSheet.Rows[2].Cells[0].Value =
"hello2";
theWorkSheet.Rows[2].Expanded =
false;
theWorkSheet.Rows[1].Expanded =
false;
BIFF8Writer.WriteWorkbookToFile(theWorkBook,
"C://file.xls");
}
}
}

Thursday, July 12, 2007

Excel Export for Multi-Header UltraGrid

This is in continuation of the Blog on Multi-Header implementation of UltraWebGrid.

If the UltraWebGrid has multi-header then UltraWebGridExcelExporter doesnot export the Grid properly. The only way to get around the problem is to create a custom method to write the Grid data in xls format.
One way of doing this is by using StringBuilder to create html table and then passing it as a response. The Column and Rowspacing can be achieved using RowSpan and ColumnSpan of Table Header

Friday, July 6, 2007

Multi header implementation in UltraWebGrid

Multi-Header Implementation is possible in Infragistic's UltraWeGrid.



So how to do it:
  1. Mostly if we are going for Multi column header then there should be some static Columns
  2. So first write the code to Bind the DataSet
  3. Use Initialize Layout Event to write the Static Columns and also to work on the Spanning of the columns.

Sample Code


public void UltraWebGrid1_InitializeLayout(object sender,
Infragistics.WebUI.UltraWebGrid.LayoutEventArgs e)
{
// Create Static UltraGrid Header
Infragistics.WebUI.UltraWebGrid.ColumnHeader ch = new
ColumnHeader(true);
// other Code
// .......
// Initilaize the Spans here
ch.RowLayoutColumnInfo.OriginY = 0;
ch.RowLayoutColumnInfo.OriginX = 0;
ch.RowLayoutColumnInfo.SpanX = 2;
ch.RowLayoutColumnInfo.SpanY = 1;
// other Codes
}



The Methods Span X, OriginX are self explanatory, but what is important is to visualize how the axis is getting created in UltraWebGrid. This is shown in the dig above.
One more thing to note is correct calculation of the Spans and Origins of each header is critical.
If you get it wrong then
  1. The Headers may be scrambled
  2. Some Headers may be lost

Note that no error Will be thrown on either of the case so write the Origin and Spanning of the columns carefully


The Story Behind
I was new to .net and Infragistics and one requirement came up to construct a Grid using Multi-Header. I know for sure that this will be possible using Infragistics but don't know how exactly to do it. I tried a lot of googling but in vain. Finally I got a Chinese web site which talked about this :)

That was a wake up call for me, I thought how many ppl would've searched for this implementation and would've suffered?

I decided then that I should write a Blog about this and other things which I know and assume many ppl do not know. May be a guy reading this implementation might think its silly to do it in the way i wrote and can come back with a better approach. Or may be I'm duplicating a thing which would've been already known to many ppl. If my consciousness says to share something then I will definitely share it.

Table Dependency Issue

SQL Server's inbuilt feature of finding the dependency for a Table seems to have an issue. If a SP has just an "Insert into Table1" then this SP (say SP1) will not be shown as a dependent to Table1!! If I just add "Select * from Table1" in the above SP then SP1 is getting showed as dependent to Table1!!!!!!!!!!So if we are going to use the "View Dependency" feature then we are gonna have some trouble. The best way to get around this problem is to use the following "Text" search query
SELECT OBJECT_NAME(id) FROM syscomments WHERE [text] LIKE '%Table1%' AND OBJECTPROPERTY(id, 'IsProcedure') = 1 GROUP BY OBJECT_NAME(id)

Preamble

I’m a software engineer with 3 years experience. I’ve been coding in .NET 2.0 and SQL Server 2005 for almost a year now. I use Infragistic’s NetAdvantage 6.2 to do most of the UI stuff in ASP.NET. Whenever I encounter some problem or don’t know how to do a piece of code I search the net for sample codes. There are times when I don’t get the answers and I have to toil a lot to fix the issues. I did some introspect and found out that I always consume things but never shared the info I know. So I decided to write this blog to share something I know on .NET, SQL Server and Infragistics. All the tips and code snippets I’m going to share are not really hi-fi stuff, but are a bit elusive.