rails-sqlserver / tiny_tds

TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
Other
605 stars 191 forks source link

LoadError: cannot load such file -- tiny_tds/tiny_tds #391

Open aharpervc opened 6 years ago

aharpervc commented 6 years ago

Before submitting an issue please check these first!

If none of these help. Please fill out the following:

Environment

Operating System

Please describe your operating system and version here.

TinyTDS Version and Information

Please paste the full output of `ttds-tsql -C` (or `tsql -C` for older versions
of TinyTDS) here. If TinyTDS does not install, please provide the gem version.
$ ttds-tsql -C
ttds-tsql : The term 'ttds-tsql' is not recognized as the name of a cmdlet, function, script file, or operable program
$ tsql -C
[TinyTds][v1.0.5][tsql]: c:/Program Files (x86)/ruby/233/lib/ruby/gems/2.3.0/gems/tiny_tds-1.0.5-x86-mingw32/exe/tsql.EXE

FreeTDS Version

Please provide your system's FreeTDS version. If you are using the pre-compiled windows gem you may omit this section.

Description

Please describe the bug or feature request here.

I am not able to use TinyTds 2.1.0 on Ruby 2.3.3. The gem appears to install fine, but when I try to require it, I get the error LoadError: cannot load such file -- tiny_tds/tiny_tds.

It looks like this, followed by more stack trace:

$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]

$ gem install tiny_tds
Fetching: tiny_tds-2.1.0-x86-mingw32.gem (100%)
Successfully installed tiny_tds-2.1.0-x86-mingw32
1 gem installed

$ irb
irb(main):001:0> require 'tiny_tds'
LoadError: cannot load such file -- tiny_tds/tiny_tds
        from C:/bin/ruby/233/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'

Since we have apparently not dropped support for ruby 2.3.3, I would like to figure out what is going on.

coderjoe commented 6 years ago

@metaskills I'm at the point where I have officially been swayed. I feel like we do need to do version sniffing and automatically require 'devkit' in the gem. If @aharpervc (who knows the project very well) can't make it work without guidance, I don't think we can expect the average random windows ruby developer to figure it out either.

I'm very welling to review PRs to fix this as well as give the PR a try if it sticks around until next weekend.

aharpervc commented 6 years ago

I can hack it for myself with require devkit, as mentioned in the last thread, but since that isn't good/safe, I'm out of ideas.

It may also simply be an environment configuration requirement. Perhaps the solution isn't changes to the code, but something in the readme? (Although I myself do not know exactly what that configuration would be...)

coderjoe commented 6 years ago

Until a solution is created, you need to require 'devkit' in your rails app before the rails app is bootstrapped and therefore before tiny_tds is required.

Edit: Either that or edit your path/environment variables so devkit is always loaded.

aharpervc commented 6 years ago

I can deal with that. However, it's still unclear to me what devkit is changing to make library loading work. It's changing the ENV PATH right? So some feature of devkit resides in it's own folder, added to the PATH, and now library loading is working. Is there a way to discover whatever that is, and load it selectively, without changing the PATH?

coderjoe commented 6 years ago

@aharpervc unfortunately no. Because of how devkit works its dependent on the user's choice of installation directory. That's why the devkit shim exists, to modify a ton of environment variables all at once if your project needs to use devkit.

If you'd like to learn more I'm happy to discuss it, but I'd rather do that via gitter than in this issue.

mbratch commented 6 years ago

@aharpervc and @coderjoe thanks for the tip on using require 'devkit' in the application. I put it between require 'rails/all' and Bundler.require(*Rails.groups) in my config/application.rb and it seems to work around this issue.

aharpervc commented 6 years ago

I had been hacking tiny_tds.rb, before it tries to load the native library, but hypothetically any time before require 'tiny_tds' should work.

wakeless commented 6 years ago

Is there a fix for this, we are using OCRA to create a binary and this doesn't seem to work with the require 'devkit' fix.

JohnAtFenestra commented 5 years ago

Adding a comment. You may want to look at my findings for Ruby 2.4 + on https://github.com/rails-sqlserver/tiny_tds/issues/416. Try reinstalling the gem with:

gem install --platform ruby tiny_tds
meric426 commented 4 years ago

Is there a fix for this, we are using OCRA to create a binary and this doesn't seem to work with the require 'devkit' fix.

Did you ever solve this?

JohnAtFenestra commented 4 years ago

@meric426

See my comment directly above yours. #416 documents how using --platform ruby corrects the issue.

meric426 commented 4 years ago

@meric426

See my comment directly above yours. #416 documents how using --platform ruby corrects the issue.

@JohnAtFenestra I can get the script running. But trying to package it into a .exe with OCRA doesn't work

JohnAtFenestra commented 4 years ago

If tiny_tds runs from a script but not after packaging, then I'd say you have an issue with Ocra packaging rules. Without seeing your error, my guess is that Ocra isn't dealing with the issues that --platform ruby resolves. If you look at my notes on #416, you'll see that the .so files existed in the correct locations, however, for whatever reason, tiny_tds still didn't work. Building the extensions with --platform ruby resolved them, but I didn't dig deeper into why.

Good luck!

EDIT: I looked at Ocra's documentation. What happens if you build your executable with the --gem-full option?

vidhijain24 commented 3 years ago

Hi Team,

I am facing same error message when I require 'tiny_tds' in my code. LoadError: cannot load such file -- tiny_tds/tiny_tds

My ruby version is Ruby30-x64. Also I have installed tiny_tds using below command: gem install tiny_tds -v '2.0.0'

Please help me to resolve my issue.Thanks

swistak35 commented 1 year ago

@meric426 Have you managed to solve your issue with tiny_tds and ocra?

swistak35 commented 1 year ago

If someone would like to take a look at the issue, I've made minimal reproduction example here:

https://github.com/swistak35/tiny_tds_issue391

meric426 commented 1 year ago

@meric426 Have you managed to solve your issue with tiny_tds and ocra?

Nah, abandoned that project a long time ago

swistak35 commented 1 year ago

Thank you for your response.

Would one of the maintainers be willing to provide paid support for that issue? (I'd have to ask about the details, but it would be possible) If the setup part sound too intimidating (Windows, I know...), we could also pair-program the issue on my machine. Feel free to contact me through the e-mail on my github profile.

swistak35 commented 1 year ago

I've figured this out. The problem was missing dlls, in the previous tiny_tds version I've used (1.3.0) they were included, in 2.1.5 they were not and ocra didn't include them. That should be I guess expected (not ocra's fault), it's just that the error message is cryptic and doesn't provide good entrypoint for debugging.

I've figured out which libraries were missing by using procmon tool as described here: https://github.com/larsch/ocra/issues/174#issuecomment-1112104881

It turned out I was missing following dlls:

The first one (libiconv) is included in ruby 2.6 installation. The rest of them I took from tiny_tds 1.3.0 gem (ports directory). The ones from tiny_tds 1.3.0 I've put in my ruby 2.6 bindir (C:/Ruby26/bin), and I've added following options to ocra command:

--dll ruby_builtin_dlls/libiconv-2.dll --dll libsybdb-5.dll --dll libcrypto32-1.1.0e-i686-w64-mingw32.dll --dll libssl32-1.1.0e-i686-w64-mingw32.dll