472,125 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

pass-through queries and parameters

Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the server ?
Is it possible to use parameters in pass-through queries ?

An additional question: Is it possible to connect to a database on MySQL or
PostgreSQL using ADO ?
Is it possible to execute pass-through queries with parameters, using ADO
command object ?

Thanks!
Nov 13 '05 #1
7 21280
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SQL Pass Through (SPT) queries are used in DAO .mdb files, only.

Sending parameters to an SPT means the SPT is calling a stored procedure
(SP).

I set up a QueryDef as an SPT. Then in VBA code I set the .SQL property
of the QueryDef w/ the SP and its parameters. E.g.:

dim strSQL as string
dim db as dao.database
dim qd as dao.querydef

strSQL = "My_Procedure param1, param2"

set db = currentdb
set qd = db.querydefs("my query")
qd.sql = strSQL
qd.Execute

' or use a Recordset to get resultset from SP

dim rs as dao.recordset
set rs = qd.openrecordset()

You can connect to any ODBC database using ADO as long as you have that
database's ODBC driver. If that database has an OLEDB driver you can
use that. You can use the ADO Command object to set up the parameters
for a call to an SP. Read the Access Help articles on using ADO. The
Access Help Contents hierarchy is:

Microsoft ActiveX Data Objects (ADO)
Microsoft ActiveX Data Objects (ADO)
Microsoft ADO Programmer's Reference

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQlWCloechKqOuFEgEQJ+4ACePzoy+XHWDJtw/aCdyGBaK93O2QwAoNoI
EqIzWhaJLAe1/EWTJrwmKDgi
=uuqd
-----END PGP SIGNATURE-----
Zlatko Matić wrote:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the server ?
Is it possible to use parameters in pass-through queries ?

An additional question: Is it possible to connect to a database on MySQL or
PostgreSQL using ADO ?
Is it possible to execute pass-through queries with parameters, using ADO
command object ?

Nov 13 '05 #2
I didn't understand you exactly...
My concern is about how to execute a pass-through parameterized query from
Access front-end on MS SQL Server.
I successfully executed several queries without parameters, but don.t know
how to execute pass-through query with parameters.
For example, we have a stored procedure dbo.procedure1 with 3 input
parameters @param1,@param2,param3.
Lets say that the sql is "SELECT * from dbo.Table1 WHERE @param1=value1 and
@param2=value2 and @param3=value3". Instead of calling the procedure on the
server, I would like to have the SQL code on the front end. Therefore I need
some kind of pass-through query or some sql string that would be transfered
to the server.
I have also tried to execute the query using ADO command and Parameter's
object and query string (adCmdText), but the server asked parameters to be
declared inside the string. I put then "DECLARE @param1 type1, @param2
type2, @param3 type3" before the select statement in the string, but then
VBA said that the syntax is wrong. Now I don't know how to solve it...
Can I reference the name of the pass-through query in ADODB command object,
instead of using string and adCmdText ?
Does anyone has an idea how to execute a parameterized query on the SQL
Server, calling it from Access front-end ?
I know how to do it in Access Project, but don't know how to do it in
..mdb....
Please, either direct pass-through query either ADO...I don't like DAO.

Thanks.
You
"MGFoster" <me@privacy.com> je napisao u poruci interesnoj
grupi:oo*****************@newsread2.news.pas.earth link.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SQL Pass Through (SPT) queries are used in DAO .mdb files, only.

Sending parameters to an SPT means the SPT is calling a stored procedure
(SP).

I set up a QueryDef as an SPT. Then in VBA code I set the .SQL property
of the QueryDef w/ the SP and its parameters. E.g.:

dim strSQL as string
dim db as dao.database
dim qd as dao.querydef

strSQL = "My_Procedure param1, param2"

set db = currentdb
set qd = db.querydefs("my query")
qd.sql = strSQL
qd.Execute

' or use a Recordset to get resultset from SP

dim rs as dao.recordset
set rs = qd.openrecordset()

You can connect to any ODBC database using ADO as long as you have that
database's ODBC driver. If that database has an OLEDB driver you can
use that. You can use the ADO Command object to set up the parameters
for a call to an SP. Read the Access Help articles on using ADO. The
Access Help Contents hierarchy is:

Microsoft ActiveX Data Objects (ADO)
Microsoft ActiveX Data Objects (ADO)
Microsoft ADO Programmer's Reference

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQlWCloechKqOuFEgEQJ+4ACePzoy+XHWDJtw/aCdyGBaK93O2QwAoNoI
EqIzWhaJLAe1/EWTJrwmKDgi
=uuqd
-----END PGP SIGNATURE-----
Zlatko Matić wrote:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the server ?
Is it possible to use parameters in pass-through queries ?

An additional question: Is it possible to connect to a database on MySQL
or PostgreSQL using ADO ?
Is it possible to execute pass-through queries with parameters, using
ADO command object ?

Nov 13 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pass through queries (SPT) are run using DAO. If you use ADO it is NOT
an SPT. SPTs require a QueryDef, i.e., a DAO object in an .mdb file.

How to set up a QueryDef:

Open a new QueryDef in Design View.
- From the main menu select Query > SQL Specific > Pass through. The view
will change to the SQL view.
Put some junk phrase in the SQL view - this will be replaced in the
following steps.
Save this QueryDef w/ a name like "mySPT."
Look at the VBA code in my original posting. Substitue "mySPT" for
"My_Procedure."
Put your parameter values in place of "param1" and "param2" and add your
3rd parameter value.
Run the code. The SPT will execute the procedure on SQL Server.

How to run a stored procedure (SP) using ADO. The SP doesn't return any
records. Set up a Command object "cmd" and do this:

cmd.CommandText = "mySPT 'param1', param2"
cmd.CommandType = adCmdStoredProc
cmd.Execute

' or, if the SP returns records - not updateable.
' To open an updateable recordset use the recordset's Open method.
' AFAIK, SP recordsets are not updateable, i.e., Read Only.

Set rs = cmd.Execute

Substitute your SP's name for "mySPT," and your parameter values for
'param1' and param2, and, again, add your 3rd parameter. Param1 is a
string value; param2 is a numeric value - change to suit your needs.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQla5VYechKqOuFEgEQJluwCfSEXmZEJmtsJ7e4o9RPGUts 07DeEAoOMP
iAYniMgHESoxdP5tP952unVR
=1oss
-----END PGP SIGNATURE-----

Zlatko Matic wrote:
I didn't understand you exactly...
My concern is about how to execute a pass-through parameterized query from
Access front-end on MS SQL Server.
I successfully executed several queries without parameters, but don.t know
how to execute pass-through query with parameters.
For example, we have a stored procedure dbo.procedure1 with 3 input
parameters @param1,@param2,param3.
Lets say that the sql is "SELECT * from dbo.Table1 WHERE @param1=value1 and
@param2=value2 and @param3=value3". Instead of calling the procedure on the
server, I would like to have the SQL code on the front end. Therefore I need
some kind of pass-through query or some sql string that would be transfered
to the server.
I have also tried to execute the query using ADO command and Parameter's
object and query string (adCmdText), but the server asked parameters to be
declared inside the string. I put then "DECLARE @param1 type1, @param2
type2, @param3 type3" before the select statement in the string, but then
VBA said that the syntax is wrong. Now I don't know how to solve it...
Can I reference the name of the pass-through query in ADODB command object,
instead of using string and adCmdText ?
Does anyone has an idea how to execute a parameterized query on the SQL
Server, calling it from Access front-end ?
I know how to do it in Access Project, but don't know how to do it in
.mdb....
Please, either direct pass-through query either ADO...I don't like DAO.

Thanks.
You
"MGFoster" <me@privacy.com> je napisao u poruci interesnoj
grupi:oo*****************@newsread2.news.pas.earth link.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SQL Pass Through (SPT) queries are used in DAO .mdb files, only.

Sending parameters to an SPT means the SPT is calling a stored procedure
(SP).

I set up a QueryDef as an SPT. Then in VBA code I set the .SQL property
of the QueryDef w/ the SP and its parameters. E.g.:

dim strSQL as string
dim db as dao.database
dim qd as dao.querydef

strSQL = "My_Procedure param1, param2"

set db = currentdb
set qd = db.querydefs("my query")
qd.sql = strSQL
qd.Execute

' or use a Recordset to get resultset from SP

dim rs as dao.recordset
set rs = qd.openrecordset()

You can connect to any ODBC database using ADO as long as you have that
database's ODBC driver. If that database has an OLEDB driver you can
use that. You can use the ADO Command object to set up the parameters
for a call to an SP. Read the Access Help articles on using ADO. The
Access Help Contents hierarchy is:

Microsoft ActiveX Data Objects (ADO)
Microsoft ActiveX Data Objects (ADO)
Microsoft ADO Programmer's Reference

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQlWCloechKqOuFEgEQJ+4ACePzoy+XHWDJtw/aCdyGBaK93O2QwAoNoI
EqIzWhaJLAe1/EWTJrwmKDgi
=uuqd
-----END PGP SIGNATURE-----
Zlatko Matić wrote:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the server ?
Is it possible to use parameters in pass-through queries ?

An additional question: Is it possible to connect to a database on MySQL
or PostgreSQL using ADO ?
Is it possible to execute pass-through queries with parameters, using
ADO command object ?


Nov 13 '05 #4
Bri
Your original message sounded like you wanted to use parameters in the
passthrough itself, not in an SP on the server. MGFoster answered the
question based on that (ie create an SQL string and make it the .SQL
property of an existing saved passthrough query).

If you are wanting to use the passthrough to execute an SP with
parameters then just set the SQL of the passthrough to:
Execute MySP "param1", "Param2"

--
Bri

Zlatko Matic wrote:
I didn't understand you exactly...
My concern is about how to execute a pass-through parameterized query from
Access front-end on MS SQL Server.
I successfully executed several queries without parameters, but don.t know
how to execute pass-through query with parameters.
For example, we have a stored procedure dbo.procedure1 with 3 input
parameters @param1,@param2,param3.
Lets say that the sql is "SELECT * from dbo.Table1 WHERE @param1=value1 and
@param2=value2 and @param3=value3". Instead of calling the procedure on the
server, I would like to have the SQL code on the front end. Therefore I need
some kind of pass-through query or some sql string that would be transfered
to the server.
I have also tried to execute the query using ADO command and Parameter's
object and query string (adCmdText), but the server asked parameters to be
declared inside the string. I put then "DECLARE @param1 type1, @param2
type2, @param3 type3" before the select statement in the string, but then
VBA said that the syntax is wrong. Now I don't know how to solve it...
Can I reference the name of the pass-through query in ADODB command object,
instead of using string and adCmdText ?
Does anyone has an idea how to execute a parameterized query on the SQL
Server, calling it from Access front-end ?
I know how to do it in Access Project, but don't know how to do it in
.mdb....
Please, either direct pass-through query either ADO...I don't like DAO.

Thanks.
You
"MGFoster" <me@privacy.com> je napisao u poruci interesnoj
grupi:oo*****************@newsread2.news.pas.earth link.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SQL Pass Through (SPT) queries are used in DAO .mdb files, only.

Sending parameters to an SPT means the SPT is calling a stored procedure
(SP).

I set up a QueryDef as an SPT. Then in VBA code I set the .SQL property
of the QueryDef w/ the SP and its parameters. E.g.:

dim strSQL as string
dim db as dao.database
dim qd as dao.querydef

strSQL = "My_Procedure param1, param2"

set db = currentdb
set qd = db.querydefs("my query")
qd.sql = strSQL
qd.Execute

' or use a Recordset to get resultset from SP

dim rs as dao.recordset
set rs = qd.openrecordset()

You can connect to any ODBC database using ADO as long as you have that
database's ODBC driver. If that database has an OLEDB driver you can
use that. You can use the ADO Command object to set up the parameters
for a call to an SP. Read the Access Help articles on using ADO. The
Access Help Contents hierarchy is:

Microsoft ActiveX Data Objects (ADO)
Microsoft ActiveX Data Objects (ADO)
Microsoft ADO Programmer's Reference

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQlWCloechKqOuFEgEQJ+4ACePzoy+XHWDJtw/aCdyGBaK93O2QwAoNoI
EqIzWhaJLAe1/EWTJrwmKDgi
=uuqd
-----END PGP SIGNATURE-----
Zlatko Matić wrote:
Let's assume that we have a database on some SQL server (let it be MS SQL
Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the server ?
Is it possible to use parameters in pass-through queries ?

An additional question: Is it possible to connect to a database on MySQL
or PostgreSQL using ADO ?
Is it possible to execute pass-through queries with parameters, using
ADO command object ?


Nov 13 '05 #5
Hello.

Thank you for suggestions, but I knpow hoe to execute stored procedures
placed on SQL Server. It's quite easy by using ADO...
But I want to have saved pass-through query on the front-end, in order to
have all the code on the front-end.
My problem is how to pass parameters to parameterized pass-through query
dynamically. It means I have a pass-through query with several parameters
(@param1, @param2, @param3 etc...) that are changing every time the
pass-through query is executed. These parameters are referenced to controls
on some forms.
When I was working in .adp, I was using Input Parameters property of forms
and reports to pass such referenced values, but in .mdb there is no such
property. In regular JET queries you can reference controls in queries
directly . But, how to solve it in PASS-THROUGH QUERIES ????
I suppose that it would be possible to acomplish the task by query string in
ADO (adCmdText),and to break the string in order to insert some variable
that would be references to the form control...but it seems to be complex to
write the code and I would like to avoid such strings, because thar is a
beautifull container that is called pass-through query and I would like to
use it.
I was searching a lot on the internet also, and couldn't find anything
specific concernig this issue...
Am I missing something, or it is impossible to use parameters in
pass-through queries ?
"Bri" <no*@here.com> je napisao u poruci interesnoj
grupi:ELA5e.927774$Xk.356022@pd7tw3no...
Your original message sounded like you wanted to use parameters in the
passthrough itself, not in an SP on the server. MGFoster answered the
question based on that (ie create an SQL string and make it the .SQL
property of an existing saved passthrough query).

If you are wanting to use the passthrough to execute an SP with parameters
then just set the SQL of the passthrough to:
Execute MySP "param1", "Param2"

--
Bri

Zlatko Matic wrote:
I didn't understand you exactly...
My concern is about how to execute a pass-through parameterized query
from Access front-end on MS SQL Server.
I successfully executed several queries without parameters, but don.t
know how to execute pass-through query with parameters.
For example, we have a stored procedure dbo.procedure1 with 3 input
parameters @param1,@param2,param3.
Lets say that the sql is "SELECT * from dbo.Table1 WHERE @param1=value1
and @param2=value2 and @param3=value3". Instead of calling the procedure
on the server, I would like to have the SQL code on the front end.
Therefore I need some kind of pass-through query or some sql string that
would be transfered to the server.
I have also tried to execute the query using ADO command and Parameter's
object and query string (adCmdText), but the server asked parameters to
be declared inside the string. I put then "DECLARE @param1 type1, @param2
type2, @param3 type3" before the select statement in the string, but then
VBA said that the syntax is wrong. Now I don't know how to solve it...
Can I reference the name of the pass-through query in ADODB command
object, instead of using string and adCmdText ?
Does anyone has an idea how to execute a parameterized query on the SQL
Server, calling it from Access front-end ?
I know how to do it in Access Project, but don't know how to do it in
.mdb....
Please, either direct pass-through query either ADO...I don't like DAO.

Thanks.
You
"MGFoster" <me@privacy.com> je napisao u poruci interesnoj
grupi:oo*****************@newsread2.news.pas.earth link.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

SQL Pass Through (SPT) queries are used in DAO .mdb files, only.

Sending parameters to an SPT means the SPT is calling a stored procedure
(SP).

I set up a QueryDef as an SPT. Then in VBA code I set the .SQL property
of the QueryDef w/ the SP and its parameters. E.g.:

dim strSQL as string
dim db as dao.database
dim qd as dao.querydef

strSQL = "My_Procedure param1, param2"

set db = currentdb
set qd = db.querydefs("my query")
qd.sql = strSQL
qd.Execute

' or use a Recordset to get resultset from SP

dim rs as dao.recordset
set rs = qd.openrecordset()

You can connect to any ODBC database using ADO as long as you have that
database's ODBC driver. If that database has an OLEDB driver you can
use that. You can use the ADO Command object to set up the parameters
for a call to an SP. Read the Access Help articles on using ADO. The
Access Help Contents hierarchy is:

Microsoft ActiveX Data Objects (ADO)
Microsoft ActiveX Data Objects (ADO)
Microsoft ADO Programmer's Reference

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQlWCloechKqOuFEgEQJ+4ACePzoy+XHWDJtw/aCdyGBaK93O2QwAoNoI
EqIzWhaJLAe1/EWTJrwmKDgi
=uuqd
-----END PGP SIGNATURE-----
Zlatko Matić wrote:

Let's assume that we have a database on some SQL server (let it be MS
SQL Server) and that we want to execute some parameterized query as a
pass.through query. How can we pass parameters to the server ?
Is it possible to use parameters in pass-through queries ?

An additional question: Is it possible to connect to a database on MySQL
or PostgreSQL using ADO ?
Is it possible to execute pass-through queries with parameters, using
ADO command object ?



Nov 13 '05 #6
Zlatko Matic wrote:
Hello.

Thank you for suggestions, but I knpow hoe to execute stored
procedures placed on SQL Server. It's quite easy by using ADO...
But I want to have saved pass-through query on the front-end, in order to have
all the code on the front-end.
My problem is how to pass parameters to parameterized pass-through
query dynamically. It means I have a pass-through query with several
parameters (@param1, @param2, @param3 etc...) that are changing every
time the pass-through query is executed. These parameters are
referenced to controls on some forms.
When I was working in .adp, I was using Input Parameters property of
forms and reports to pass such referenced values, but in .mdb there
is no such property. In regular JET queries you can reference
controls in queries directly . But, how to solve it in PASS-THROUGH
QUERIES ???? I suppose that it would be possible to acomplish the task by
query
string in ADO (adCmdText),and to break the string in order to insert
some variable that would be references to the form control...but it
seems to be complex to write the code and I would like to avoid such
strings, because thar is a beautifull container that is called
pass-through query and I would like to use it.
I was searching a lot on the internet also, and couldn't find anything
specific concernig this issue...
Am I missing something, or it is impossible to use parameters in
pass-through queries ?


I just change the SQL of the pass-through's QueryDef so it includes the hard
coded parameter values and then execute it. Works fine for me.

--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #7
Bri
Hi,

Passthrough queries do not have Parameters as they are 'Passed Through'
directly to the server. The only way I know of to do what you want is to
build the SQL of the Passthrough query as a string and then change the
..SQL property of the query. Once you change the .SQL Property then you
can do any of the DAO query operations you want. The SQL you build can
be either a string with the Execute command (run a SP on the BE) or with
the actual T-SQL you want to run (still runs on BE but all the logic is
stored in the FE). You were given examples of these in previous posts.
What difference does it make if you modify the .Parameters Property or
the .SQL Property of the stored query before you work with it?

--
Bri

Zlatko Matic wrote:
Hello.

Thank you for suggestions, but I knpow hoe to execute stored procedures
placed on SQL Server. It's quite easy by using ADO...
But I want to have saved pass-through query on the front-end, in order to
have all the code on the front-end.
My problem is how to pass parameters to parameterized pass-through query
dynamically. It means I have a pass-through query with several parameters
(@param1, @param2, @param3 etc...) that are changing every time the
pass-through query is executed. These parameters are referenced to controls
on some forms.
When I was working in .adp, I was using Input Parameters property of forms
and reports to pass such referenced values, but in .mdb there is no such
property. In regular JET queries you can reference controls in queries
directly . But, how to solve it in PASS-THROUGH QUERIES ????
I suppose that it would be possible to acomplish the task by query string in
ADO (adCmdText),and to break the string in order to insert some variable
that would be references to the form control...but it seems to be complex to
write the code and I would like to avoid such strings, because thar is a
beautifull container that is called pass-through query and I would like to
use it.
I was searching a lot on the internet also, and couldn't find anything
specific concernig this issue...
Am I missing something, or it is impossible to use parameters in
pass-through queries ?
"Bri" <no*@here.com> je napisao u poruci interesnoj
grupi:ELA5e.927774$Xk.356022@pd7tw3no...
Your original message sounded like you wanted to use parameters in the
passthrough itself, not in an SP on the server. MGFoster answered the
question based on that (ie create an SQL string and make it the .SQL
property of an existing saved passthrough query).

If you are wanting to use the passthrough to execute an SP with parameters
then just set the SQL of the passthrough to:
Execute MySP "param1", "Param2"

--
Bri

Nov 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by z_learning_tester | last post: by
3 posts views Thread by Brett | last post: by
6 posts views Thread by lisp9000 | last post: by
15 posts views Thread by ramif | 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.