Solved

SQL Server Stored Procedures and VBScript/ODBCDirect

Posted on 1998-02-15
8
765 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

860 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