Cannot catch exception for application

18 February 2007

Hi there, long time no update since i am very busy on my work. :)

Some days before, i meet a problem about catch exception in .NET . Let me show the sample coding 1st, then we discuss what’s the fuck….

     static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                Application.Run(new Form1());
            }
            catch (Exception e)
            {

                MessageBox.Show(“Error”);
            }
        }
    }

It’s a main method of window application. I want to catch any unhandle exception of the windows application. It’s worked when i run the problem in VS.NET IDE. However, when i run the executable file in bin, the exception cannot be captured. It prompt me a exception message box like a exception i haven’t handled. I am so strange why this happen since i have try and catch to handle all exception. I have no idea why this happen. Therefore, i search from google and MSDN forum. I found that if we need to capture the exception of throw at Application, you have to Listen the event of Application.ThreadException. Thus, i rewrite my code to listen the event. Although it works at executable of the application, it doesn’t work at IDE mode.

I have no idea why there is different behaviour between IDE mode and execuable file. However, i think it is so trouble for developer since it is hard to debug. =.=

If you have any idea or suggestions, please let me know. Thanks


How to create an local report for reporting service in .NET?

22 October 2006

In the last few weeks, i started to create reports for my current project. I decided to use the reporting service for my project. It is because it is very powerful than crystal report such as user real time sorting, collaspe and expand, etc..It is very flexible than crystal report.

Reporting Service Interactive Sorting

 ReportingService Expand/Collaspe 

However, it is a new things for me, and i had no idea how to create an report. I spent a lot of time to try it. At last, i have created my first version of reporting engine for reporting service.

OK! Let’s me introduce how to create an report in reporting service at VS.ENT. However, there is so much things. I will show the coding part 1st. Are you ready?!

DataSet dataset = new DataSet(“CustomerSet”);
SqlConnection connection = new SqlConnection(connectionString);

SqlCommand command = new SqlCommand(“Select Name, Age, Address From Customer”, connection);
SqlDataAdapter salesOrderAdapter = new SqlDataAdapter(command);
salesOrderAdapter.Fill(dataset, “CustomerTable”);

ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Name = dataSourceName;
reportDataSource.Value = dataset.Tables["CustomerTable"];

reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.LocalReport.ReportPath = reportPath;
reportViewer.LocalReport.DataSources.Add(reportDataSource);

reportViewer.RefreshReport();

Is It easy?However, one thing you have been care. It is that the datasource name must been same as the dataset name in the report. Otherewise, it will prompts you an error that the datasource does not exist.


Row Number Function In SQL Server Server 2005

18 October 2006

Did you want to add a row number column in a select result!? Did you think it is hard to do that!? Luckly, SQL Server 2005 has added a row number function that can help you paging records for your database application.

Let’s me show an example for you to learn more about it.

Example:

This shows the first 10 records in employee table which is order by the entry date

SELECT  Name, EntryFROM (select  row_number() over (order by EntryDate Asc) AS RowNo, Name, EntryDate FROM Employee) AS Employee WHERE  RowNo between 1 and 10

This shows the next 10 records in employee table which is order by the entry dateSELECT  Name, EntryFROM (select  row_number() over (order by EntryDate Asc) AS RowNo, Name, EntryDate FROM Employee) AS Employee WHERE  RowNo between 11 and 20


ClickOnce Installs fail, ADODB 7.0.3300 required?!

12 October 2006

Do you have experience of click once deployment? It is very painful tools for me since i found a new problem again. Let’s me state it out 1st.

The problem is when your application add “Report Viewer” for your prerequisite. You may got fail for installation when your client computer visit the deployment site and click the “Install” button. It will warns you that

Unable to install or run the application.   The application requies the assembly ADODB 7.0.3300 to be installed in the Global Assembly Cache (GAC) first.“.

Therefore, you never success to install the application to client if you checked the “Report Viewer” for a prerequisite of an application.

Is it a BUG ???

I think it is a bug because VS.NET falsely calculates that it needs the adodb.dll file. Therefore, it adds the adodb.dll file into the prerequisite list.

How to solve the problem??

OH!!!It is quite easy way to solve the problem. The steps will show in the following:

  1. Right click your “Windows Application” project and click the “Propertise”
  2. Go to the “Publish” Tag
  3. Click the “Application Files…” button.
  4. There should be a File Name “adodb.dll” and the publish status should be selected as “Prerequisite(Auto)”
  5. Change the public status to “Include”. (I suggest to select the include because I am not sure the report viewer requests it or not)

That’s all. You can publish your application, and success to install it to your clients.


Add own prerequisite to “ClickOnce” application

12 October 2006

To add our own prerequisite you need to have boot strapper package. Once created boot strapper package then it will automatically included into prerequisite list. To generate boot strapper can use “Bootstrapper Manifest Generator” tool. Follow the steps given below to add own boot strapper using “Bootstrapper Manifest Generator” tool.

1.      Download “Bootstrapper Manifest Generator” http://www.gotdotnet.com/workspaces/workspace.aspx?id=ddb4f08c-7d7c-4f44-a009-ea19fc812545

2.      Install “Bootstrapper Manifest Generator”.

3.      Open BMG (Bootstrapper Manifest Generator).

4.      Select FileàNew.

5.      Select “Package Manifest” and click on OK.

6.   Type project name and click on “Add Installer File” icon top left.

7.   Browse for file, you wish to add into prerequisite, as I added exe as prerequisite you can  choose as per your requirement.

8.      Click on Ok you will see following screen.

9.   Type display name and click on “Build” icon top left.

10.       Your prerequisite is been created, can see in prerequisite list.

11. All set select “Test” as prerequisite from above list and publish application.


“Find & Replace” Not Working???

12 October 2006

Today is a bad lucky day. Why? I got a problem of the “Find and Replace” in VS.NET IDE. Whatever i pressed the Ctrl+F or clicked the

“Edit>Find & Replace > Find”. It was no repsonse to me.

OH!! How comes?

I could use that function b4 but why couldn’t now?

I searched a lot of articles and Q&A. I find out one shit solution from MSDN.

The solution is that:

Run the “Visual Studio 2005 Command Prompt” and then type the command “devenv.exe /ResetSettings”

It works but i should tell you a worse things.

since it is used for reset your IDE setting, all of your customerise setting in your IDE will also be reset. SHIT!!!


Welcome to my Blog~!

12 October 2006

It is my first time to create a blog. I choice the programming topic for this because i want to share my programming experience to my friends. (Also, it is a good place for me to save those experience XD). I hope my experience is useful for those guys~!

I hope you will love here and enjoy here. I am welcome you to give any comments for me. If you have any questions or unclear place, you can also email to me. You don’t know my email? You can find it here :P .

 Thanks for your supports~!Enjoy your life.


Follow

Get every new post delivered to your Inbox.