Friday, April 24, 2009

Can't debug on IE

Error : I forget about the error messages. If I'm not mistaken, the error message was just as common. As far as I remember, it sounds like this :

Unable to Start Debugging on the Web Server... user is not a member of "debugger users"

Solution : Run Internet Explorer (it should be more or less the same in other browsers), choose menu Tools -> Internet Options -> Security tab -> Choose Local Internet -> click Sites button -> click Advanced -> add http://localhost to the zone, then ok.

ASP.NET State Service

Error :
Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the
value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Param
eters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either 'localhost' or '' as the server name.

This is also one of the mostly retrieved errors. This error occurs when using StateServer mode for the sessionState in web.config, yet the ASP.NET State Service is not started.
I met this error when I first made a web application. After I get the solution, I ask a little about about StateServer sessionState mode to a senior.

When making an application with login page, u can consider using StateServer for the sessionState mode, because when u use this mode, u don't have to login again and again, just have to refresh the web page, because the session is still kept on server. Yet, when deploying the application, should omit it, or change it to InProc mode. I used only these 2 modes. Never use the SQLServer mode.

<sessionState mode="StateServer" stateconnectionstring="tcpip=" sqlconnectionstring="data source=;Trusted_Connection=yes" cookieless="false" timeout="200000" />

Start the ASP.NET State Service on Services. Go to control panel -> Administrative Tools -> Services, or simply press window + Run, then type services.msc. Choose ASP.NET State Service, right-click, then Start the service. To start it automatically, choose startup type : Automatic.

Crystal Report error while deploying

Error : Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its
dependencies. The system cannot find the file specified.

Solution : Install crystal report runtime available in Visual Studio CD, on the server.

Error on connection string

Error : An error has occurred while establishing a connection to the server.
When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Solution : Check if the connection string is properly defined.

Error on event validation

Error :
Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Solution : If there is a part of the code where repeater is used, DO NOT bind data on pageload (ispostback) section.

Also cannot debug application

Error : Error while trying to run project: unable to start debugging on the web server. the project is not configured to be debugged.

This is the most widely retrieved error while developing web applications... Hahaha... And the solutions may vary greatly. This solution works in my case.

Solution : re-register aspnet to IIS. Go to start menu -> Programs -> Microsoft Visual Studio xxxx -> Visual Studio Tools -> Visual Studio xxxx Command Prompt -> type aspnet_regiis -r.

I was using 3 version of VS.Net, i.e. version 2003, 2005, and 2008. This maybe the reason of this error in some way.

Cannot debug application

Error : Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.

Solution : Check the start-up project. Make sure the start-up project is the web application, not a class library project.

Error while building on release mode

Error : "LC.exe" exited with code -1073741701

I was building a pre-compiled web in release mode (using WebDeployment program). As known, compiling in release mode always retrieves undiscovered errors -.-"""

Solution : Exclude licenses.licx file from project, then rebuild again.

There was a time when I faced the same problem, after my computer was attacked by a virus that caused the executable files became corrupted. In this case, just ask for a copy of LC.exe file from a friend and place it on the folder where LC.exe is located on the computer.

Parser Error

Error :
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'Web.MasterPages.GeneralTemplate'.

Source Error:
Line 1: <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="GeneralTemplate.Master.cs"
Line 2: Inherits="Web.MasterPages.GeneralTemplate" %>
Line 3: Source File: /Web/MasterPages/GeneralTemplate.Master

Version Information: Microsoft .NET Framework Version:2.0.50727.3053;

ASP.NET Version:2.0.50727.3053

Solution : Yet another weird error, I deleted the bin folder on the web application, then rebuilt the solution, and it just worked!

Ambiguous match found

Error :
Server Error in '/Web' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Ambiguous match found.

Source Error:

Line 1: <%@ Control Language="c#" AutoEventWireup="false"
Codebehind="GeneralTemplate.ascx.cs" Inherits="Web.Service.MasterPages.GeneralTemplate"

Line 2: <%@ Register TagPrefix="uc1" TagName="MainMenu" Src="../UserControls/MainMenu.ascx" %>
Line 3: <%@ Register TagPrefix="Web" Namespace="Web.Web.Controls" Assembly="BLMS.BackEnd.Web.Controls" %>

Source File: /Web/MasterPages/GeneralTemplate.ascx Line: 1

This is actually a weird error, I've faced a lot of problems while deploying and debugging web application developed under, and these errors are sometimes not quite relevant to the error messages, so have to figure it out by myself. Phew...

Solution : Made a new web directory on IIS outside the default website, for the web application. And it worked like charm!! -.-"""

Error when using ajax component

Error : The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Solution : Put all the tags on the body, not on the head.

Error connecting to undo manager of source file

Error : Error connecting to undo manager of source file.
This error occur when debugging a web application on

Solution :
1. Delete the aspx.designer.cs file
2. Right-click the aspx, select convert to web application.

There are 3 layers (that's how I call it) on web application, i.e. Design layer(.aspx), Coding layer(.cs), and the other one is the layer that contains all the Components used in Design layer(.aspx.designer.cs).

I code more than dragging elements to the page while working on the design of a web page. Sometimes, the Components layer doesn't synchronize well with the design layer, so some elements used in the design layer are not created properly. Deleting the .aspx.designer.cs and converting to web application will create a new file, thus all the elements will be created more properly.

Username & Password requested when downloading

Problem : When downloading a file, username and password is requested.

Solution : If I'm not mistaken, I used impersonation on the web, so have to grant permission on the IIS. Go to control panel -> Administrative Tools -> Internet Information Services. Or simply press window + Run, then type inetmgr.

Right-click Default Web Site, properties, go to Home Directory tab, push button Connect as -> dialog box to fill username and password will be prompted, fill with the user used for impersonation.

Can't access local web aplication from another computer

Error : No error, it's just that local web application can not be accessed from another computer.

Solution : go to control panel -> windows firewall -> add port :
Name : HTTP
Port Number : 80
Type : TCP

Accessing web from local : http://localhost/webName/Default.aspx
When accessing from another computer, just use the ip address of the computer where the web is located, i.e. http://ip_address/webName/Default.aspx.

Error displaying report

Error : C:\DOCUME~1\STEVEN~1\ASPNET\LOCALS~1\Temp\temp_c31eb8a4-2e63-4b42-b43d-c91550cca5b4 {25A8AD89-FCF3-4B82-A544-375DE1838F98}.rpt: Unable to connect: incorrect log on parameters

This problem is quite typical, and happen under some typical conditions. I was using crystal report to view a report on a web page, and the connection used for the report is ODBC. I had made the ODBC on User DSN tab, yet the error still occurred. Have to create ODBC on System DSN.

Solution : Add ODBC to System DSN (on the server where the application is located), and make sure the connection in the application is using valid username & password.

Assemblies / DLL not included

Error : One or more Assemblies / DLL have not been included...
I forgot the exact error message, but it should include those words. This error is caused by the unavailability of one or more DLLs when deploying.

Solution : Some DLLs, that are imported components, are usually not copied to deployment folder. To make them copied when creating deployment project, we have to change the property of the DLL.

Goto References folder of the application, then select the DLL, right-click, choose copy local = true. Then rebuild the project, the DLLs will be automatically copied to the deployment folder.

File has not been pre-compiled

Error : The file '/Web/Default.aspx' has not been pre-compiled, and cannot be requested.

I used WebDeployment program to compile the web on release mode.

Solution : Re-copy the compiled files. This problem usually occurs when deploying pre-compiled web. Maybe missed some files while copying the files. Try re-copy the compiled files.

Wednesday, April 22, 2009

Error when creating deployment project

Error : The target directory could not be deleted. Please delete it manually, or choose a different target.

Solution : Delete publish folder (the folder where the published web is located), then try compiling in release mode again.

Problem with server / Web Service

Error : No connection could be made because the target machine actively refused it

Solution : If you use web service or get data from a server, check whether the web service is working properly, or the connection to the server is available.

Friday, April 17, 2009

Check whether a file exists or not

This is actually a simple code, but someones may not know it when first using VB, so I post it here.
Here's the code to find a file named file.txt:
If Dir(App.Path & "\file.txt") <> "" Then
MsgBox "Found: file.txt"
End If

How to detect running program

Make a module and use the functionality of API to make it work.

Code in the module:
Option Explicit
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long

Private Declare Function EnumWindows Lib "user32.dll" _
(ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long

Private Target As String
Private IsOpen As Boolean

Private Function EnumCallback(ByVal app_hWnd As Long, ByVal param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long
Dim hWndREC As Long
length = GetWindowText(app_hWnd, buf, Len(buf))
title = Left$(buf, length)
If InStr(1, title, Target, vbTextCompare) Then
IsOpen = True
End If
EnumCallback = 1
End Function

Public Function WindowOpen(app_name As String) As Boolean
'app_name is the name of the application when tracked on Windows Task Manager
IsOpen = False
Target = app_name
EnumWindows AddressOf EnumCallback, 0
If IsOpen Then WindowOpen = True
End Function

To check whether a program is running, e.g. Notepad:

If WindowOpen("Notepad") Then
MsgBox "Notepad is opened"
MsgBox "Notepad is not opened"
End If


How to clear all textboxes in a form

Sometimes, when we use a lot of textboxes in a form, and want to clean all the textboxes the form, it's not efficient to clean it one by one by using Text1.Text = "", Text2.Text = "", etc.
There is a short way to do it:
Dim a As Control
For Each a In Form1
If TypeOf a Is TextBox Then
a.Text = ""
End If

Wednesday, April 15, 2009

Get file name from a path in VB

One of my friend once asked how to get file name from a path. There're actually a lot of ways to do it. I'll try a simple one, using Split and UBound function.

e.g. the path is C:\Test\DeeperPath\EvenDeeperPath\Test.txt
and we're going to get the file name, i.e. Text.txt

The name of the controls:
textbox : Text1, containing the path

Some things we have to know:
1. To split the path into array: Split(Text1.Text, "\")
We'll get array of string:
Split(Text1.Text, "\")(0) = C:
Split(Text1.Text, "\")(1) = Test
Split(Text1.Text, "\")(2) = DeeperPath
Split(Text1.Text, "\")(3) = EvenDeeperPath
Split(Text1.Text, "\")(4) = Test.txt

2. To get upper bound of an array: UBound(array)

So, to get the file name from a path, we just need a line of code:
Split(Text1.Text, "\")(UBound(Split(Text1.Text, "\")))

The result will be: Test.txt

Connecting Crystal Report and VB using TTX

I'd like to share how to make a report using Crystal Report, and connect it from VB here, since there has been several friends asking about this.
There are actually several ways to connect VB and Crystal Report, ones of which that I've ever used are using TTX and ODBC.

I'd like to share the usage of TTX here. I use Crystal Report 8.5, but it's more or less the same as the other versions.

Like it's data source type - Field Definition Only - implies, it makes a .ttx file to define the fields used in the report. Thus, when creating a report, we have to make a .ttx file that contains all the fields and type of the fields used in the report.

The advantages of this method are:
1. Flexible, we don't have to change the report if there is any changes on the logic while retrieving the data.

2. We only have to define the data type, that's all, and do the code in the application.

These are the steps need to be done for the report:
1. Run Crystal Report, choose Create a New Crystal Report Document [As a Blank Report].

2. Choose the type of the data source: Field Definition Only.
Data Source: Field Definition Only

3. It will ask to browse for a text file or make a new file, I'll make a new one.
Just insert the Field Name and the Field Type to be used in the report. Make sure the field name and the field type is correct. Add all fields used. When finished, click the close icon of the form. It will ask to save the file, then click OK.

4. Click Add to add the .ttx file to the report, then click Close.

Add TTX to report

5. Start designing the report by inserting the fields used in the report then save it.

I use the table [Customers] from the Northwind database.
I'll try to print Customers data by Country.
PS: I use ADODB for the database connection.

These are the steps in the VB:
1. Add Crystal Report component to the application by pressing ctrl+T or go to menu Projects -> Components. On the Controls tab, check [Crystal Report Control], then press ok. A crystal report component will be added to the toolbox window.

2. Drag the component to the form.

Crystal Report Component

3. The small programs will look like this.

Application View

4. Here's the code on the print button event:
The name of the Controls:
combo : cmbCountry
command button : cmdPrint

Private Sub cmdPrint_Click()
With CrystalReport1
Dim sql As String
sql = "select CustomerID, CompanyName, ContactName, ContactTitle, " & _
"Address from Customers where Country = '" & cmbCountry.Text & "'"
Set rs = con.Execute(sql)

.ReportFileName = App.Path & "/RptTest.rpt"
.Destination = crptToWindow
.SetTablePrivateData 0, 3, rs
.WindowState = crptMaximized
.WindowShowPrintBtn = True
.Action = 1
End With
End Sub

5. And the report looks like this.

Report View

That's all folks.



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