Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Accessing 2 mdb databases through PowerShell

$
0
0

Hi,

Scenario: I have two MS Access databases, one with 2380 records (the targetDB) , the other with 2387 records (the sourceDB)

Tables and fields are identical in both target and sourceDB's, but are located on different servers.

I'm trying use SQL to update a table in a target database using records from another source database in PowerShell.

I can successfully create 2 separate connections (TargetDB and SourceDB) and retrieve the last record in each database to determine how many records need to be updated by using:

$strQuery = "SELECT Last(RecordID) AS RecordID FROM tblRecord"

Once I get the number of records and the actual record number, I want to use the following sql to update the target database:

$strQuery1 = "INSERT INTO TargetDB.tblRecord SELECT * FROM SourceDB.tblRecord WHERE tblRecord.recordID = "  $i+$idNum01 ";" 

($i would be an index to iterate from 1 to 7 from the first recordID (2381) to the Last recordID (2387)..... $idNum01 holds the starting recordID number)

The scenario here is to Insert new records in the table of the target database using the select statement to pull data from the source database table. (this is easier than creating a new table evertime there is an update to maintain the recordID.

The problem is how to indicate the Target database connection is different than the Source database connection.

Might it better to pull all the data into an array from the source, then write out to the target DB from the array or iterate through a Read from sourceDB, then write to targetDB one record at a time?


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>