Tuesday, June 30, 2009

Validation of viewstate MAC failed

Error : Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machinekey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Solution : Add this part to the web.config System.Web section:
<pages enableEventValidation="false" viewStateEncryptionMode ="Never" enableViewStateMac="false" />

Thursday, June 25, 2009

Fail loading Web Application Project

Error : I do not quite remember the exact error, encounter it long time ago, and just now, a friend asked about it again. The error contain the words ..... System.Runtime.InteropServices.COMException...

It is characterized by web application project not being loaded while opening a solution, while any other projects open well.

Solution : Check whether IIS is installed on the computer. Press window + Run, type "inetmgr" (without quotes). If IIS is installed on the computer, Internet Information Services window should appear. Otherwise, you should install IIS first, then try opening the solution again.

To install IIS, go to Start Menu -> Control Panel -> Add or remove programs -> Add or remove windows components -> Check Internet Information Services, then click details -> don't forget to check FrontPage 2000 Server Extensions (if not checked yet) -> Click Next. It will asks to insert windows installer CD.
Yes, the IIS is on the windows installer CD, so you have to own a windows installer CD.

Debug not working on VS 2003.Net

Problem : Debug is not working on Visual Studio.NET 2003. There are some problems with Visual Studio 2003. Yet, still using it in some projects. One common problem is that the debug is not attached to the process while run in debugging mode. Hence, the breakpoints set will not be hit. This is sometimes annoying, when errors occur, and we're looking for the source of error.

Solution : Just run the application as usual, using F5, then on VS, choose menu Debug -> Processes -> look for aspnet_wp.exe. If more than 1 version are used on the computer, there might be more than 1 aspnet_wp.exe listed on the processes.

Choose any (if more than one available) aspnet_wp.exe process, then click Attach. A dialog box will appear. The process detail will be prompted, e.g.
It should look more or less like this :
[3644] c:\windows\microsoft.net\framework\v1.1.4322\aspnet_wp.exe

Notice that if the text in blue is not in v1...., then you should have chosen the wrong aspnet_wp.exe process. Cancel, and choose another aspnet_wp.exe process.

If there are more than 2 versions of VS used in the computer, i.e. 2003, 2005, 2008, etc., there should be :
[3708] C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_wp.exe -> .net Framework 2, for VS 2005 and above

[3644] c:\windows\microsoft.net\framework\v1.1.4322\aspnet_wp.exe -> .Net Framework 1, for VS 2003 and prior

Then, check only the Check box which says : Common Language Runtime, then OK.

Thursday, June 18, 2009

Can not add service reference / web reference

Error : The components required to enumerate web references are not installed on this computer. Please re-install Visual studio.

This error pops up as a dialog box while trying to add service reference / web reference.

Solution : Press window + Run, then type "devenv /resetskippkgs"
(without quotes), then press Enter.

This command clears all options to skip loadings added to VS Packages.

Then, try adding the service reference / web reference again.


Error with web service

Error variations:
- No connection could be made because the target machine actively refused it.
- The request failed with HTTP status 404: Not Found

Solution : Check whether the URL for the web service is set properly.

This problem appears to be a debugging problem when web service is used for desktop application. Yet, it appears to be a deploying problem when the web service is used for web application.

Wednesday, June 17, 2009

Creating Simplified Duwamish from a scratch

This is a step by step on how to create an asp.net C# web application using simplified Duwamish framework. I call it simplified Duwamish framework, because it is not the real Duwamish. It is my own version. I like it better, after eliminating some parts of the Duwamish framework I rarely use.
FYI, sample for the Duwamish template is already provided when installing Visual Studio .Net 2003.
This is a picture which describes the plot of Duwamish framework.

Picture Source : http://madgeek.com/Articles/SOA/EN/SOA-Softly.html

For more information about Duwamish, refer to http://msdn.microsoft.com/en-us/library/aa288561(VS.71).aspx

For my Simplified Duwamish framework, I only use these projects:
- BusinessFacade (Class Library)
- DataAccess (Class Library)
- Common (Class Library)
- Control (Class Library) -> this project is not in Duwamish framework
- Web Application (ASP.NET Web Application)

1. Create a blank solution
Menu File -> New Project -> Visual C# -> Other Project Types -> Visual Studio Solutions -> Blank Solution, name the solution, and it will appear on the right side of the Solution Explorer.

2. Some things which should be known:
- Common -> does not depend on any other projects
- Control -> depends on Common
- DataAccess -> depends on Common
- BusinessFacade -> depends on Common and DataAccess
- Web Application -> depends on BusinessFacade, Common, and Control
Therefore, this would be the order used in creating projects in the solution.
To create a new project, right-click on the solution, choose Visual C#, then choose the project type.

3. Create Common Project
Add a new project of type Class Library, then name it Common. A class named Class1.cs will be automatically created. It can be renamed later.

4. Create Control Project
Add a new project of type Class Library, then name it Control. A class named Class1.cs will be automatically created. It can be renamed later.

5. Create DataAccess Project
Add a new project of type Class Library, then name it DataAccess. A class named Class1.cs will be automatically created. It can be renamed later.

6. Create BusinessFacade Project
Add a new project of type Class Library, then name it DataAccess. A class named Class1.cs will be automatically created. It can be renamed later.

7. Create Web Application Project
Add a new project of type ASP.Net Web Application, then name the web. A page named Default.aspx will be automatically created. This is usually set as the default page of the web.

8. Manage Project Dependencies
Manage project dependencies as explained in step 2. Right-click on the solution, then choose Project Dependencies.
- Common does not depend on any other projects, so we just skip this.
- Choose Control -> Check Common, since Control depends on Common.
- Choose DataAccess -> Check Common.
- Choose BusinessFacade -> Check DataAccess and Common.
- Choose Web Application -> Check BusinessFacace, Common, and Control.
Then, OK.

9. Adding Project References to the projects
To add references to the project, right-click on the project, choose tab Projects, then choose the project to be referenced.
- Control -> Add reference to Common.
- DataAccess -> Add reference to Common.
- BusinessFacade -> Add references to DataAccess and Common.
- Web Application -> Add references to BusinessFacade, Common, and Control.

10. Setting start-up project and start-up page
Right-click on the Web Application project, then Set as StartUp Project.
Right-click on the index page, then Set as Start Page (Default.aspx is usually set as start page).

11. Rebuild the Solution by right-clicking on the solution, then rebuild.

12. Running in debug mode may be necessary for the first time, after creating the application. Just press F5 to debug.

13. That’s all folks.

Tuesday, June 16, 2009

Logon failed on Crystal Report

Error : Logon failed. Details: ADO Error Code: 0x Source: Microsoft OLE DB Provider for SQL Server Description: Login failed for user 'UserXXX'. SQL State: 42000 Native Error: Error in File E:\TEMPSY~1\Tmp\temp_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}.rpt: Unable to connect: incorrect log on parameters.

Solution : Open the report, then Verify Database, using the login used while deploying!

This error takes me a lifetime to solve. It actually doesn't make sense to verify database for a report using the real login while deploying. That means all reports created while developing will have to be verified. The login info should be able to be set programmatically.

In my case, there are already some pages on the web that use similar reporting. I've printed the report using the same code, but no matter how I try, none works. I've tried a lot of ways to make it print, but all to no avail.

At last, I verify the report using the login used while deploying, then re-upload it. It works fine. phew -.-""""""

I set the login information for the report from web.config:

<!--<add key="ConnectionInfo" value="Database_name, server, user, password">-->
<add key="ConnectionInfo" value="DB1,, steven, steven"||/add>

Here's the .cs code I use for the report, and it should work fine, I guess.

private void BindConnectionInfo()
ConnectionInfo connectionInfo = new ConnectionInfo();
string conInfo = SystemConfiguration.ConnectionInfo; //get from web.config

connectionInfo.DatabaseName = conInfo.Split(',')[0].Trim();
connectionInfo.ServerName = conInfo.Split(',')[1].Trim();
connectionInfo.UserID = conInfo.Split(',')[2].Trim();
connectionInfo.Password = conInfo.Split(',')[3].Trim();

TableLogOnInfo t = new TableLogOnInfo();
t.ConnectionInfo = connectionInfo;

if (crystalViewer.LogOnInfo.Count == 0)
crystalViewer.EnableDatabaseLogonPrompt = false;
crystalViewer.EnableParameterPrompt = false;

protected void btnPrint_Click(object sender, EventArgs e)
litXXX.Text = "";

ReportDocument rd = new ReportDocument();

ParameterDiscreteValue value = new ParameterDiscreteValue();
value.Value = Period;
ParameterValues parameterValuesPriod = new ParameterValues();

value = new ParameterDiscreteValue();
value.Value = Convert.ToByte(Semester);
ParameterValues parameterValuesSem = new ParameterValues();

ParameterField parameterField = rd.ParameterFields[0];
parameterField.DefaultValues = parameterValuesPriod;
parameterField.CurrentValues = parameterValuesPriod;

parameterField = rd.ParameterFields[1];
parameterField.DefaultValues = parameterValuesSem;
parameterField.CurrentValues = parameterValuesSem;

crystalViewer.ReportSource = rd;

And here's the .aspx code:

script type="text/javascript">
function PrintPartsViewer()
var objWindow = window.open("about:blank", "print", "width=800, height=600, toolbar=no");
var strHtml = "<html>";
strHtml += "<head>";
strHtml += "</head>";
strHtml += "<body>";
var element = document.getElementById("divPrint");
strHtml += element.innerHTML;
strHtml += "</body>";
strHtml += "</html>";

<asp:literal id="litXXX" runat="server"></asp:literal>

<asp:button id="btnPrint" runat="server" text="Print Report" onclick="btnPrint_Click" />


Saturday, June 13, 2009

Appending ArrayList to another ArrayList

A friend of mine asked about how to append an ArrayList to another ArrayList in C#. I found out that it's an easy task as long as the type of the ArrayList is the same. Just have to typecast it to ICollection.

ArrayList a = new ArrayList();
a.Add("Array 1");
a.Add("Array 2");

ArrayList b = new ArrayList();
b.Add("Array 3");
b.Add("Array 4");


Tuesday, June 9, 2009

Open and close CD-ROM tray in VB

Create a module, and put this code in it:

Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal hwndCallback As Long)

To Open CD-ROM tray, use this method:

Sub OpenCDTray()
mciSendStringA "Set CDAudio Door Open", 0&, 0, 0
End Sub

To Close CD-ROM tray, use this method:

Sub CloseCDTray()
mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0
End Sub

Delete data by date

Sometimes, new Visual Basic developers may meet such problems as retrieving data by date. Just need to use # to make it right

db.Execute "DELETE FROM table_name WHERE FieldDate < #" & Format(Date, "yyyy/mm/dd") & "#"

Tuesday, June 2, 2009

Data on report won't change

Problem : If you're using crystal report to design a report and the data displayed on the report won't change.

Solution : Go check the report. Open it, then make sure that on menu File -> Save Data With Report -> is NOT checked.

This is actually a minor problem, but sometimes, people forget or don't notice it.

Invalid Handle in Crystal Report

Error : Invalid Handle
An error dialog box which says "Invalid Handle" shows while saving crystal report document.

Solution : The solution may vary in this case. Sometimes, there isn't even any mistake with the report.
1. Search for crw32.exe on the computer, in accordance with the version of Crystal Report being used, right-click the file -> properties -> go to tab Compatibility -> check Run this program in compatibility mode for, and choose Windows 2000.
2. Check whether all data and connections are correct (be meticulous), i.e. stored procedures, tables, etc.
3. If everything seems fine, just try closing the crystal report, then opening it again.
4. If the error still occurs, try restarting the computer.
5. Last, if none of the points above works, go to point 2 ^^

NB : Try saving first, doing a little updates on the report, because if you've done a lot of revisions, then this error appears when you try saving it, all your works will be futile.


Related Posts

Dual Axis not Working in Tableau

Problem : When creating chart with Dual Axis, Synchronize Axis is disabled and cannot be clicked. Cause : Tableau identified this as ...

About Me

My photo
Is an ordinary unNoticed man, with a little knowledge to share and high dreams to achieve. I'd be glad if I can help others, 'coz the only thing for the triumph of evil is for a good man to do nothing. I like English and Chinese language, and know a little about them. Hence, for me, most things can best be expressed in Chinese, some in English, and the rest in others ^^

About Blog

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Popular Posts



Follow by Email