Error: "in` require": cannot load such file - win32ole (LoadError) "when trying to connect from ruby ​​program to ms access database

From my Ruby program running under Ubuntu, I am trying to connect to an Access database located on another computer running Windows. I get an error

'require': cannot load such a file - win32ole (LoadError)

Another problem that I encountered is that the Access file that is not in my system, so I want to use ip address, and port number, and user name, and passwordthe system in which the file is located, so that, using an Internet connection, I can connect and get data. Unfortunately, I do not know where I can specify these details in my code snippet below.

connect_to_access_db.rb

require 'win32ole'

connection = WIN32OLE.new('ADODB.Connection')
connection.Open('Provider=Microsoft.ACE.OLEDB.12.0;
             Data Source=c:\path\filename.accdb')


SQLstatement = "SELECT * FROM TABLE"
recordset = WIN32OLE.new('ADODB.Recordset')
res = recordset.Open(SQLstatement, connection)
p res

How can I connect to an Access database?

+4
source share
1 answer

Your problems three times:

1. Attempting to use win32ole / OLEDB on a non-Windows machine

, win32ole Ruby, -Windows-. , OLEDB Linux-, , .

2.

ip address port number

. Access , Windows, TCP-. , Windows , Linux .

3.

win32ole , . ODBC - , , , ODBC Access Linux ( " mdb" "unixODBC" ) , , .

JRuby UCanAccess JDBC. Ubuntu 14.04 LTS JRuby...

connUrl = "jdbc:ucanaccess:///mnt/weezerpublic/uca301demo.accdb"
conn = java.sql.DriverManager.get_connection(connUrl)
stmt = conn.create_statement
rs = stmt.execute_query("SELECT TextField FROM myTableInAccess WHERE ID=1")
while (rs.next) do
    puts rs.getString("TextField")
end
conn.close

... script...

#!/bin/bash

export CLASSPATH=.:/home/gord/Downloads/JDBC/UCanAccess/loader/ucanload.jar

jruby jrubyTest.rb

... :

  • Windows -. VPN-.
  • JDBC UCanAccess . Ruby , – – - (, Microsoft SQL Server, MySQL,...) .
+4

Source: https://habr.com/ru/post/1648026/


All Articles