473,418 Members | 2,033 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,418 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 18597
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.