Re: can't get query to run over ADO, but works fine in Access interfac
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 7 Jan 2006 23:54:08 -0600
Hi,
If an SQL statement runs in Query Analyzer (or some other interface), you
should be able to execute it using an ADO Command object. However, the
statement must be assigned to the CommandText property of the Command object
as a string. It can be difficult to convert a statement to a string,
complete with line continuations. Is this the problem? If I were to run this
with ADO, I would use something similar to (in part):
adoCommand.CommandText = "INSERT INTO PersonsToOrganizations " _
& "( OrgID, ID, [Position] ) " _
& "SELECT Q1.OrgID, Q1.ID, Q1.Position " _
& "FROM (SELECT PM1.IDMstPerson AS OrgID, PM.IDMstPerson AS ID,
P2O1.Position AS Position " _
& "FROM (([Src00001] AS S " _
& "INNER JOIN PersonMatch AS PM " _
& "ON S.ID = PM.IDSrcPerson) "
.... etc, etc.
As I say, this often introduces errors. You have to get the commas and
spaces right. I use line continuations so I can read the command without
scrolling. Note that the string can also be passed as a parameter to the
Execute method of the ADO Connection object, but the issue is the same - you
have to enclose it is quotes.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
"Joe" <Joe@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C69FF5DB-7A2C-41E2-8246-AF45D3E6E717@xxxxxxxxxxxxxxxx
> The following query runs fine if created in the interface, but cannot be
> executed over an ado connection. Error is -2147467259, Automation error,
> Unspecified Error. The connection error object has no description. I've
> also
> tried to use adox to store it and to store it manually as a test in a
> query
> but get the same error when trying to save over adox or run over ado. As
> the
> query is generated in code and refers to dynamically created and named
> tables, I don't know how to convert it to a parameterized query (table
> names
> can't be parameters so far as I know). To reiterate: pasting the text into
> a
> query in the interface results in a query that can be stored and run from
> the
> interface but not run as a stored procedure over ADO connection. What's
> going
> on, and how can I work around this?
>
> INSERT INTO PersonsToOrganizations ( OrgID, ID, [Position] ) SELECT
> Q1.OrgID, Q1.ID, Q1.Position FROM (SELECT PM1.IDMstPerson AS OrgID,
> PM.IDMstPerson AS ID, P2O1.Position AS Position FROM (([Src00001] AS S
> INNER
> JOIN PersonMatch AS PM ON S.ID = PM.IDSrcPerson) INNER JOIN
> PersonsToOrganizations_00001 AS P2O1 ON S.ID = P2O1.ID) LEFT JOIN
> PersonMatch
> AS PM1 ON P2O1.OrgID = PM1.IDSrcPerson WHERE (((PM1.IDSrcPerson) Is Not
> Null)
> AND ((PM1.IDSource)=1) AND ((PM1.IDMaster)=0) AND ((PM.IDSource)=1) AND
> ((PM.IDMaster)=0) AND ((PM.Status)>=50) AND ((S.MADEStatus)>=50) AND
> ((PM1.Status)>=50))) AS Q1 LEFT JOIN PersonsToOrganizations ON
> (Q1.Position =
> PersonsToOrganizations.Position) AND (Q1.ID = PersonsToOrganizations.ID)
> AND
> (Q1.OrgID = PersonsToOrganizations.OrgID) WHERE
> (((PersonsToOrganizations.OrgID) Is Null));
.
- Follow-Ups:
- Prev by Date: Re: ado error and on error statement in vba
- Next by Date: Re: can't get query to run over ADO, but works fine in Access inte
- Previous by thread: Re: ado error and on error statement in vba
- Next by thread: Re: can't get query to run over ADO, but works fine in Access inte
- Index(es):
Relevant Pages
- Re: Handle double quote in VB for MS Access
... Build a Command object with parameters and let ADO figure out the framing ...
> If I use the following query in VB, on execution of ... (microsoft.public.data.ado) - Re: Inserting Records Into Access Table via DAO
... > I'm used to using the command object in ADO to insert records into an SQL ...
Another way is to use the RunSQL command object. ... Dim iIntVal as integer ...
The downside is that the query will not be optimized. ... (microsoft.public.access.modulesdaovba) - Re: Trying to import several million rows- help!
... > interface. ... You may be able to use ADO to query the text
file to get meaningful ... Row-by-row processing must surely be impractical. ...
(microsoft.public.excel.worksheet.functions) - Re: Command Object and IColumnsRowset
... Set DBPROP_IColumnsRowset to trur for command object ... CComQIPtr< IColumnsRowset>
pMyColumnInfo = ... is Query the Interface of a Recordset or Command Object from ADO and
... that there are dynamic properties that return tree for the ADO Command ... (microsoft.public.data.oledb) - RE: ODBC query in VB code Need HELP
... Everything for ADO is in the first 2 messages that I gave you. ... Since your
pass-through query already exists (including the ... Dim STRSQL As String
... (microsoft.public.access.formscoding)