简体   繁体   中英

MS Access Pass-Through Query With "Returns Records: No" Truncates ODBC Connect Str

This is a very strange one and I can't seem to find anyone else on the web who's experienced it, but I'm attempting to run an SQL Server UPDATE stored procedure (returns 0 records) via an MS Access 2010 pass-through query, but when I set Returns Records: No it appears to truncate my ODBC Connect String and throws an error!

(sanitised strings in parens, no parens used in actual string)

ODBC Connect Str: ODBC;DSN=(dsn name);Description=(description);Trusted_Connection=Yes;DATABASE=(example database name)

First, setting Returns Records: Yes allows the query to execute successfully (confirmed through SQLServer Mgt Studio) but throws error: Pass-through query with ReturnsRecords property set to True did not return any records.

Then setting Returns Records: No throws error The Microsoft Access database engine cannot find the input table or query 'ODBC;DSN=(dsn name);Description=(description);Trusted_Connection=Yes;DA'. Make sure it exists and that its name is spelled correctly. The Microsoft Access database engine cannot find the input table or query 'ODBC;DSN=(dsn name);Description=(description);Trusted_Connection=Yes;DA'. Make sure it exists and that its name is spelled correctly.

Because it probably matters, my DSN is 8 chars long, Description is 8 chars, and Database is 21 chars. I don't think they're excessively long, and the DB is in production and used by several clients, so changing / shortening them at this point is infeasible.

Has anyone else experienced this or can anyone else reproduce?

I've heard that MS Access has a built in hard limit of 255 chars for the ODBC connect str, but mine is certainly <100!

I have a saved query called qryPass . It is set to return records = no.

To use the above, in code we can go:

With CurrentDb.QueryDefs("qryPass")
  .SQL = "Exec myStoreProc"
  .Execute
End With

In above I of course provide the pass-though sql, but if you not needing to provide the SQL/t-SQL on the fly then you can run the above saved pass-though like this:

CurrentDb.QueryDefs("qryPass").Execute

Since you not provided the 2-3 lines of code as to how you call this stored procedure, then we can only guess as to your issues. However try the above approach.

Also before running the query in code, use 100% the UI, create the PT query and try running it (with returns records = no).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM