Solved

SQL Server Stored Procedures and VBScript/ODBCDirect

Posted on 1998-02-15
8
764 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
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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…

823 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