Solved

SQL Server Stored Procedures and VBScript/ODBCDirect

Posted on 1998-02-15
8
768 Views
Last Modified: 2008-02-01
I'm having a problem getting SQL Server stored procedures to function in an MSOutlook97 form using ODBCDirect.  

The problem is that if the stored procedure has any parameters passed into it, then it doesn't work.  However, if there are no parameters, it works fine.  I don't understand why this is happening.  Could someone please explain this & give me an example that works?

This is the code I'm using:

Dim dbe
Dim wrkODBC
Dim conDB
Dim RS

'Dimension variables to hold DAO constants
Dim dbUseODBC
Dim dbDriverComplete
Dim dbDriverNoPrompt
Dim dbDriverPrompt
Dim dbDriverCompleteRequired
Dim dbOpenSnapshot
Dim dbOpenForwardOnly
Dim dbOpenDynamic

'Assign DAO constants
dbUseODBC = 1
dbDriverComplete = 0
dbDriverNoPrompt = 1
dbDriverPrompt = 2
dbDriverCompleteRequired = 3
dbOpenSnapshot = 4
dbOpenForwardOnly = 8
dbOpenDynamic = 16

'Establish an ODBCDirect connection
Set dbe = Item.Application.CreateObject("DAO.dbEngine.35")
Set wrkODBC = dbe.CreateWorkspace("ODBCWorkspace", "sa",_
   "", dbUseODBC)
dbe.Workspaces.Append wrkODBC
Set conDB = wrkODBC.OpenConnection("Connection1", dbDriverCompleteRequired, _
 "ODBC;DSN=priceWF;UID=sa;PWD=;")

'Use stored procedure to obtain data
'(this doesn't work)
strSQL = "spInfProjectByLocation 'mmm45',7"
Set RS = conDB.OpenRecordSet(strSQL, dbOpenSnapshot)

'But this works (stored procedure with no parameters):
strSQL = "spInfAllProjects"
Set RS = conDB.OpenRecordset(strSQL, dbOpenSnapShot)


****
Any ideas?
0
Comment
Question by:dmacioce
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Author Comment

by:dmacioce
ID: 1457197
Edited text of question
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1457198
Did you try putting parantesis () around the params?

strSQL = "spInfProjectByLocation('mmm45',7)"

Of course I don't know SQL server that well yet
0
 

Author Comment

by:dmacioce
ID: 1457199
Yes, I did try putting paretheses around the parameters, but that didn't work either.

As a further analysis, I thought that perhaps that the SQL command containing the stored procedure was being rejected before getting passed to SQL Server, so I was thinking I might need to use the dbSQLPassThrough option.

I did try adding the following to the relevant sections of the code, and this gave me an "Invalid argument" error:

'Added the following delcaration and assignment statements
Dim dbSQLPassThrough

dbSQLPassThrough = 64

'Added the option value to OpenRecordset as follows:
Set RS = conDB.OpenRecordset(strSQL, dbOpenSnapshot, _
   dbSQLPassThrough)

***
I suspect that the reason dbSQLPassThrough doesn't work (invalid argument) is that I'm using ODBCDirect; I think this option might be for a Jet connection only (?).

Today I will try using dbExecDirect, but I'm not sure this will work yet...  Any comments?

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dmacioce
ID: 1457200
Just tried using dbExecDirect with no success.

I'm beginning to think that what I want to do is not possible with ODBCDirect.  None of the references available to me indicate that it is possible to use ODBCDirect with stored procedures.  The VB5.0 guide to building client/server apps indicates that RDO should be used with stored procedures, but as far as I know, I cannot use the RDO engine in an MS Outlook form. Am I wrong about this?  Is there any way around this?


0
 

Author Comment

by:dmacioce
ID: 1457201
Adjusted points to 100
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1457202
Provide us with the heading of the stored procedure so that we can see how your parameters are defined.
0
 
LVL 2

Accepted Solution

by:
alokm earned 100 total points
ID: 1457203
hello dmacioce,
i think the problem is u are trying to directly pass parameters with openrecordset method.
U will have to put "exec " before the stored proc. name.
             strSQL = "exec spInfProjectByLocation 'mmm45',7"
             Set RS = conDB.OpenRecordSet(strSQL,dbOpenSnapshot)
hope this solves it.
alok
0
 

Author Comment

by:dmacioce
ID: 1457204
Actually, there were two problems.  You solved one of them.  I appreciate it very much.  The other one I figured out on my own.  In order to use the stored procedure, which contained multiple select statements, I had to do the following:

strSQL = "exec spInfPrjLOcation 'mmm45',7"
Set QD = conDB.CreateQueryDef ("", strSQL)
QD.CacheSize = 1
Set RS = QD.OpenRecordset (dbOpenForwardOnly _
    , , dbReadOnly)

As an alternative, I could have set the DefaultCursorDriver property to dbUseNoCursor.

Therefore, I gave you a B.  
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question