By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

SQL 'Unknown Error'

P: n/a
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?
Nov 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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 Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
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?

Nov 17 '05 #2

P: n/a
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 Machin ( .NET/ C# MVP )" wrote:
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 Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
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?


Nov 17 '05 #3

P: n/a
,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

"Ignacio Machin ( .NET/ C# MVP )" wrote:
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 Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
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?


Nov 17 '05 #4

P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
,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

"Ignacio Machin ( .NET/ C# MVP )" wrote:
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 Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
>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?


Nov 17 '05 #5

P: n/a
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:8D**********************************@microsof t.com...
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 Machin ( .NET/ C# MVP )" wrote:
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 Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
>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?


Nov 17 '05 #6

P: n/a
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

"Ignacio Machin ( .NET/ C# MVP )" wrote:
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,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
,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

"Ignacio Machin ( .NET/ C# MVP )" wrote:
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 Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"quilkin" <qu*****@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
>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?


Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.