Connecting Tech Pros Worldwide Forums | Help | Site Map

VB.NET SQL Server Stored Procedure

Michael
Guest
 
Posts: n/a
#1: Jul 20 '05
This one's really got me. I have a VB.NET (version 1.1.4322) project
that provides an easy way to execute stored procedures on a generic
level. When I run the code on computer A (running SQL Server 2000
version 08.00.0194) the code works great. However, computer B
(running SQL Server 2000 version 08.00.0534) bombs when I try to
execute the sproc saying 'Could not find stored procedure
'spmw_ReadByPage'. My thought process went as follows...

1. Does the procedure really exist. Yes it did. (I tried fully
qualifying it too...'dbo.spmw_ReadByPage')
2. Do I have permission to execute the procedure with the way I'm
logging into the database. Yes I did.
3. Can I execute a different stored procedure in that db with the
exact same code. Yes I could.
4. Can I run the same procedure simpliefied to just return a value and
no parameters. YES I COULD!!
5. So it must be an error in the stored procedure. NO, it executes
with the same parameters in Query Analyzer just fine.
6. At this point I guess that what I've come to is....that in version
08.00.0534 of SQL SERVER 2000, I could NOT execute any stored
procedure in VB.NET if it accepted parameters (Of course, I mean by
using the OleDBCommand object)

Is this true? Is it just me? Any help would be greatly appreciated.
Here's what my code looks like. (By the way, the Parameters collection
just has some home-made objects that have the same properties as a
OleDBParameter object, so you don't need it to try the example. Any
sproc that takes parameters should reproduce the error.)


Public Function ExecuteProc(ByVal ExecutionStyle As ExecutionStyle,
Optional ByVal sSQL As String = "") As Boolean
'Create a command object
Dim oCommand As New OleDbCommand
'Create a connection to our default database and open it
Dim oConn As New OleDbConnection(DBConn.DefaultConnectString)
oConn.Open()
Try
'Go ahead and assing our connection to our Command object
oCommand.Connection = oConn
'OK. Did they pass us an SQL statement?
If sSQL.Trim <> "" And IsNothing(Parameters) Then
Try to use the sql statement
oCommand.CommandType = CommandType.Text
oCommand.CommandText = sSQL
Else
'Don't sweat it, we'll do it for ya
oCommand.CommandType = CommandType.StoredProcedure
'What's the name of the procedure?
oCommand.CommandText = ProcedureName
'Use the Parameters the user has specified to create
the
'command object parameters
For l = 1 To Parameters.Count
With Parameters(l)
Dim oParm As New OleDb.OleDbParameter
'Create a new parameter
oParm = oCommand.CreateParameter()
'Set our parm properties
oParm.ParameterName = .Name
oParm.Direction = .Direction
oParm.OleDbType = .Type
oParm.Value = .Value
'Add parameter to our command
oCommand.Parameters.Add(oParm)
End With
Next
End If
'Execute our command the way we specified
Select Case ExecutionStyle
Case ExecutionStyle.ExecuteNonQuery
mRowsAffected = oCommand.ExecuteNonQuery
Case ExecutionStyle.ExecuteResultSet
'Throw that guy in a table so that we can
Dim oAdapter As New OleDbDataAdapter(oCommand)
Dim oSet As New DataSet
'Use our data adapter to fill our data set
oAdapter.Fill(oSet, "ResultSet")
'User our new data table to set our properties
mResultSet = oSet.Tables("ResultSet")
mRowsAffected = 0
mResultCount = oSet.Tables("ResultSet").Rows.Count
Case ExecutionStyle.ExecuteScalar
'Execute this guy returning a single value as an
object
mScalarValue = oCommand.ExecuteScalar()
If Not IsNothing(mScalarValue) Then
mResultCount = 1
End If
End Select
'Now that we have executed our commands, we need to
'populate the value property for our Output and Return
values
For l = 0 To oCommand.Parameters.Count - 1
With oCommand.Parameters(l)
If .Direction = ParameterDirection.InputOutput _
Or .Direction = ParameterDirection.Output Then
Parameters(l).Value = .Value
End If
End With
Next
'Cleanup
oConn.Close()
ExecuteProc = True
Catch ex As Exception
mResultDesc = ex.Message
mResultCode = Err.Number
End Try
End Function

Erland Sommarskog
Guest
 
Posts: n/a
#2: Jul 20 '05

re: VB.NET SQL Server Stored Procedure


Michael (mholloway@core-techs.net) writes:[color=blue]
> This one's really got me. I have a VB.NET (version 1.1.4322) project
> that provides an easy way to execute stored procedures on a generic
> level. When I run the code on computer A (running SQL Server 2000
> version 08.00.0194) the code works great. However, computer B
> (running SQL Server 2000 version 08.00.0534) bombs when I try to
> execute the sproc saying 'Could not find stored procedure
> 'spmw_ReadByPage'. My thought process went as follows...[/color]

8.00.194 is the RTM release, and 534 is SP2. The most current service
pack is SP3, which is build 760. Many run with a security fix which
has build number 818.
[color=blue]
> 6. At this point I guess that what I've come to is....that in version
> 08.00.0534 of SQL SERVER 2000, I could NOT execute any stored
> procedure in VB.NET if it accepted parameters (Of course, I mean by
> using the OleDBCommand object)[/color]

I am right to assume that if you bave no parameters you will actually
use CommandType.Text? I cannot really be sure if I can conclude this
from your VB code.

Anyway, maybe you should add a parameter for the return value. Name
RETURN_VALUE, type OleDbTypes.Integer and Direction.ReturnValue. This
should be first parameter.

You could also use the Profiler to see what the program submits to
SQL Server.


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
DFS
Guest
 
Posts: n/a
#3: Jul 20 '05

re: VB.NET SQL Server Stored Procedure


"Erland Sommarskog" <sommar@algonet.se> wrote in message
[color=blue]
> 8.00.194 is the RTM release, and 534 is SP2. The most current service
> pack is SP3, which is build 760. Many run with a security fix which
> has build number 818.[/color]


And it looks like you can determine this value by executing

SELECT SERVERPROPERTY('ProductVersion')

or by looking at the About screen in Query Analyzer.

I have SP3a installed; it shows 8.00.760.



[color=blue][color=green]
> > 6. At this point I guess that what I've come to is....that in version
> > 08.00.0534 of SQL SERVER 2000, I could NOT execute any stored
> > procedure in VB.NET if it accepted parameters (Of course, I mean by
> > using the OleDBCommand object)[/color]
>
> I am right to assume that if you bave no parameters you will actually
> use CommandType.Text? I cannot really be sure if I can conclude this
> from your VB code.
>
> Anyway, maybe you should add a parameter for the return value. Name
> RETURN_VALUE, type OleDbTypes.Integer and Direction.ReturnValue. This
> should be first parameter.
>
> You could also use the Profiler to see what the program submits to
> SQL Server.
>
>
> --
> Erland Sommarskog, SQL Server MVP, sommar@algonet.se
>
> Books Online for SQL Server SP3 at
> http://www.microsoft.com/sql/techinf...2000/books.asp[/color]


Ellen K.
Guest
 
Posts: n/a
#4: Jul 20 '05

re: VB.NET SQL Server Stored Procedure


or SELECT @@VERSION

On Wed, 28 Jan 2004 19:06:19 -0500, "DFS" <nospam@nospam.com> wrote:
[color=blue]
>And it looks like you can determine this value by executing
>
>SELECT SERVERPROPERTY('ProductVersion')
>
>or by looking at the About screen in Query Analyzer.[/color]

Closed Thread