|
captainmogo wrote: If the database in unreachable - I want to wait and then try again but if there is a problem with the retrieved data, I want to send it up to the calling code
This is where you'd throw your exception. The calling code would be running in a Try/Catch block to catch this error. It's the calling code that has to worry about what the problem is and how to deal with it, not the database code.
|
|
|
|
|
ok well my calling code is in a backgroundworker
Class1
Private Sub DoSomething(ByVal sender as Object, ByVal e as DoWorkEventArgs) Handles worker.DoWork
SetTriggerStatus(nam, id, "Started")
Query(start_time, end_time)
....Wait
Query(start_time, end_time)
End Sub
End Class
Module1
Sub SetTriggerStatus(Byval nam as String, ByVal id as Integer, ByVal status as String)
Dim connection as New Client.OracleConnection(My.Settings.OracConnectionString.ToString)
Dim cmd as Client.OracleCommand = Nothing
Try
cmd = New Clinet.OracleCommand("INSERT INTO StatusLog (Name, RuleID, Status) VALUES(:Name,
:RuleID,:Status)", connection)
....set oracleparameters
....execute script
connection.close
Finally
..dispose
End Try
End Sub
End Module
Basically if I get an error connecting to the database in here, I want it to try again. So I would have to put the try/catch around the SetTriggerStatus call from within DoWork? Same with both the query subs?) I also read somewhere that it is not good practice to be putting try/catch blocks in background workers (of course I cant find a good explanation for it now)
|
|
|
|
|
Hi,
here are some guide lines, they should enable you to make good decisions about error handling:
1. only try-catch exceptions your catch can deal with; don't just swallow exceptions to make them go away; always leave some trace of an exception, say in a log file. it makes debugging much harder if you don't.
2. when you want retries, you can but the try-catch inside the loop and swallow exceptions in all but the last iteration. Don't retry forever.
3. background threads typically need to report back to their parent thread, whether success or failure. You shouldn't have a background thread retry forever, or just fail or give up without telling.
4. when your app needs to report failure back to the user, make sure to have both a message the user can understand (and knows what we'd do best then), and the technical information behind it (that could be the low-level exception) should be somewhere, again in a log file.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I am going to write the errors to a log file because there is not user interface for this app. It is actually going execute on a machine with no monitor. The requirements I was given was to have the the db queries fail on any error but I want to try and handle what I can before saying its failed. say somethign like the db is not available.
Luc Pattyn wrote: . when you want retries, you can but the try-catch inside the loop and swallow exceptions in all but the last iteration. Don't retry forever.
3. background threads typically need to report back to their parent thread, whether success or failure. You shouldn't have a background thread retry forever, or just fail or give up without telling.
This makes sense
so could I use recursion to do a retry. I dont want it to retry it forever... just wait a sec and then try to connect again. If it fails again then exit.
|
|
|
|
|
Hi,
I see no problem in retrying a couple of times, and only report failure if all tries have failed.
I would not actually use recursion for that though, recursion gets abused all too often.
Basically what I'd do is (in C# syntax, VB.NET can do similar things):
for (int tryCount=1; ; tryCount++) {
try {
...
} catch(Exception exc) (
if (tryCount< maxTry) continue;
log(exc.ToString());
throw new ApplicationException("Operation XXX failed after "+maxTry+" tries", exc);
}
}
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Thanks for your help. I used your example and it works well. If it cannot see/find the database after 2 tries, it throws an exception which is caught by the run worker completed event and the rest of the DoWork method is not executed (which is fine since the whole point is to access the database anyway)
Thanks again
|
|
|
|
|
Hello I am trying to create a windows form application with VB 2008 and i am intending to read info from any textbox or whatever and export the data to word I do not know how to do it, I did some research and this is what I found :
Dim oWord As Word._Application()
oWord = New Word.Application()
But is giving me errors the word.application declaration seems to work with older version but not 2008. Please help.
I also found this code but it does not work:
Public Module DriveWord
Public Sub Main()
'Start Word in the background
Dim App As New Word.Application()
App.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone
'Create a new document
Dim Doc As Word._Doucment = App.Documents.Add()
Console.WriteLine()
Console.Writeline("Creating New Document")
Console.Writeline()
'Add a heading and two lines of text
Dim Range As Word.Range = Doc.Paragraphs.Add().Range
Range.InsertBefore ("Test Document")
Range.Style = "Heading 1"
Range = Doc.Paragraphs.Add().Range
Range.InsertBefore("Line one." &vbCrLf & "Line two.")
Range.Font.Bold = True
'Save and close the current document.
Doc.SaveAs(App.StartupPath & "\test.doc")
Doc.Close()
Doc=Nothing
End Sub
regards,
|
|
|
|
|
Hi,
FWIW: I recently decided to create RTF files from C#, foregoing all .NET-to-various-Office-versions troubles. Once an RTF file exists, you can launch it using Process.Start(filename) which launches the default RTF application, i.e. WordPad if no Office is present, Office otherwise. And BTW: RTF is capable of much more than you can edit in WordPad, e.g. I did some table stuff which is visible in WordPad, and works fine (viewing and editing) in Word, any version.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
hai,
i have a xml doc i need the nodes in the xml to be converted to a database table records for example access or oracle or sql. any one know the vb.net code to do this??
|
|
|
|
|
Tons of ways and you'll need to read up on it, because there are entirely to many details to list here and each DB has diff. methods for doing this.
1. You could do an XML reader and handle the import yourself.
2. SQL - you can use SSIS to import the data.
3. You could do an XML transform for the import.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Hi
I am using visual studio 2003. I need to ping every computers in my LAN for my application. For this purpose I have used the "System.Net" namespace's TCP class. Is there any better solution to this problem.
Thanks.
reman
|
|
|
|
|
I'm not certain of the method you're talking about, but chances are the System.Net.NetworkInformation.Ping class will be more verbose and robust
|
|
|
|
|
If they all ran an app you write, you could use UDP.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Hi everyone, i need to create a project on .NET remoting. I am a newbie at VB.NET and need some help. Here is the specifications:
Must be in the console Console
Write a console client that lets the user input a String value for the path of a text file.
This path must be passed to a Function which displays the contents of the specified file.
If possible please provide coding examples.
thanks in advance.
|
|
|
|
|
Sorry we do not do your homework for you.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Well, Im just looking for some guidelines, as my VB.NET book does not cover .NET Remoting. The example they give is so simple and i have tried searching the net, with no luck.
|
|
|
|
|
In that case, don't get stuck at the title of the assignment. Look at the specifications.
In other words, (apparently) you need to make a console program that takes a string parameter (path to a text file) and returns the contents of that file to the screen.
So:
1. look into console programming. For example just start a new console project in Visual Studio.
2. Figure out how you can pass parameters to a console program. For example look into command line arguments.
3. figure out how to find a file and read from it. For example look into System.IO and the StreamReader class
4. Use Console.Write or Console.WriteLine to return the content of the file to the screen.
My advice is free, and you may get what you paid for.
|
|
|
|
|
Your spec's don't have anything to do with Remoting. All you're doing it taking a filepath as a command line argument, opening that file and reading it into a String, then using Console.WriteLine to write that string out. .NET Remoting is WAY overkill for such a simple assignment.
BTW, there's nothing in this code that would not have been covered in the chapters of the book you're using up to this point. So, if you're in Chapter 5, the answer is not going to be in Chapters 6 and above.
|
|
|
|
|
Thanks alot, I know Remoting makes it way overkill, but they asked us to do it in remoting, I can easily get this doen trough console alone. The thing is My VB.NET book does not really cover Remoting in advance. the example they give is simple and does not really explain anything in detail. But thanks alot anyway guys. Appreciated alot.
|
|
|
|
|
OK, then start Googling for ".net remoting tutorial". You'll find thousands of them. Your remote component would just need the filename to read (a string obviously) and return the contents of that file (another string). There's nothing too difficult in there.
|
|
|
|
|
Hi all,
i create vb.net dll and tlb file and i useed it as reference in vb6, in the vb6 code i wrote :
Dim MyObj As New DllName.ClassName
this statment run correct and return result, but when i wrote :
Dim MyObj as Object<br />
Set MyObj = CreateObject("DllName.ClassName")
there is error accour can't create active x component
I want to if i can use late binding rather than early binding.
Thanks for help
|
|
|
|
|
Pretty sure that should work. You did register the .tlb right?
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks for reply
yes i did, and when i search about it in the registry i found it, so i want to know why createobject didn't work
|
|
|
|
|
I tested this with a FTP assembly I have. In the .Net project, I checked "Register for COM interop" and added the following attributes to the class:
<classinterface(classinterfacetype.autodual)> _
<progid("ftpdotnet.clsftp")> _
Public Class FTP_Client
Compiled the project. Copied the .dll and .tlb to win\sys32. Registered the .dll with regasm (regasm FTPDotNet.dll /tlb:FTPDotNet.tlb /codebase
Added a reference in VB6 to the .tlb. Used this code in VB6 and everything was peachy:
Dim o As Object
Set o = CreateObject("FTPDotNet.clsFTP") 'Note: I am only using the progID specified above.
o.Server = "test"
o.UserName = "blah blah"
If you're still having errors, verify you have *simple datatypes* being exposed. With the .Net command, navigate to the directory with the .dll and .tlb are and register them as above.
Any suggestions, ideas, or 'constructive criticism' are always welcome.
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison
|
|
|
|
|
Thanks alot for your help
|
|
|
|