Connection to the MS Access datebase


#1

How can I connect to the MS Access datebase in ruby/sketchup.
I work on win 8.1 64bit and Sketchup 15 64bit to.

I have script which works properly on XP/Sketchup 14 but dosn,t want work in 64bit enviroment
br

Marcin


#2

I guess you are using a xxx.so to ‘bridge’ Ruby into the MS app ?
Like win32ole.so ?
You need a test in your code Sketchup.version.to_i > 13
if so just require ‘xxx.so’ - as they are now built-in to the newer Ruby set.
if not require 'path_to_xxx.so'
Note that to be cross platform compatible, you should put your own xxx.so in a subfolder so it is NOT found during the require
If it’s a custom .so you probably need a version compiled for 64 bit ?


#3

Can you provide some more info?
Sounds like you are using binary Ruby C/C++ extensions that needs to be built for 64bit.


#4

The script which worked is:

require 'win32ole'
		base_path = 'D:\ANNA_SZAFY_SKECHUP\anna_szafy.mdb'
		connection = WIN32OLE.new('ADODB.Connection')
		
		if   File.exist?(base_path) then
			connection.Open("Provider=Microsoft.Jet.OLEDB.4.0;
							Data Source=#{ base_path }")

#5

And what is the error you are getting now?


#6

Done. Ruby says: (in OLE method ‘Open’: )
OLE error code:800A0E7A in ADODB.Connection
Nie można odnaleźć dostawcy. Może on być niepoprawnie zainstalowany.
HRESULT error code:0x80020009
Wyst¹pi³ wyj¹tek.

Do you need translate into english?


#7

Yes, a translation would be good.


#8

Nie można odnaleźć dostawcy. Może on być niepoprawnie zainstalowany.
Can not find supplier. It may be not properly installed.

Wyst¹pi³ wyj¹tek.
An exception occurred


#9

Try running it in v2015 - but with the “win32ole.so” you have manually added temporarily removed from the v2015 Plugins folder.
Then the native “win32ole.so” in the Ruy might be loaded with your “require”…
You might need to add the “.so” onto the end of the file name in your “require” example ?


#10

Unfortunatly doesn’t work. I didn’t have Plugin folder and I added it. I loaded to this folder file win32ole.so. I changed name file after require to “win32ole.so” And still doesn’t work. Mayby is some wrong in “require”. How can I check if win32ole.so is loaded into skcript properly?


#11

Wait - you didn’t have a SketchUp Plugins folder? Are you sure you looked in the correct location? The folder moved in SU2014 for Windows to a new location: http://help.sketchup.com/en/article/38583

And where did you obtain this win32ole?
As of SU2014 SketchUp ships with the Ruby Standard Library, and that should include win32ole. But not that it’s not located in the Plugins folder because it’s part of the SketchUp application.


#12

Ok.I checked Plugins Folder, and it is in right place. Winole32.so I found in instalation of Ruby. I use SU2015 and when I write
connection = WIN32OLE.new(‘ADODB.Connection’)

without require
and
Done. Ruby says: uninitialized constant AS_RubyEditor::RubyEditor::WIN32OLE

with require ‘win32ole.so’ or require ‘win32ole’

Done. Ruby says: Nil result (no result returned or run failed)


#13

Here is what I get - plain install of SketchUp:

require 'win32ole'
true

connection = WIN32OLE.new('ADODB.Connection')
#<WIN32OLE:0x0000000b637620>

base_path = 'D:\ANNA_SZAFY_SKECHUP\anna_szafy.mdb'
D:\ANNA_SZAFY_SKECHUP\anna_szafy.mdb

connection.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=#{ base_path }")
Error: #<WIN32OLERuntimeError: (in OLE method `Open': )
    OLE error code:800A0E7A in ADODB.Connection
      Provider cannot be found. It may not be properly installed.
    HRESULT error code:0x80020009
      Exception occurred.>

Now, I haven’t tried to set up a database provider - so I’m not surprised that I get this error. Have you made sure you have the appropriate DB provider installed?


#14

This is an issue with AS Ruby console editor. Try using sketchup’s Ruby console.


#15

I put require ‘win32ole’ in ruby console
and receive:
Error: 126: Nie mo¿na odnaleŸæ okreœlonego modu³u. - C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/win32ole.so
C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:45:in require' C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:45:inrequire’

:in `' SketchUp:1:in `eval'

I chacked, file: win32ole.so is in the place C:/Program Files/SketchUp/SketchUp 2015/Tools/RubyStdLib/


#16

Hi guys, you all are very impressive with your knowledge, how hard would it be for trimble to include a simple database link interface for SU?.. just imagine a two wsy link for things like door schedules, facilities management etc, etc…


#17

I know this as an old thread but it is the only one I could find about connecting to an Access database.

Does anyone know if it is possible to connect to an Access database from SketchUp 64 Bit? As SU 2017 is only available in 64 now I was wondering I it’s still possible to connect if a 32 bit version of office is installed.

This code works fine in SU 2016 32 bit but not in any of the 64 bit installs.

require 'WIN32OLE'
connection = WIN32OLE.new('ADODB.Connection')
path = 'C:\Users\Server Computer\Documents\BCC\dbzip.mdb'
connection.Open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + path)
recordset = WIN32OLE.new('ADODB.Recordset')
sql = 'SELECT TOP 5 * FROM ZipCodes'
recordset.Open(sql, connection)
rows = recordset.GetRows.transpose

Trying this code in SU 2017 64 bit gives the following error:

Error: #<WIN32OLERuntimeError: (in OLE method `Open': )
    OLE error code:800A0E7A in ADODB.Connection
      Provider cannot be found. It may not be properly installed.
    HRESULT error code:0x80020009
      Exception occurred.>

Any input will be appreciated.


#18

What line is giving you that error?

When I try on my machine:

require 'WIN32OLE'
connection = WIN32OLE.new('ADODB.Connection')

I get a different error message with WIN32OLE.new:

Error: #<LoadError: 127: The specified procedure could not be found.   - Init_WIN32OLE
C:/Program Files/SketchUp/SketchUp 2017/Tools/RubyStdLib/platform_specific/WIN32OLE.so>
C:/Program Files/SketchUp/SketchUp 2017/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:54:in `require'
C:/Program Files/SketchUp/SketchUp 2017/Tools/RubyStdLib/rubygems/core_ext/kernel_require.rb:54:in `require'
<main>:1:in `<main>'
SketchUp:1:in `eval'

#19

Might this depend on a given service being installed on the target machine? Which then in turn needs to also be 64bit…?


#20

I’m not sure if the WIN32OLE.so file has a bug in SU 17. I had to copy the one from 2016 to get it to work.