471,320 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,320 software developers and data experts.

Q:Access Parameterized Query to Oracle?


I want to know how to use Oracle views with session variables in
The parameterised views in access, are migrated to views with per

The open questions:
How to display a resultset
How to handle Oracle exceptions

Closed questions:
How to call a stored procedure from DAO.
How to call a stored procedure from ado and then display a view in a
Using a cache to get the same session.

[Sample database setup]

(I have an Oracle backgroud)

The open questions:
How to display a resultset
I am not sure how to display a recordset that is created in VBA.

How to handle Oracle exceptions
Oracle handles errors by 'exceptions',
I am not sure how to handle them in Access.

Closed questions:

What I have been able to do is:

[My session variables have an API, but basically one needs to call a
stored procedure/function to set/get them]

How to call a stored procedure from DAO

Set session variables over DAO/ODBC:
where 'QUERYEXAMPLE:input_name' references a variable and 'smith' is
the value
to set.

call to set string via dao
Function SetVal() As Boolean
Dim db As Database
Set db = DBEngine.Workspaces(0).Databases(0)
Set qitem = db.CreateQueryDef("")
qitem.Connect = "ODBC;DSN=o92;UID=scott;PWD=tiger"
qitem.ReturnsRecords = False
qitem.ODBCTimeout = 15
qitem.SQL = "CALL
omwb_emulation.utilities.setvarchar2('QUERYEXAMPLE :input_name','smith')"
Set qitem = Nothing
SetVal = True
End Function
How to call a stored procedure from ado and then display a view in a
using ado/oledb
************************************************** *********************

How to bind Microsoft Access forms to ADO recordsets:

looks like adodb.recordsets bound to forms are read only.
The following is based on the Microsoft information with nformation
fille in
about using odbc to reach the oracle database with the views. The same
is used to set the parameter and then select from the view to populate

Option Compare Database

Private Sub Form_Open(Cancel As Integer)
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim setstring As ADODB.Command
Dim param1 As ADODB.Parameter
Dim param2 As ADODB.Parameter

strConnection = "ODBC;DSN=o92;UID=northwindalt;PWD=oracle"
'Create a new ADO Connection object
Set cn = New ADODB.Connection

With cn
.Provider = "MSDASQL"
.Properties("Data Source").Value = strConnection
End With

'Create an instance of the ADO Recordset class, and
'set its properties

Set setstring = New ADODB.Command
With setstring
.ActiveConnection = cn
.CommandText = "omwb_emulation.utilities.setvarchar2"
.CommandType = adCmdStoredProc
End With

Set param1 = setstring.CreateParameter(, adVarChar, adParamInput,
100, "QUERYEXAMPLE:input_name")
setstring.Parameters.Append param1

Set param2 = setstring.CreateParameter(, adVarChar, adParamInput,
100, "smith")
setstring.Parameters.Append param2


Set setstring = Nothing

Set rs = New ADODB.Recordset
With rs
Set .ActiveConnection = cn
.Source = "SELECT * FROM queryexample"
.LockType = adLockOptimistic
.CursorType = adOpenKeyset
.CursorLocation = adUseClient
End With

'Set the form's Recordset property to the ADO recordset
Set Me.Recordset = rs
Set rs = Nothing
Set cn = Nothing
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Close the ADO connection we opened
Dim cn As ADODB.Connection
Set cn = Me.Recordset.ActiveConnection
Set cn = Nothing
End Sub

Using a cache to get the same session.
The thing is there is a timeout

The Microsoft Jet database engine uses the ODBC entries as follows.

Initialization Settings for Microsoft Jet-connected ODBC Databases
The \HKEY_LOCAL_MACHINE\Software\Microsoft\Jet\4.0\Eng ines\ODBC folder
contains initialization settings for the Microsoft Jet database engine.

ConnectionTimeout The number of seconds a cached connection can remain
before timing out. The default is 600 (values are of type REG_DWORD).

Sample database setup

table example1.
ID, name, telephone

query queryexample:
Parameters [input name] text;
select telephone from example1 where name=[input name];

becomes in oracle
SELECT telephone
FROM example1
omwb_emulation.utilities.getvarchar2('QUERYEXAMPLE :input_name') FROM

which can be called from Oracle sqlplus:

SQL> begin
omwb_emulation.utilities.setvarchar2('QUERYEXAMPLE :input_name','smith');
3 end;
4 /

SQL> select * from queryexample;


Nov 13 '05 #1
0 2802

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jon Ole Hedne | last post: by
8 posts views Thread by Alfonso Esteban Gonzalez Sencion | last post: by
12 posts views Thread by zwasdl | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.