tracertong
New member
- Joined
- Oct 22, 2010
- Messages
- 3
- Programming Experience
- 5-10
Hello,
I've recently inherited a VB.NET forms project which does basic background administrative tasks on a Windows Server 2003 machine (virtual machine, FWIW). Part of it's functionality is a Timer control, whose tick is set at every 10 seconds, and runs all the time. This tick event writes or updates a progress record into a database running locally on the same machine, using a Non-query call.
Normally, this runs fine, but very occasionally (say between one to five occasions, every hour) it throws a "ConnectionString property has not been initialized." error out.
This is the method it is calling, to write the progress query to the database (I haven't shown the call, because it is this that appears to be the problem):
Now, this may be a little sloppy, I don't know (I'm not strong on .NET, as yet), but I don't see how the ConnectionString property can not be initialized, when it appears to be hard-coded ("sffdsn" is a system DSN, by the way). I also don't see why this might happen as infrequently as 1 in 600 occasions that it is called.
My predecessor appears to have 'handled' this problem, by wrapping the call in a Try, with an empty catch - but since any number of other things could escape attention, this way, I decided to catch it properly, and log the exception message. The problem is, the exception message is a fairly typical ".NET barf", of around 30 lines, and (intermittent as it is) logging the error is making my log almost twice as big as it was before. In the 11 hours since midnight, for instance, I have 42 examples of this happening, and the 42 records dwarf the rest of the log. (The other problem is, that I don't know enough .NET to understand why the exception is happening, of course!)
I've recently inherited a VB.NET forms project which does basic background administrative tasks on a Windows Server 2003 machine (virtual machine, FWIW). Part of it's functionality is a Timer control, whose tick is set at every 10 seconds, and runs all the time. This tick event writes or updates a progress record into a database running locally on the same machine, using a Non-query call.
Normally, this runs fine, but very occasionally (say between one to five occasions, every hour) it throws a "ConnectionString property has not been initialized." error out.
This is the method it is calling, to write the progress query to the database (I haven't shown the call, because it is this that appears to be the problem):
VB.NET:
Public Function doNonQuery(ByVal strQuery As String)
Dim result As Integer
myConnection = New OdbcConnection()
myConnection.ConnectionString = "dsn=sffdsn"
myCommand = New OdbcCommand(strQuery, myConnection)
myConnection.ConnectionTimeout = 0
myCommand.CommandTimeout = 0
Do Until myConnection.State = ConnectionState.Open
myConnection.Open() <-- The error throws here
Loop
result = myCommand.ExecuteNonQuery()
myConnection.Close()
myConnection.Dispose()
Return result
End Function
Now, this may be a little sloppy, I don't know (I'm not strong on .NET, as yet), but I don't see how the ConnectionString property can not be initialized, when it appears to be hard-coded ("sffdsn" is a system DSN, by the way). I also don't see why this might happen as infrequently as 1 in 600 occasions that it is called.
My predecessor appears to have 'handled' this problem, by wrapping the call in a Try, with an empty catch - but since any number of other things could escape attention, this way, I decided to catch it properly, and log the exception message. The problem is, the exception message is a fairly typical ".NET barf", of around 30 lines, and (intermittent as it is) logging the error is making my log almost twice as big as it was before. In the 11 hours since midnight, for instance, I have 42 examples of this happening, and the 42 records dwarf the rest of the log. (The other problem is, that I don't know enough .NET to understand why the exception is happening, of course!)
Last edited: