break
Oct 27

In my quest to deploy an application to a Windows 2003 Server, I got another error:

“Access is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET write access to a file, right-click the file in Explorer, choose “Properties” and select the Security tab. Click “Add” to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.”

That description is really nice, but it didn’t solve the problem. Not even close. You need to go to the Event Viewer, System, and in there I found a DCOM error that said:

“The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID
{361146D5-C2AC-30BE-841C-385F740A88FC}
to the user MLIDDOMAIN1\user SID (S-1-5-21-7223768-1134175843-1648912389-106998). This security permission can be modified using the Component Services administrative tool.”
. In reality, this is the error you are dealing with.

Solution:

Go to start -> run and then type “regedit”. In the registry editor go to edit and search for: “361146D5-C2AC-30BE-841C-385F740A88FC” (in my scenario). You should find that string and a “value data” (in my case sqlHelper). When you find the value data, look for that component in the Component Services. To get to the component services, go to start -> run and then type “dcomcnfg”.

In the component services, expand component services -> computers -> my computer -> com+ applications. In my case the component sqlHelper was here. I did a right click -> properties. In the security tab “UNCHECK” where it says “Enforce access checks for this application”.

The error should be gone!!!

Oct 27

I was deploying an application in a Windows 2003 Server and got the following error:

“The page cannot be found. HTTP Error 404 – File or directory not found.
Internet Information Services (IIS)”

I went to IIS, and looked for the “Web Service Extensions” section. I made sure the following is allowed:

  • Active Server Pages
  • ASP.NET v1.1.4322

In my case it was in a “prohibited” status. After it was in an “allowed” status, this error went away.

Jun 7

I have seen this problem in the following scenario: You type some input in a textbox, you hit enter and when you are expecting the retrieve/submit button (based on the wording you are using) to return a result set, instead you get this pop-up:

If this is your scenario, I have a recommendation for you: Use an asp.net panel, and assign a DefaultButton to your panel ( usually the name of your retrieve/submit button )
For example:
<asp:panel id="Panel1" runat="server" defaultbutton="btnRetrieve">
If you have a different solution, with a different scenario, let me know.

Jan 13

Is debugging becoming a slow process? Lately, the first time I try to debug an ASP.NET project, it doesn’t start debugging smoothly. After 3 or 4 minutes I receive the following message:

“Unable to start debugging on the web server. The web server did not respond in a timely manner. This may be because another debugger is already attached to the web server”.

This problem may have many solutions. I fixed this problem by removing all my breakpoints from the project. There are 2 ways of doing this:

1- Press “Ctrl + Shift + F9″

2- On the menu bar press “Debug” then select “Delete All Breakpoints”

If you find another way to solve this let me know.

Feb 23

I was trying to return a String with the XML necessary to construct an Excel File. I was using a StringBuilder, and as soon as I declared a table inside the worksheet

For example
sb.Append(“<ss:table>”);

I got the following error:
XML PARSE ERROR: Missing end-tag
Error occurs at or below this element stack:
<ss:workbook>

How Did i fix it?
sb.AppendLine(“ss:table>”); instead of sb.Append(“<ss:table>”);

If you find another fix let me know.

Aug 18

If you run the code below you will notice the following behavior:

For some reason when I press a button and the button puts an error text in my cell (because of an error validation) when I go back to the cell, it selects all the text in the datagridviewcell and if you press a number you are going to be able to watch two behaviors:

1- The Datagridviewcell adds itself:
This was happening in my real world application.
For example, if I have a number like 1111.000 (let’s say this sends a validation error), if you go back to the cell and press “1″ you will see something like
1111.001
If you press “5″ you will see something like
1111.002
If you keep pressing numbers you will see that you will be adding your current number.

2- The Datagridviewcell will only let you put one number at a time.
This is what happens in the code below. If you press 1111.000 and you go back to the cell and press “1″ you will see something like
1.000

If you press “2″ instead of being 12.000 or 1.002 you will see
2.000

It will only let you put one number at a time.

Here’s the code for this scenario


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace DataGridViewBugBlog
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
InitializeGridColumns();
FormatDataGridColumn(dataGridView1, "Price", typeof(double), null);
}
private void InitializeGridColumns()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.Tables.AddRange(new System.Data.DataTable[] {dt});
// Adding columns to the DataTable
dt.Columns.Add("Quantity", typeof(double));
dt.Columns.Add("Price", typeof(double));
dataGridView1.DataSource = ds.Tables[0].DefaultView;
// Setting the width of both columns
foreach (DataGridViewColumn col in dataGridView1.Columns)
col.Width = 95;
}
private void button1_Click(object sender, EventArgs e)
{
showConfirmation();
}
///

/// If the price or quantity doesn't have a correct
/// format it will send a messagebox.
///

private void showConfirmation()
{
bool error = false;
foreach (DataGridViewRow mRow in this.dataGridView1.Rows)
if (!ValidateData(mRow))
error = true;
if (error)
MessageBox.Show("Invalid quantity or price, please check and reenter", "Errors", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
///

/// The valid format for the price
/// is 000,0000
///

private bool ValidateData(DataGridViewRow mRow)
{
bool ok = true;
string txtPrice = "Price";
//quantity format
if (!Regex.IsMatch(mRow.Cells[txtPrice].FormattedValue.
ToString(), @"(?!^0*$)(?!^0*\.0*$)^\d{1,3}(\.\d{1,4})?$"))
mRow.Cells[txtPrice].ErrorText = "Please enter a valid numeric format. Ex (000,0000) ";
ok = false;
return ok;
}
///

/// This event handler manually raises the CellValueChanged event
/// by calling the CommitEdit method. The event CellValueChanged
/// was used to handle DataGridViewCheckBoxCell logic.
///

private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.IsCurrentCellDirty && dataGridView1.CurrentCell.ColumnIndex >= dataGridView1.Columns["Price"].Index)
dataGridView1.
CommitEdit(DataGridViewDataErrorContexts.Commit);
}
internal static void FormatDataGridColumn(DataGridView dataGrid, string col, Type type,
string format)
{
DataGridViewColumn column = dataGrid.Columns[col];
if (type == typeof(Double))
column.DefaultCellStyle.Format = format == null ? "##0.0000" : format;
}
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
{
dataGridView1.EditMode = DataGridViewEditMode.EditOnEnter;
}
}
}

This only an excerpt of my code. The interesting part about this, is that what causes this error is the CurrentCellDirtyStateChanged event. I had this event because inside of it i had a CommitEdit method that raises the CellValueChanged event in which I was changing the values of some DataGridViewCheckBoxCell.

The solution:
Make sure in the CurrentCellDirtyStateChanged the CommitEdit is only made when you are in a DataGridViewCheckBoxCell. For the code above just comment the CommitEdit method and it will work like it should.

Jun 6

I was building a Windows Presentation Foundation browser application, and somewhere in my code I was trying to open a SqlConnection, and the error appeared.

“Request for the permission of type ‘System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.”

I had this annoying bug, which at the end it wasn’t that bad to solve.

The solution:

If you do a right click in the properties of your solution, and you go to security, click on “This is a full trust application”. This should solve this problem.

I would also like to thank Animesh for his input in this topic. He had another solution to it, and according to him “There was a change needed in web.config. Increased the trust level to full for security policies and it worked”.

If you have another way to solve this problem, please comment it, and let me know.

May 21

I was trying to convert an object to a long in C# and tried it like this at first:

value = row.Cells[columnIndex].Tag as long;

I got the following error:

“The as operator must be used with a reference type (‘long’ is a value type)”

The Solution

value = Convert.ToInt64(row.Cells[args.ColumnIndex].Tag);

Using Convert.ToInt64 will let you convert an object to a long.