SQL Server bug

leojordao

New member
Joined
Oct 23, 2006
Messages
3
Programming Experience
1-3
Hello all,

I have a problem in my WebApplication. The following error occures:

System.Data.SqlClient.SqlException: A severe error occurred on the current command. The results, if any, should be discarded.

This error occures also occasionaly on other Usercontrols, in which the SQLServer is accessed.

I can not reproduce the error. Sometimes it works and sometimes not, with the same data in the webform. Other Applications with the same basic Architecture do not
have this problem.

I’m working with Stored Procedures, but not using nvarchar types, just varchar less them 4000.

The Application runs on the Webserver with Windows2000AdvancedServer installed and The Database on a Databaseserver also with Windows2000AdvancedServer
installed and SqlServer2000.

Pls help. Thanks in advance.

Leo Jordao
 
Hi,

There is one part of the code where the error occur . Exactly in the line “[FONT=&quot]Dim[/FONT][FONT=&quot] dr As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)[/FONT]”
VB.NET:
[COLOR=blue][FONT=&quot]Public[/FONT][/COLOR][FONT=&quot] [COLOR=blue]Function[/COLOR] GetUsuario([COLOR=blue]ByVal[/COLOR] Matricula [COLOR=blue]As[/COLOR] [COLOR=blue]String[/COLOR]) [COLOR=blue]As[/COLOR] Cl_Usuario[/FONT]
[FONT=&quot][COLOR=blue]Dim[/COLOR] bd [COLOR=blue]As[/COLOR] SqlConnection[/FONT]
[FONT=&quot][COLOR=blue]Try[/COLOR][/FONT]
[FONT=&quot]bd = bd_Principal.CriaConexao()[/FONT]
[FONT=&quot][COLOR=blue]Dim[/COLOR] sql [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] StringBuilder()[/FONT]
[FONT=&quot]sql.Append("select U.Matricula,Nome,Ramal,Cgc, codTipoAcesso from Usuarios U ")[/FONT]
[FONT=&quot]sql.Append(" inner join Acesso A on u.Matricula = A.Matricula ")[/FONT]
[FONT=&quot]sql.Append("where U.Matricula = @Matricula ")[/FONT]

[FONT=&quot][COLOR=blue]Dim[/COLOR] paramMatricula [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] SqlParameter("@Matricula", SqlDbType.VarChar, 7)[/FONT]
[FONT=&quot][COLOR=blue]Dim[/COLOR] myCommand [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] SqlCommand(sql.ToString, bd)[/FONT]

[FONT=&quot]paramMatricula.Value = Matricula[/FONT]

[FONT=&quot]myCommand.Parameters.Add(paramMatricula)[/FONT]
[FONT=&quot][COLOR=blue]If[/COLOR] bd.State = ConnectionState.Closed [COLOR=blue]Then[/COLOR][/FONT]
[FONT=&quot]bd.Open()[/FONT]
[FONT=&quot][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]

[FONT=&quot][COLOR=blue]Dim[/COLOR] dr [COLOR=blue]As[/COLOR] SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)[/FONT]
[FONT=&quot]D[COLOR=blue]im[/COLOR] usuario [COLOR=blue]As[/COLOR] [COLOR=blue]New[/COLOR] Cl_Usuario()[/FONT]

[FONT=&quot][COLOR=blue]If[/COLOR] dr.Read [COLOR=blue]Then[/COLOR][/FONT]
[FONT=&quot]usuario.Nome = dr("Nome")[/FONT]
[FONT=&quot]usuario.Matricula = dr("Matricula")[/FONT]
[FONT=&quot]usuario.Cgc = dr("Cgc")[/FONT]
[FONT=&quot]usuario.Ramal = dr("Ramal")[/FONT]
[FONT=&quot]usuario.IdPerfil = [COLOR=blue]CType[/COLOR](dr("codTipoAcesso"), [COLOR=blue]Integer[/COLOR])[/FONT]
[FONT=&quot]dr.Close()[/FONT]
[FONT=&quot][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]


[FONT=&quot][COLOR=blue]Return[/COLOR] usuario[/FONT]
[FONT=&quot][COLOR=blue]Catch[/COLOR] e [COLOR=blue]As[/COLOR] SqlException[/FONT]
[FONT=&quot]Debug.WriteLine(e.Message)[/FONT]
[FONT=&quot]Debug.WriteLine(e.Number)[/FONT]
[FONT=&quot]Debug.WriteLine(e.StackTrace)[/FONT]
[FONT=&quot][COLOR=blue]Throw[/COLOR] [COLOR=blue]New[/COLOR] Bd_Usuario_Ex(e)[/FONT]
[FONT=&quot][COLOR=blue]Finally[/COLOR][/FONT]
[FONT=&quot][COLOR=blue]If[/COLOR] [COLOR=blue]Not[/COLOR] IsNothing(bd) [COLOR=blue]Then[/COLOR][/FONT]
[FONT=&quot][COLOR=blue]If[/COLOR] bd.State = ConnectionState.Open [COLOR=blue]Then[/COLOR][/FONT]
[FONT=&quot]bd.Close()[/FONT]
[FONT=&quot][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
[FONT=&quot][COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
[COLOR=blue][FONT=&quot]End[/FONT][/COLOR][FONT=&quot] [COLOR=blue]Try[/COLOR][/FONT]
[COLOR=blue][FONT=&quot]End[/FONT][/COLOR][FONT=&quot] [COLOR=blue]Function[/COLOR][/FONT]

[FONT=&quot]Thanks in advance for your help.[/FONT]
 
Last edited by a moderator:
1) Just so you know, what you have there is a parameterized query.... not a stored procedure. Two different animals.
2) A couple of things to try:
a) split the line up:
VB.NET:
Dim dr As SqlDataReader
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
b) Try messageBox.show the myCommand.SelectStatement.ToString <- I think that's right -- to see what the actual SQL is... make sure nothing weird has been done to it during the .Append.

-tg
 
Thank TechGnome, for your help...

I know, this code just shows a parameterized query, but in other part of code i have SP's and this error occur too.

I made your sugestions (a and b), but i don't have sucess...

Have you another idea???

Thanks a lot.
 
Back
Top