Calling MS Access Stored Queries with Parameters using DAAB v5.0 - ms-access

I wanted to find out if it is possible to call MS Access Stored Queries with parameters using DAAB.
I am using the Northwind sample database to test this scenario I have created the following Stored Query with parameter in MS Access:
PARAMETERS FirstName Text ( 255 );
SELECT Employees.ID
FROM Employees
WHERE (((Employees.[First Name])=[#FirstName]));
This query is stored with name: GetEmployeeIDByName
I have created a wrapper over the DAAB to allow access to various databases like SQL, Oracle, any OLEDB and and ODBC database.
Below is the sample code for my test:
Database db = new GenericDatabase("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Database\Access\Northwind 20071.accdb",OleDbFactory.Instance);
DbCommand cmd = db.GetStoredProcedure("GetEmployeeIDByName");
db.AddInParameter(cmd,"#FirstName",DbType.String,40);
object employeeID = db.ExecuteScalar();
I get an error Invalid Operation. I am not sure if I am calling the stored Queries correctly as I am able to call Stored Queries that do not have any parameter without any errors.

I was able to resolve the issue. The issue was with the Northwind sample database. I then imported Northwind database from SQL Server into MS Access and also created the stored queries in MS Access. Here is the detailed discussion that I had with the Enterprise Library DAAB's team: entlib.codeplex.com/Thread/View.aspx?ThreadId=223653 Hope it helps. Access does not care about the # character you can call the parameter with or without the # character.

Related

The Microsoft Access database engine cannot find the input table or query on a local query against linked tables

I am trying to execute a SQL Select query that references linked tables in a backend database.
The query that I am trying to execute is saved as a query in the front-end database named: HourlyDistinctMonitoringDates.
HourlyDistinctMonitoringDates is defined as:
SELECT DISTINCT JobInstrumentId,
DATEVALUE(decibellog.readingdate) AS MonitoringDate,
HOUR(decibellog.readingtime) AS MonitoringHour
FROM jobinstrumentimport INNER JOIN decibellog ON jobinstrumentimport.id = decibellog.jobinstrumentimportid;
The decibellog and jobinstrumentimport tables reside in a back-end (split) database.
If I execute the HourlyDistinctMonitoringDates in a SQL View in Access from the front-end, it executes without any problem.
If I execute the SQL Command that is built by my VBA in a SQL View in Access from the front-end, it executes without any problem.
However, when I try to execute the following code; I obtain error 3078:
The Microsoft Access database engine cannot find the input table or query on a local query against linked tables...
distinctDaysAndHours = "SELECT * FROM HourlyDistinctMonitoringDates WHERE jobinstrumentid=" & rstJobInstruments!id
Set rstDistinctDatesHours = CurrentDb.OpenRecordset(distinctDatesAndHours)
When executed in VBA, the string: distinctDaysAndHours contains a SQL command such as:
SELECT * FROM HourlyDistinctMonitoringDates WHERE jobinstrumentid=10
This command will execute if pasted into the SQL View in the Access Query Design.
So the problem is obviously in the use of:
CurrentdB.OpenRecordset
The query residing in the front-end instead of the back-end.
Possibly both?
Since you have an error number, your answer is nearby
check microsoft website
https://learn.microsoft.com/en-us/office/troubleshoot/access/database-engine-not-find-input-table

MS Access and Stored Procedures

Does MS Access support stored procedures on .accdb or .mdb databases? Or are stored procedures only supported when the backend is SQL Server or something else that supports an Access DB engine (Jet / ACE/ MSDE)?
Information is mixed and not quite complete from what I have found on MS Access and Stored Procedures from various sources. For example this Access help file initially looks like Access supports stored procedures.
https://support.microsoft.com/en-us/office/create-procedure-statement-91c700d1-8076-4040-896a-a0b7cf9d9888?ns=msaccess&version=90&ui=en-us&rs=en-us&ad=us
When I try to run the following query, it errors saying I have incorrect syntax for CREATE TABLE statement. The table is in an .accdb file on my local laptop.
CREATE PROCEDURE GetReport (pFileId Integer)
AS
SELECT * FROM FileInfoTable WHERE FileId = pFileId
Some Access DDL features are only available when the statement is executed with ADO. Your statement will succeed if you execute it from CurrentProject.Connection.Execute as this Immediate window example demonstrates:
strSql = "CREATE PROCEDURE GetReport (pFileId Integer)" & vbCrLf & _
"AS" & vbCrLf & _
"SELECT * FROM FileInfoTable WHERE FileId = pFileId"
CurrentProject.Connection.Execute strSql
However notice that the SQL text in the saved query object does not exactly match the text in the CREATE PROCEDURE statement. But I think it's functionally equivalent.
Debug.Print CurrentDb.QueryDefs("GetReport").SQL
PARAMETERS pFileId Long;
SELECT *
FROM FileInfoTable
WHERE FileId = pFileId;
Well, yes, access does have what is called table triggers, and access also has what we call stored procedures (procedural code that can run at the table level - or in fact you can even call such stored procedures from VBA, or macros).
However, just like MySQL, SQL server, Oracle and more? They ALL HAVE their OWN type of code system for these stored procedures. Access is no different.
This feature and ability was introduced in Access 2010. However, this feature, this ability has ZERO to do with the SQL supported CREATE procedure command.
That command was introduced to give "some" compatibility with SQL Server syntax - but it is quite lame, and limited. WHEN you use CREATE PROCEDURE in Access SQL, it ONLY creates a select command. As such, the select command is JUST THAT - ONLY a select command and is NOT procedural code.
However, as noted, you can write stored procedures in Access, and they run by the data engine, and they run at engine level. To write these routines, you have to use the macro language. This language is NOT VBA, and not T-SQL (SQL Server code), but Access has its OWN syntax and code.
These so called table routines are thus created when working on a table in design mode.
While such code is limited, it is REAL procedural code, does not use SQL syntax in most cases, and such routines can be called from table events.
And these so called "data macros" are not created with SQL data create commands, you are limited to using the built in macro editor for this purpose.
Keep in mind that while Access has this stored procedure code ability, they are not transaction based. But, they can be of GREAT use, since they even function when using OLEDB or ODBC sources to Access.
So, if you write such code, and then say open Access with FoxPro, or even c# in .net? And then you update a row? The procedural table code and triggers WILL run.
You can see these options here:
So, I could for example maintain the total cost of an invoice for each change, or edit, or adding of rows to a sub form.
The macro language editor looks like say this:
So you can loop over data, you have if/then else etc.
It is a very limited language - but they are in fact true real stored procedure code that runs at the table level, and they run 100% independent of VBA or any other code.
And these table stored procedures run:
when edit data in a form - even forms without code
when you issue SQL update or modify statements
when you modify data via VBA + recordset code
if an external ODBC or OLEDB source such as .net c# or whatever modifies data

Query to transfer from ODBC

I have a database connection using ODBC.. i want to write a query to transfer all tables and columns to export the data in DOMO..
select* from database ()
Can someone help in a query where i can replace only with the new data?
Assuming the ODBC database connection has been made (using Domo workbench or cloud connector) and the data is present in Domo, you can add a transform (in MySql or Redshift - refer screenshot), in which you can write your query [select * from database].
Once you have finished writing your transform(s), you can 'Add Output Dataset' (see screenshot) to extract the data.Screenshot

Copying SQL Server query results into an Access 2010 table

Monthly, I need to get "new" data from our SQL Server business application into an Access 2010 database that contains all our "Management Reports". The Access database has a "staging table" that is to contain the raw data on which the reports are based.
I have no Access experience, but I suggested that we:
Write a query (stored proc?) on our SQL Server that returns the required raw data (...this bit was easy.)
At the end of each month, call the SQL Server stored proc from within Access 2010 (...click a button?)
Save the results of the stored proc into the staging table within Access.
But I'm finding it harder than I expected. I think I can get something ugly working using ADODB in a code-behind, looping through rows in a recordset one by one, and then setting column values one by one. But there must be a better way :)
How should I go about getting SQL Server data from Access 2010? (ADODB? DAO? QueryDesigner? other?)
Is there a "Insert Recordset Into Table" (or similar) mechanism that I can leverage?
Link the relevant sql server table or view to MS Access. Run a query against the linked table using MS Access syntax and update the staging table.
It is also possible to update an MS Access table using a connection string for SQL Server in-line in your query.
SELECT *
INTO newtable
FROM [odbc;filedsn=Z:\DSN\test.dsn].table1
Working from the SQL Server end, you can use MS Access as a linked server or run a query and update from there.
INSERT INTO
OPENDATASOURCE(
'Microsoft.ACE.OLEDB.12.0', 'Data Source=z:\docs\test.accdb')...[table1]
( atext )
SELECT atext FROM table1 WHERE id=2

SSIS Query Parameters for ADO .NET Source

I am trying to retieve data from a MySQL table and insert into a SQL Server table using ADO .NET connections in SQL Server 2008 SSIS. In my data flow task I have an ADO .NET Source which queries the MySQL table (select all invoices) and an ADO .NET Destination which inserts the data in my SQL Server table. Now, I would like to add a parameter in my data source so that I only select the max(invoiceNumber) retrieved from my SQL Server table. I have performed a similar task using "OLE DB Command" but the problem is that I need to query a MySQL database. Any ideas how I can achieve this?
I found that the only way to use parameter with the ADO.NET Data Source is this workaround:
Go to the Flow Control and selenct the Activity Flow containing your ADO.NET source.
In the properties window you can see the ADO.NET source Sql Command
Go to expression and select the properties: [YOU SOURCE NAME].[SqlCommand] and then edit the expression using variables to simulate parameters
Set Data Access Mode in ADO.NET Source to SQL Command and write the query.
You shoudn't have to add a parameter:
select *
from invoices
where invoiceNumber = (select max(invoiceNumber) from invoices)
The above works in SQL Server. I'm assuming that the same query will work in MySQL