Wednesday, February 28, 2007

The ASP.NET process identity does not have read permissions to the global assembly cache.

I am trying to run the default website installed by the, but it keeps giving me this error until I reinstalled the on my development box.

The step I follow is :

  1. Open a command prompt
  2. Stop IIS: iisreset /stop
  3. Change to the .NET Framework 2.0 root directory: C:\winnt\Microsoft.Net\Framework\v2.0.50727\
  4. Reinstall ASP.NET 2.0 by using the following command: aspnet_regiis -i command.
  5. Start IIS again after it has been run: iisreset /start

"Timeout expired" error message when the sql debugging is on.

Following yesterday's post, now, I am able to debug into the stored procedure from my windows application or web application. But after a couple of times, I start to receive annoying "Timeout expired" error message when the program tries to open a connection to the server.

Finally, I have to find another KB830118,  and the status of this issue is "This behavior is by design".  I am start to doubt if "step into stored procedure" will cause the web site hanging in debug session, what is the real use of it.

Interesting..., maybe all those KBs are existing to address those stupid bugs.

Tuesday, February 27, 2007

Magic EXEC SP_SDIDEBUG 'legacy_on'

In my previous job, I don't have to do too many stored procedures and those stored procedures are generally simple. The project I am working on right now involves a lot of stored procedures, and I need a good way to debug it. It's pretty easy if I am working in visual studio 2005 and SQL server 2005. Everything works right out of box.

But when I started to use visual studio 2003 to debug a stored procedure on SQL server 2005, it complained that the sp_sdidebug cannot be found. It's true, this particular debug procedure is not in the "Extended Stored Procedures" of the master database of the SQL server 2005, but it is in the master database of the SQL server 2000.

So, I moved the database to the SQL server 2000. It's getting much better, it can allow me to debug into the stored procedure from the server explorer.  It at least proved that the SQL debugger is working. But every time, when I tried to debug into the stored procedure from the code, it never stepped into the code.

I searched a lot of posts, and a lot of posts pointing to this KB328151. I tried this magic statement EXEC SP_SDIDEBUG 'legacy_on'  , no , it didn't work. I rebooted the server machine, tried this statement again, it seemed it worked finally. 

In the KB, it mentioned it's only an issue of SQL server sp3, actually, my SQL server is sp4 , and it still applys.

Monday, February 26, 2007

Visual studio 2005 Class Designer

I am not a big fan of UML, or any diagram in the development process.  The biggest issue I found is the inconsistency between those nice diagrams and the actual codes.  I just found it's too difficult to think over every possible situations at the beginning stage of the project, not just the developers. The clients also have the same issue, they are not very clear what they want too at the beginning. I find out unless you are a real guru in making those nice diagrams, and you can always make changes to those diagrams very fast ( I am NOT), it's so hard to keep those diagrams consistent with your code when the project requirements change.


The visual studio class design is a different story. The changes you made to the designer can be applied to the code instantly, on the other hand, the changes you made to the code can be applied to the designer instantly too. You don't have to worry about two pieces any more, you can just worry about one piece.


There is a power toy for the enhancement here too.

Thursday, February 22, 2007

Scrollable DataGrid with Sorting - ExtremeExperts

Scrollable DataGrid with Sorting - ExtremeExperts

I am working on a project which uses a lot of datagrid, and yes, it's still based on .Net 1.1 framework. The annoying issue is the scrolling, all the headers are scrolled with the grid when the datagrid is scrolled. Asp.Net renders all the datagrid to one table, and it's not surprising that the header will be scrolled.

I found a solution here, but the issue is the aligning of the columns between the header tables and the content tables rendered by the grid.

I ends up writing some javascript code.

function AdjustTable(firstTableId, secondTableId)
var firstTable = document.getElementById(firstTableId);
var secondTable = document.getElementById(secondTableId);
if(firstTable!=null && secondTable!=null)
var firstTableRows = firstTable.getElementsByTagName("tr");
var secondTableRows=secondTable.getElementsByTagName("tr");
if(firstTableRows!=null && secondTableRows!=null)
if(firstTableRows.length>0 && secondTableRows.length>0)
for(i = 0; i < secondTableRows[0].cells.length; i++)
}//if(firstTable!=null && secondTable!=null)

This will loop through all the table cells in the first row for the second table, and set the width to be the same with the table cells in the first row of the first table.

Tuesday, February 20, 2007

SQL Server 2005 Compact Edition and SQL Server 2005 Express Edition

I have been using the Express Edition for a while, but are not aware the difference between the compact edition and the express edition. Here is a white paper.

Monday, February 12, 2007

Design time rendering and run time rendering.

I was doing some work on the GMap.Control over the weekend. On thing I found is that whenever I drop the control on the form, it always gives me an error on rendering, error to create control, error to render a control.

The problem is , when the visual studio render a control on the form, it will look for the DesignerAttribute, if it's not available, it will look for the default ControlDesigner. The ControlDesigner has a default method called GetDesignTimeHtml() , It will render the view on the form.

Use the reflector, here is what GetDesignTimeHtml() will do by default:

public virtual string GetDesignTimeHtml()
StringWriter writer1 = new StringWriter(CultureInfo.InvariantCulture);
DesignTimeHtmlTextWriter writer2 = new DesignTimeHtmlTextWriter(writer1);
string text1 = null;
bool flag1 = false;
bool flag2 = true;
Control control1 = null;
control1 = this.ViewControl;
flag2 = control1.Visible;
if (!flag2)
control1.Visible = true;
flag1 = !this.UsePreviewControl;
text1 = writer1.ToString();
catch (Exception exception1)
text1 = this.GetErrorDesignTimeHtml(exception1);
if (flag1)
control1.Visible = flag2;
if ((text1 != null) && (text1.Length != 0))
return text1;
return this.GetEmptyDesignTimeHtml();
Actaully, at the design time, a lot of objects are not initialized properly, so it will cause an exception.
So, I made an easy approach, I override the GetDesignTimeHtml() method to let it simply draw a string. Of course, there are a lot of more interesting stuff you can do here.

public override string GetDesignTimeHtml()
StringBuilder sb
= new System.Text.StringBuilder();
"GMap2 Server Control");
return sb.ToString();
catch (Exception ex)
return GetErrorDesignTimeHtml(ex);

It at lease won't give me any error anymore.

Sunday, February 11, 2007

DataReader vs DataSet

A very good article about Data Access in .Net

Enterprise .NET Community: Designing Performance - Optimized ADO.NET Applications

This is also a question I was asked in an interview..

Choosing Between a DataSet and a DataReader

A critical choice when designing your application is whether to use a DataSet or a DataReader to retrieve data. If you need to retrieve many records rapidly, use a DataReader. The DataReader object is fast, returning a fire hose of read-only data from the server, one record at a time. In addition, retrieving results with a DataReader requires significantly less memory than a creating a DataSet. The DataReader does not allow random fetching, nor does it allow for updating the data. However, .NET data providers optimize their DataReaders for efficiently fetching large amounts of data.

In contrast, the DataSet object is a cache of disconnected data stored in memory on the client. In effect, it is a small database in itself. Because the DataSet contains all of the data that has been retrieved, you have more options in the way you can process the data. You can randomly choose records from within the DataSet and update/insert/delete records at will. You can also manipulate relational data as XML. This flexibility provides impressive functionality for any application, but comes with a high cost in memory consumption. In addition to keeping the entire result set in memory, the DataSet maintains both the original and the changed data, which leads to even higher memory usage. Do not use DataSets with very large result sets as the scalability of the application will be drastically reduced.

Friday, February 02, 2007

Good way to transfer database.

I have been looking for a method which can easily transfer my database on the local machine to the hosting server. I don't have the enterprise manager, the express management studio seems not support this functionality. I have been trying to write some scripts using smo, but was not very successful. Finally, I found this SQL Server Hosting Toolkit, and it's very useful.

1> Connect to your local database, and script the database into an SQL file.

2> Connect to the remote database, and open and SQL query window, then copy all the scripts into the SQL query window. Run the scripts, it will generate all the objects and data into the remote database.