
hugobooze
Avatar/Signature-
Posts
26 -
Joined
-
Last visited
Personal Information
-
Visual Studio .NET Version
Visual Basic .NET
-
.NET Preferred Language
VB.NET
hugobooze's Achievements
Newbie (1/14)
0
Reputation
-
Almost worked... Well, my solution worked when I run the exe-file on my, or another computer with Visual Studio installed. But when I ran it on a computer with only the framework installed, the same error occurrs. Mabye the jit-debugger isn't installed when the framework is installed. I found some information about this bug. It's a bug known by Microsoft: http://support.microsoft.com/?kbid=836674 (describes the WorkAround that I described earlier in this thread) Joe Mamma: If you have another solution, please help me out!
-
I solved it! I solved the problem! Now the exceptions is catched even if i run the exe file. Solution:I created a textfile in the bin-folder, named testShowDialogInTryBlock.exe.config (the exe file's name was testShowDialogInTryBlock.exe). In the config file i put the text: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> Then I had to compile the application in debug-mode! I was close before, but I must have made some mistake, so it didn't work then. But now I tested again, and now it worked! I think I can add this config-file in the project too. Have to test that, but in every case: Now it works! Thank you all for your help!
-
techmanbd: Well, in that thread you linked, you replaced try-catch with thread.abort. But in my case, i have to use try-catch, because I want to catch all unexpected errors. (in that case I have to add try-catch to every single function) Joe Mamma: You use .show, I have to use .showdialog, otherwise the program pointer passes through the try-catch statement when mybase.load is ready. In that case, I can't catch errors caused by exceptions when pressing buttons i the opened form. Mabye I'm on the wrong track. What I really want to do, is to encapsulate almost my whole program in the same try-block, to catch all unexpected errors. Is there any way to do that? The code: try myMainForm.showDialog catch .. works in visual studio, but the errors isn't catched when I run the exe file.
-
Well I have to admit I use Framework 1.0 (and Microsoft Development Environment 2002, version 7.0.9466) Mabye this is a bug solved in Framework 1.1. I will try to get Framework 1.1. I'll be Back! Thanks for all your help!
-
That's weird indeed! I attach small test solution where I test showdialog as your example show (testShowDialogInTryBlock.zip) If you run the solution in visual studio, the msgbox "Catched" appears, but if you run the exe file in the bin-folder, the dialog with the answers details/continue/quit appears. Or mabye you should send me your test code testShowDialogInTryBlock.zip
-
Mabye you want to know why I want to catch exceptions like this: This try-catch statement catches almost all exceptions that can appear in my program. If an exception is thrown, I the program catch the exception and mails a error description to my email address. The user also have a chance to comment what he/she did when the error happened. As soon as i get the email, i can fix the bug real quick, and deliver a bug-free version.
-
Seem to be a hopeless case... JABE: Yes, of course I can move code from frmChooseObject_Load to the constructor, but that doesn't help if the exception is thrown from another sub/function in frmChooseObject. For example btn_SearchObject_click, mnu_getObjectInfo_click, txt_description_leave... I want all this code to be handled by the try-catch statement. If an exception is thrown from searchObject_click, that gives the same effect as if the exception was thrown in frmChooseObject_Load. Arch4ngel: I suppose you mean the .exe in the bin-folder. Yes that's the one I execute
-
Sorry, that code gives the same result: An unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attampt to continue. If you click Quit, the application will be shut down immediately Exception of type System.Exception was thrown --------------------------------------------------------------- See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Exception: Exception of type System.Exception was thrown. at Kasper.frmChooseObject.Button1_Click(Object sender, EventArgs e) in H:\SEHJo\Servicegrän . . . ************** JIT Debugging ************** To enable just in time (JIT) debugging, the config file for this application or machine (machine.config) must have the jitDebugging value set in the system.windows.forms section. The application must also be compiled with debugging enabled. For example: <configuration> <system.windows.forms jitDebugging="true" /> </configuration> When JIT debugging is enabled, any unhandled exception will be sent to the JIT debugger registered on the machine rather than being handled by this dialog. I've tryed to turn JIT-debugging on/off (menu - options - debugging - just-in-time) but that makes no difference
-
In this example, MsgBox(CStr(CInt("asdf"))) throws an exception, but the try-catch statement doesn't catch it. No matter what code it is in the Catch block. I want to catch all exceptions which can happen then the form "myFrmChooseObject" is open (not only errors in the sub frmChooseObject_Load) This form does a lot of things, it even opens new windows, and exeptions can appear there too, but I want all this exceptions to be handled by the try-catch statement. JABE: I tryed you example (see vbcode below), but with the same result. It works when i run it in my debug environment, but when i run the exe file, the exception is not catched: Public Sub OpenFrmChooseObject() Try myFrmChooseObject = New frmChooseObject(newSessionUserASW, New Global(CurUserSK) Catch ex As Exception ... End Try End Sub Public Sub New(ByRef inUserASW As dbASWTbl_SOUser, ByRef inGlobal As Global) MyBase.New() InitializeComponent() CurUserAsw = inUserASW Global = inGlobal allowClosing = False Me.ShowDialog() End Sub Private Sub frmChooseObject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MsgBox(CStr(CInt("asdf"))) '(could have written "throw new Exception()" with the same result) End Sub Is there any way to make showdialog in a try-block work?
-
I have a vb application with a try-catch-statement. The try-catch statement encapsulates a ShowDialog-command. When this dialog throws exceptions in debug-mode, the try-catch statement catches all errors, but if i run the exe-file it doesn't catch any errors, and a dialog box appears: "An unhandled exception has occurred in your application..." ([Details], [Continue], [Quit]) This is my code: Public Sub OpenFrmChooseObject() Try myFrmChooseObject.ShowDialog() Catch ex As Exception ... End Try End Sub Private Sub frmChooseObject_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MsgBox(CStr(CInt("asdf"))) End Sub Any idea how to make the try-catch statement catch all errors?
-
This article gives an example how to code if you wants to handle two or more forms in a session with a thread for each session. I have a working, but dirty solution. Mabye someone have a better solution I have a form named frmMain, which can open one or more "sessions". For each session, frmMain starts a new thread, and this thread opens a new window (frmSessionFormA) with showDialog. I use showDialog instead of show, because I want to handle errors occurred in a session with a try-catch in frmMain the code look like this: Try frmSessionFormA.ShowDialog() Catch ex As Exception 'errorhandling End Try The frmSessionFormA have a "Next"-button, which will hide frmSessionFormA and show frmSessionFormB instead. Here is the problem: If I use frmSessionFormA.hide or frmSessionFormA.visible = false, the frmSessionFormA closes! (the whole session ends). Even if I try to cancel the closing in frmSessionFormA's Sub OnClosing, the form closes anyway. However I have a solution, a very dirty one. Instead of frmSessionFormA.visible = false, I use frmSessionFormA.opacity = 0 frmSessionFormA.showInTaskBar = False When showInTaskBar changes value, frmSessionFormA tries to close, but then, the prevention in Sub OnClosing works. When I wants to close frmSessionFormB, and open frmSessionFormA again, I use the same procedure and add frmSessionFormA.bringToFront Have anyone else encountered similar problems? Is there a better way of solving it? Code to hide frmSessionFormA and open frmSessionFormB: (me = frmSessionFormA) frmSessionFormB.Show() preventClosing = 2 Me.ShowInTaskbar = False Me.Opacity = 0 Code to prevent frmSessionFormA from closing Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs) If preventClosing > 0 Then e.Cancel = True If preventClosing = 1 Then Me.BringToFront() End If preventClosing -= 1 End If End Sub Code to close frmSessionFormB, and open frmSessionFormA again: Me.Dispose() frmSessionFormA.ShowInTaskbar = True frmSessionFormA.Opacity = 100
-
Get IDENTITY primary key value to a datatable
hugobooze replied to hugobooze's topic in Database / XML / Reporting
Ok, so it seems that you have to use the DataAdapter Configuration Wizard, or write a lot of code manually. I'm afraid this will not work in my solution, because i'm using the same dataadapter to update all tables in my database. The subs "updateDataTable" and "updateDatabase" (see above) is contained in a class that is inherited by one class for each table. However, I've solved it in a little bit dirty way: I've created shared functions to insert new rows. The function returns the primary key value. I only use this code when I insert rows, and the table has an identity primary key. In all other cases I use my old code. See example of one of my shared insert-functions below: Public Shared Function createItem_Shared(ByVal Name As String, ByVal isTemporary As Boolean, _ ByVal ChargeCodeSearchStr As String) As Int32 Dim id As Int32 Dim strSQL As String Dim connection As New SqlConnection(dbSK_Global.connectionString) strSQL = "INSERT INTO tblArticleGroup(Name, IsTemporary, ChargeCodeSearchStr) " & _ "VALUES(@Name, @IsTemporary, @ChargeCodeSearchStr); Select @@Identity as 'ArticleGroupID' ;" Dim cmd As New SqlCommand(strSQL, connection) cmd.Parameters.Add("@Name", Name) cmd.Parameters.Add("@IsTemporary", isTemporary) cmd.Parameters.Add("@ChargeCodeSearchStr", ChargeCodeSearchStr) Dim param As New SqlParameter() param.Direction = ParameterDirection.Output param.ParameterName = "@ArticleGroupID" param.SqlDbType = SqlDbType.Int cmd.Parameters.Add(param) connection.Open() Dim dr As SqlDataReader = cmd.ExecuteReader() dr.Read() id = dr.Item("ArticleGroupID") connection.Close() Return id End Function As you see: I use SqlParameters and create an output parameter (ArticleGroupID), where the identity primary key will appear after the ExecuteReader-command. -
Get IDENTITY primary key value to a datatable
hugobooze posted a topic in Database / XML / Reporting
I have a table with an automatic increasing primary key. I insert, update and delete rows in this table from my vb.net application by using a Datatable. The problem is: When i insert a new row, the Datatable doesn't get the primary key (is null today). Is there any way to solve this? (I have to use a Datatable) Here is my vb-code i use now: 'updateDataTable is executed first: Public Sub updateDataTable(strSql_SelectedData as String) Dim da As SqlClient.SqlDataAdapter da = New SqlClient.SqlDataAdapter(strSql_SelectedData, connectionString) DataTable = New DataTable() da.Fill(DataTable) End Sub 'Then a lot of code that manipulates data in the datatable is executed ' (for example: inserts rows) 'At last, updateDatabase is executed. 'I want to change this code, so all inserted row's IDENTITY primary keys ' is fetched from the database Public Sub updateDatabase() Dim da As SqlClient.SqlDataAdapter da = New SqlClient.SqlDataAdapter(strSql_DbUpdate, connectionString) da.MissingSchemaAction = MissingSchemaAction.AddWithKey sqlCommBuild = New SqlClient.SqlCommandBuilder(da) da.Update(DataTable) DataTable.AcceptChanges() End Sub -
How to get the Identity primary key value?
hugobooze replied to hugobooze's topic in Database / XML / Reporting
Well, it seems like it was a bad idea to re-formulate my question in the same thread. I'll create a new thread instead. This thread can be closed -
Width of string w/specific Font object
hugobooze replied to hugobooze's topic in Graphics and Multimedia
Ok! Thank you very much!