这可能是将一些用户表(DDL 和数据)从 Oracle 数据库自动导出到 Microsoft Access 数据库的简单方法,这意味着无需用户交互。
更新:Access 数据库上的链接表会引发用户/密码对话框以连接 oracle,这不是一个有效的选项。
您可以在 MS Access 中设置“指向”实际 Oracle 数据而不是复制它的链接表。这样,数据始终是最新的。
否则,您将需要创建一个计划进程,或者可能在每次打开 MS Access 数据库时通过 VBA 代码执行导入。
就个人而言,我会选择链接表。
Some notes about the code below:
It doesn't check if the table is already linked first. If it is, you'll get an error you'll have to handle.
The user name and password are passed as clear text, which is a security risk. Someone can open up your database code and get all the info they need to connect to your database and potentially do some harm. If this matters to you, you'll need to either compile your Access database to an MDE and distribute that, or find some way of encrypting/decrypting the connect info on the fly.
You can use ADOX to link the tables without prompting for user ID and password. First, set a reference to the "Microsoft ADO Ext. 2.8 for DDL and Security" libary (Tools\References... in the VBA editor). If you don't see this entry in the list of available references, browse for "msadox.dll" and add it manually. Your version number may be different, depending on your version of Access (I'm using 2003 here).
You can then use code like this to link to an Oracle table:
Sub LinkOracleTable(Server, UserID, Password, Schema, TableName)
Dim tbl As New ADOX.Table
Dim cat As New ADOX.Catalog
Set cat.ActiveConnection = CurrentProject.Connection
With tbl
.Name = TableName
Set .ParentCatalog = cat
.Properties("Jet OLEDB:Create Link") = True
.Properties("Jet OLEDB:Link Provider String") = "ODBC;" & _
"Driver={Microsoft ODBC For Oracle};" & _
"Server=" & Server & ";" & _
"Uid=" & UserID & ";" & _
"Pwd=" & Password & ";"
.Properties("Jet OLEDB:Cache Link Name/Password") = True
.Properties("Jet OLEDB:Remote Table Name") = Schema & "." & TableName
End With
cat.Tables.Append tbl
cat.ActiveConnection.Close
End Sub
You would call the sub like this:
LinkOracleTable "TNS Service Name", "UserName", "Password", "MySchema", "MyTable"
Oracle 可以使用 UTL_FILE 写入平面文件。然后,您需要将它们带到 Access 数据库可以上传它们的位置。
Oracle 标准版和企业版包含一个 JVM,因此您可以在其中拥有通过 JDBC 连接到 Access 并以这种方式推送数据的 Java 代码。
还要查找异构连接和数据库链接 http://www.oracle-base.com/articles/9i/HSGenericConnectivity9i.php 如果您的 Oracle DB 位于可以处理 ODBC 的服务器上,这可能只是一个选项。
最后,根据前面的评论,您可以将数据推送到单独的模式甚至单独的 Oracle 数据库(例如免费的 Oracle 快速版),并让 Access 数据库/应用程序从那里获取它。