Connecting Ruby to MSSQL server without DBI - ruby

Is there a way to connect ruby to mssql without using DBI? Is there any native Ruby TDS lib that handles that?

FreeTDS comes to mind, however I have not used it.
Java TDS to MSSQL.
Ruby ODBC or Java ODBC
SOAP using TDS endpoints.
The MSSQL DBI is by far the better out of the lot of them. However I guess if you are running Linux and trying to connect to MSSQL, then try "FreeTDS". There are heaps of tut's and sites to show how to setup and configure for all flavours of Linux.

I've published an example application how to connect to an MS SQL Server with ruby, you can check it here.
It mask use of activerecord-sqlserver-adapter to allow ORM.

Related

How to connect to Oracle through LDAP with Ruby 2.7?

My application used to query an Oracle database through a classical OCI connection string such as 'user/password#server/database'.
But the server architecture has changed so that connections should now go through LDAP for security reasons. The URL looks like this :
jdbc:oracle:thin:#ldap://intranet.oid-01.dama.ch:3063/EDWHPD,cn=OracleContext,dc=emea,dc=dama,dc=ch
I don't know how to handle this, and it raises several questions for me:
Would the old DBI gem be relevant here?
Should I use the Net-LDAP gem, and what would it bring to help establishing the connection to oracle?
Do you know a tutorial explaining how to handle this type of database access?
Thank you for your help!

accessing a database from ruby using an odbc driver (Remedy)

I have the Remedy odbc driver installed on my machine. I am able to pull down data from Remedy via excel just fine specifying this driver in my connection.
Is there any way I could use this driver from within Ruby / Ruby on rails to connect to and read from the DB?
Many thanks!
I have not found a way to use the Remedy ODBC driver from Ruby. Also, I am suspecting that using the driver which seems to be quite antiquated and is already throwing some arcane errors when used from Excel might not be simple to use.
I was able to connect through R via RODBC and thus an R script that would pull the data for you and write to CSV might be a solution.
What I am actually using - which to my mind is the simplest way of achieving this - is talking directly to the Remedy SQL backend. All that you will have to do is parse the data upon pulling it from DB which is very easy to set up (priorities, service types, statuses are stored as integers and not actual names and timestamps are in epoch format).

sybase from ruby: JDBC connection to Sybase

I need to connect to a fairly old Sybase database from Ruby.
I ended up using jRuby, only because I couldn't get any manner of connecting to Sybase from MRI to work; If there's a way that actually works and isn't crazy to set up a Sybase connection for an old-ish version of Sybase, that'd be great. But, I beat my head against the wall on that one for a while, I think there is not.
So I wound up in jRuby, in order to use JDBC. I do have a JDBC.jar file that works to connect to Sybase.
I know I can write raw JDBC code in jRuby, just as I would in Java, using the JDBC API. But the JDBC API is such a bear to work with, among other things being very poor at escaping/injection-protecting (or maybe I just don't understand how to use it right, see 'difficult to work with', at least for me).
Are there Ruby 'wrapper' libraries that will work in jRuby as a wrapper for an arbitrary JDBC? If I could get it to work with ActiveRecord, that might be cool, but not neccesarily actually required.
I had been using the Ruby 'DBI' package, which was actually working great. But the Ruby DBI package seems to be unmaintained and is becoming increasingly difficult for me to use; there are a bunch of pull requests (https://github.com/erikh/ruby-dbi/issues) related to making it work under 1.9.3, silencing deprecation warnings, etc. Which are not being attended to by committers. I emailed the github project owner to ask if there was any chance of them being attended to, and received a one-word answer "No", with no explanation. Not really sure what's going on.
So, what are my options for connecting to Sybase from Ruby, with jRuby JDBC or other?
(Per demand below, I'll add that I use RHEL 5 as an OS. But if the answer is "once you get FreeTDS installed, you can do X, Y, and Z like this", I can probably manage to get FreeTDS installed myself. In the past, I've gotten stumped even AFTER getting FreeTDS installed on the host).
I used JTDS jar and activerecord-jdbc-adapter gem for my Rails 3/Sybase ASE 15 project.
The only problem I had is limit and offset for Sybase are not really supported. I end up writing my own visitors to make limit and offset work.
You may want to take a look here: https://github.com/arkadiyk/ar-sybase-jdbc-adapter
This question seems to be abandoned, but I'd like to log some success. I'd like to start with stating that this works on windows and linux.
I am currently using MSSQL v7 and MSSQL v8 from jruby with the JDBC driver distributables I downloaded from microsoft.
The catch is, JDBC 3.0 and 4.0 drivers are unable to connect to MSSQL v7. I was very lucky to find out JDBC 2.0 actually worked against it.
I'm not sure what the OP's concern was about SQL injection, but these drivers are capable of creating Prepared Statements (for partitioned SQL) and Callable Statements (for SPs) which can be used to escape parameters safely.
About the ugliness, yes you're right. That's why a bit of code is needed:
class Java::ComMicrosoftSqlserverJdbc::SQLServerResultSet
def to_a
#I used meta_data here to convert resultset to array of hashes
end
end
and to get multiple results from a single select statement:
yap= connection.create_statement
rowing= yap.execute sql
row_the_boat= []
while rowing
row_the_boat<< yap.get_result_set.to_a
rowing= yap.get_more_results
end
I have used FreeTDS and TinyTDS on Linux via Sequel to get to some of our MSSQL and Sybase DBMs.
It wasn't as elegant as using MySQL or Postgres, but was doable. And, Sequel is a very good tool for non-Rails DB access. It's very powerful and flexible.
I put together a simple example of using FreeTDS/TinyTDS/Sequel with SyBase (we have Sybase ASE 15.3)
See the horizon-tds-example GitHub/repo for a Dockerfile
#<!-- language: rb -->
require 'dotenv/load'
require 'sequel'
require 'tiny_tds'
require 'awesome_print'
opts = {
adapter: 'tinytds',
login_timeout: 5,
timeout: 10,
tds_version: '50', #42 or 50
host: ENV['APP_HZ_HOST'],
port: ENV['APP_HZ_PORT'],
database: ENV['APP_HZ_DATABASE'],
username: ENV['APP_HZ_USER'],
password: ENV['APP_HZ_PASSWORD']
}
bib_id = Integer( ARGV[0] || 0 )
tag_num = ARGV[1] || ''
sql = "SELECT * FROM [bib] WHERE bib#=? AND tag=?"
DB = Sequel.connect opts
dataset = DB[sql, bib_id, tag_num]
dataset.each do |row|
ap row
end

How do I install an ODBC library in Jython

In python is possible to install pyodbc fairly easy, but in jython you are supposed either to install django, and to instal jdbc and then I do not know what else. Does any body know the proper steps? it is for windows an jython 2.5
In Jython you can use JDBC drivers, and via JDBC-ODBC bridge you can connect to ODBC configured source. With zxJDBC module you can use JDBC database just like DB-API2 compliant Python database interface. Have a look at example of such usage with Informix database: Consistent method of inserting TEXT column to Informix database using JDBC and ODBC

Oracle with Clients: I must install oracle for client?

I'm very newbie for Oracle and very not sure about Oracle.
one question I want to know.
if I want develop oracle windows application. first I must install oracle on server for database server but I'm not sure if I don't want install oracle on client. I must install oracle for client YES or NO !?
thank for help.
Yes. The Oracle client must be installed on any machine wishing to access the database. The components of the client you need to install will depend on the method your application using. eg. OLEDB, ODBC, etc.
The answer is 'it depends' - your software will need some kind of client-side driver or library for communicating with Oracle, but there are many ways you can do this.
1) Compiling Oracle's SDK libraries directing into your application.
2) Using a locally installed SQL*Net client (which can be shared between different local applications, so that things like TNS_NAMES setup can be shared).
3) Using third-party libraries embedded in your application.
Also the different kinds of clients can expose or restrict different levels of functionality.
You can install Oracle DB and Oracle Client on same Machine. In below order:
Oracle DB
Oracle Client
Do not forget to do an ADMIN Share prior to install Oracle DB.
To Answer the general question; You have to install Oracle Client on any machine needed to connect to the Oracle Database.

Resources