0

Is this possible programmatically? Getting the names of stored queries or checking if a query with a specific name exists?

5
  • WHy not SELECT * FROM <stored-query-name> LIMIT 1 and see if it errors out? Commented Jan 10, 2012 at 9:27
  • Sure why not! Db newb here :) Commented Jan 10, 2012 at 9:32
  • @Eugen Rieck You reckon that will work with MS Access? Commented Jan 10, 2012 at 10:36
  • @Remou why shouldn't it? Commented Jan 10, 2012 at 11:08
  • 1
    @Eugene Access does not have LIMIT 1 and you cannot select from action queries, so I cannot see how it would work. Commented Jan 10, 2012 at 11:21

3 Answers 3

2

Use OleDbConnection.GetOleDbSchemaTable Method.

OleDbConnection connection = new OleDbConnection(@"connection_string");
connection.Open();
DataTable schemaTable = connection.GetOleDbSchemaTable(
         OleDbSchemaGuid.Tables,
           new object[] { null, null, null, "VIEW" });
foreach (DataRow row in schemaTable.Rows )
{
    Console.WriteLine(row["TABLE_NAME"]);
}
Sign up to request clarification or add additional context in comments.

2 Comments

This will return only select queries, you will need OleDbSchemaGuid.Procedures (PROCEDURE_NAME) for action queries (add, update, append etc). Ref: msdn.microsoft.com/en-us/library/…
I only have select stored queries in my db but thanks for making that clear.
0

You can query Procedures table to get all stored procedures

ProcedureName field contains the name of the procedure

1 Comment

It's an access 97' database (yeah I know). Stored procedures have been available from 2000 and later. Sorry for not making that clear in my first post.
0

You can also use the undocumented but much-used MSysObjects table:

SELECT [Name]
FROM [MSysObjects]
WHERE [Type] = 5

This will include any system queries created by Access for combo boxes, list boxes, and subforms. They all start with a tilde, so you can exclude them like this:

SELECT [Name]
FROM [MSysObjects]
WHERE [Type] = 5
    AND [Name] NOT LIKE "~*"

1 Comment

You can often find that access to system tables is not allowed (permissions), and it is tedious in the extreme to find a solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.