Strange bug (x-posted to aspdotnet, sqlserver)
Date: 01/13/05
(SQL Server) Keywords: sql
I'm getting some weird behavior in a function I wrote.
Private Function GetServerStatus() As Integer
Dim strDataSource As String
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim intStatus As Integer
strDataSource = ConfigurationSettings.AppSettings("DSN")
myConnection = New SqlConnection(strDataSource)
myCommand = New SqlCommand("GetSystemStatus", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
myConnection.Open()
intStatus = myCommand.ExecuteNonQuery()
myConnection.Close()
Return intStatus
End Function
It uses the stored procedure "GetSystemStatus":
CREATE PROCEDURE dbo.GetSystemStatus
AS
DECLARE @SystemStatus int
SELECT @SystemStatus=MAX(systemstatus)
FROM Config
RETURN @SystemStatus
GO
The weird behavior is that GetServerStatus() returns -1, but when I run GetSystemStatus in Query Analyzer, it returns 0 (or whatever the value is).
Source: http://www.livejournal.com/community/sqlserver/15376.html