Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Server Stored Procedures and VBScript/ODBCDirect

Posted on 1998-02-15
8
Medium Priority
?
779 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
Independent Software Vendors: 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 300 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

636 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