Copying SQL Server query results into an Access 2010 table - sql-server-2008

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

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

Renaming ODBC query calls

I have an old VB6 application which we do not have source code to edit. The application tries to open a table to a server but the table name has a period on it because the old provider allowed periods on table names. Now, we are trying to make a workaround using an MS ACCESS table. Problem is MS ACCESS do not allow periods on table names.
Our problem is that the VB6 application will request table name MAINDIR.ITEMSTABLE and it will return a TABLE NOT FOUND error because the table or query cannot be named on MS ACCESS with a period. Is there a way that we can do a VBA function that will trigger when an external ODBC call is made to the database that will see the incoming query and replace the table name? Like for example if th VB6 application sends an SQL query like:
SELECT * FROM DBNAME.TABLENAME
how can I make it refer (or modify the query) so that it returns
SELECT * FROM DBNAME_TABLENAME?
Thank you all for your help.

Automatic Information Transfer Between Databases

I have an application which uses an Access Database to store records. This application is a third party application and cannot be altered but I do have the ability to open the database and view all the records it creates.
What I would like to know is this - Is there a way to tell Access to send new records to a table in a SQL database when the record is created in Access. This needs to be done without any user intervention. In the perfect world this application would talk directly to SQL, but I would settle for a less than perfect world if the software continues to talk to Access and then Access talks to SQL.
Access 2010 did introduce event-driven data macros which behave like triggers. An After Insert data macro can create records in another local Access table, but unfortunately
Queries that contain linked tables, action queries, and database references are not allowed in data macros.
so you cannot use an After Insert data macro in Access to "push" new records into a linked SQL Server table.
However, you could use a scheduled job in SQL Server to "pull" new records from an Access database that has been set up as a Linked Server in SQL Server. For example, say we had a table named [Inquiries] in Access
ID - Autonumber (Incrementing), Primary Key
InquiryDate - Date/Time
ContactName - Text(255)
and a corresponding [dbo].[Inquiries] table in SQL Server
ID - int, Primary Key
InquiryDate - datetime
ContactName - nvarchar(255)
We could set up the Access database as a Linked Server named ACCDBDATA in SQL Server and then have SQL Server run a scheduled job every so often to pull new records from the Access database using a T-SQL statement like this
INSERT INTO dbo.Inquiries (ID, InquiryDate, ContactName)
SELECT ID, InquiryDate, ContactName
FROM ACCDBDATA...Inquiries
WHERE ID > (SELECT ISNULL(MAX(ID),0) FROM dbo.Inquiries)

SSIS Data Source select all from table store in variable

I am working with a SQL Server 2008 R2 BIDS 2008 solution.
I need to transfer data from an Oracle(11g) source database to a SQL Server database. I need to copy all data from multiple tables in the Oracle database. I have a ForEach container in which there is one Data Flow Task.
I want to loop round a list of table names, select all columns out of in the Oracle source and copy to dest_ in the SQL Server.
I have added a Property Expression to the Data Flow Task for [ADO NET Source].[SqlCommand] with an expression of "SELECT * FROM " + #[User::ImportPath]
As the table is undefined at this point it isn't clear if I can map columns or setup the ADO NET Destination task correctly.
Is there steps I am missing? Is what I am attempting to do even possible?
You cant loop through tables and dinamically map columns on your source and destinations components. You would need one set of Source -> Ddestination per table.
If that's not feasible, you may want to lokk at the Transfer SQL Server Objects Task

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