SQL 'Unknown Error'

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am getting a System.Data.SqlClient.SqlException with a message string of
'Unknown Error'. Happens occasionally when creating a "new SqlCommand(...)"
while the same command works perfectly happily hundreds of other times. A
side effect is that the connection closes.
..NET version is 1.1, same thing happens on various machines, but seems to
happen more often on slower ones.
Any ideas?
 
Hi,

Did you check InnerException ?
What about the Errors collection ?

Here is a method which unfortunately is in VB.NET that gives you all the
info from a SqlException:

Sub ShowSQLError(ByVal e As SqlCeException)

'Dim errorCollection As SqlCeErrorCollection = e.Errors

Dim bld As StringBuilder = New StringBuilder

Dim inner As Exception = e.InnerException

For Each err As SqlCeError In e.Errors
bld.Append("\n Error Code: " + err.HResult.ToString("X"))
bld.Append("\n Message : " + err.Message)
bld.Append("\n Minor Err.: " + err.NativeError.ToString())
bld.Append("\n Source : " + err.Source)

For Each numPar As Integer In err.NumericErrorParameters
If 0 <> numPar Then
bld.Append("\n Num. Par. : " + numPar)
End If


Next

For Each errPar As String In err.ErrorParameters
If String.Empty <> errPar Then
bld.Append("\n Err. Par. : " + errPar)
End If
Next


MessageBox.Show(bld.ToString())
If (Not (inner Is Nothing)) Then
ShowSQLError(CType(inner, SqlCeException))

End If
bld.Remove(0, bld.Length)
Next



End Sub


Cheers,
 
Ignacio

I don't think I need the VB to get the info, I can get it from the debugger.
Actually on closer inspection it is 'ExecuteNonQuery()' and not 'new
SQLCommand()' causing the error.
Does any of the info here help?
Message "Unknown error."
InnerException: { }System.Exception
_COMplusExceptionCode: -532459699
_HResult: -2146232060
Class: 20
errorClass: 20
Source: ".Net SqlClient Data Provider"

Everything else seems to be either null, zero or empty strings.

Thanks, Chris
 
,Ignacio,

I've now got more information on this. One time, the message in my log file
(next to the 'unknown error' was
"SQL error: Line 1: Incorrect syntax near 'DESCUPDATE'."
I have no commands 'DESCUPDATE' but I do have plenty that start with
'UPDATE' and plenty that end with 'DESC'. So the SqlClient is concatenating
the commands.

Hanving looked at the documentation I now see that SqlCommand (etc) is not
thread-safe, but my app is using several threads to collect data from
connected devices and store the data in the database. Is there any way round
this?
I tried making the SqlConnection and SqlCommand static but that just made
things worse.
Do you know if .NET 2.0 has thread-safe versions of these classes?(I am
using .NET 1.1 now)

Chris
 
Hi,

If you are creating a new command in each thread ( or in each operation )
you are ok.

are you using SP ?
If not, why don you dump the content of the CommandText when you get an
error?

it may sound that your query is the one with error.


cheers,
 
Hi,

Did you check the Errors colection?

I though the same once, but only when I wrote the below code I found the
error description.

What about the NativeError?

cheers,
 
Hi again,

I'm not using threads explicity - but there are a few timers which use the
db connection in their handlers. So, on occasion, the timer handlers may be
trying to connect to the db at the same time.
What is SP?
How do I dump the content of the command text?
What do you mean, "it may sound that your query is the one with error"? As I
mentioned, 99% of the time the (same) commands are processed OK, it's just
now and again the connection gives this error.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top