Solved

SQL Server Stored Procedures and VBScript/ODBCDirect

Posted on 1998-02-15
8
753 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now