473,390 Members | 1,156 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

VB.NET SQL Server Stored Procedure

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
Jul 20 '05 #1
3 18593
Michael (mh*******@core-techs.net) writes:
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...
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.
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)


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, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
DFS
"Erland Sommarskog" <so****@algonet.se> wrote in message
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.

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.

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)


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, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 20 '05 #3
or SELECT @@VERSION

On Wed, 28 Jan 2004 19:06:19 -0500, "DFS" <no****@nospam.com> wrote:
And it looks like you can determine this value by executing

SELECT SERVERPROPERTY('ProductVersion')

or by looking at the About screen in Query Analyzer.


Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Yves Touze | last post by:
Hi All, I'm trying to migrate from SQL Server 7.0 to SQL Server 2000. I've got some ASP page which call VB components that retrieve shaped recordsets from SQL Server using the MSDATASHAPE...
18
by: Robin Lawrie | last post by:
Hi again, another problem! I've moved from an Access database to SQL server and am now having trouble inserting dates and times into seperate fields. I'm using ASP and the code below to get the...
5
by: gilles27 | last post by:
I've ready many of the posts on this and other newsgroups in which people describe working practices for source control of database scripts. We are looking to implement something similar in my...
26
by: David W. Fenton | last post by:
A client is panicking about their large Access application, which has been running smoothly with 100s of thousands of records for quite some time. They have a big project in the next year that will...
4
by: Bill Sonia | last post by:
Hello, I have a Widnows Service that creates a system event that I would like to have a Sql Server stored procedure fire when the stored procedure is called. I have a Windows Service that runs...
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
12
by: Light | last post by:
Hi all, I posted this question in the sqlserver.newusers group but I am not getting any response there so I am going to try it on the fine folks here:). I inherited some legacy ASP codes in my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.