Automatic Information Transfer Between Databases - sql-server-2008

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)

Related

SQL Server rows not editable for Access after Insert

I have this problem: I'm using a SQL Server 2008R2 backend and MS Access 2000 frontend where some tables are connected via ODBC.
Following Structure (Tables all on SQL-Server):
Import (not connected to Access)
Products (connected via ODBC to Access)
Pricing (connected via ODBC to Access)
I want to fill the Pricing table automatically with some data from Products and Import. This is supposed to run as a SQL Agent job with a T-SQL script.
I want to insert the data from "Products" with following command:
INSERT INTO Pricing (Productnr, Manufacturernr)
(SELECT Productnr, Manufacturernr
FROM Products
WHERE Valid = 1
AND Productnr NOT IN (SELECT Productnr FROM Pricing ));
Right after that the inserted rows are locked for Access, I can't change anything. If I execute sql queries with SQL Server Management Suite or if i start queries as SQL Agent jobs everything works fine.
Why are the rows locked in ms access after the query ran (even if it finished successfully)? and how can I unlock them or make it unlock itself right after the query/job ran?
Thanks
When SQL Server inserts new rows, those new rows are in fact exclusively locked to prevent other transactions from reading or manipulating them - that's by design, and it's a good thing! And it's something you cannot change - you cannot insert without those locks.
You can unlock them by committing the transaction that they're being inserted under - once they're committed to SQL Server, you can access them again normally.
The error message i get says, that the dataset has been changed by another user and if i save it, i would undo the changes of the other user. (and asks me for copying into clipboard).
This is different from "locked", and completely normal.
If you have a ODBC linked table (or form based on the table) open, and change data in the backend, Access doesn't know about the change.
You need to do a full requery (Shift+F9) in Access to reload the data, afterwards all records can be edited again.
Got the solution for my Problem now.
I had to add a timestamp row into the pricing table, so access could recognize the change.
Access loads the data into the front end when the table is first accessed. If something in the backend changes the data, you need Access to refresh it first, before you can edit it from the front end (or see the changes).
Do this by (in Access) by closing and reopening the table, or switching to the table and pressing shift-F9 as Andre suggested, or programmatically using a requery statement. You must requery, not refresh, for it to release the locks and register the changes made in SQL.

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.

What's an alternative to triggers when using a Jet tables in an Access Database (mdb file)?

I have this project that would require users to check in/out through a finger print reader ZK SF200.
The system that I am building needs to fetch new data that is added into this machine's database which unfortunately is a MS Access mdb file.
In my limited experience in MS Access databases, I managed to link this file to my MySql database table which allows me to manually do the insert from MS Access.
All I want to do now is to create some form of trigger that would add data to my MySql database when new rows are inserted into the MS Access table.
This problem would have been solved if the file type was .accdb because we can use After Insert events however it is an mbd type so those are not supported.
Any idea on how I can solve this matter ?
As a final note: I am willing to change DBMS in case MySql is the obstacle here. Would creating a linked server or doing sql server replication through mssql 2008 r2 work ?
EDIT: I need to insert data to MySql table because I have a trigger implemented there which does its side of logical manipulation of the data (ex: Increment the number of visits for the customer, check if customer subscription has expired or not and update the customer status accordingly)
Thank you.
Linking a table in MS-Access to the ODBC source is probably an answer for you. The table in MS-Access will be more like a view on the source table. Any DML operation (INSERT, UPDATE, DELETE) will be synced immediately with the source database. You will not need any trigger, which is not available in MS-Access (unless some VBA expert knows a solution).
The Linked table technology is default available for SQL-server, but since it uses ODBC I quess you can use it with MySQL too.

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

mySQL combining data from 2 databases

The Problem.
I have a website which was recently switched over to a new server php/mysql.
Its an e-commerce site, when it was switched over the person who did the switch did not switch over the database for all the pages on the site, so I have some data that exists on both mysql databases (the new and old server), and some data that exists on the old server but not on the new server and vice versa.
I need to merge the data from the 2 databases into one database with all the data.
My solution:
I am thinking the best way to go about this is too write a php script that gets the data from the old server, checks to see if the fields (other than the primary id) exists on the new server, if the record does not exist then insert it into the new table on the new server.
The structure is not so complex, but the orders table has a look-up field to the order details table (using the primary key of the orders table as the foreign key)
Any ideas on an easier quicker way to do this, is there something in phpmyadmin that can merge two databases?
Any suggestions much appreciated.
You could create another table using the federated storage engine on your new server.
http://dev.mysql.com/doc/refman/5.5/en/federated-usagenotes.html
Then you can have access to both within single sql queries.
Assuming you have privileges to allow other hosts to connect to your old server.