Do I need FreeTDS to use TinyTDS under Windows? - ruby-on-rails

I'm trying to connect to SQL Express from a Rails app, and I've installed the TinyTDS gem. I keep getting an error:
--------------------
Unable to connect: Adaptive Server is unavailable or does not exist
--------------------
Everything I find on Google relates to FreeTDS. Do I need it in order to use TinyTDS on Windows? The TinyTDS github page says it requires it but it makes no mention of Windows.
Do I need drivers or something else? I already isntalled the 'activerecord-sqlserver-adapter' gem.
If I do need FreeTDS, where do I get it?

There is a binary version of Tiny_TDS that is installed on Windows when you install this gem. This includes FreeTDS, so there's no need to install it separately. Only time you have to worry about FreeTDS on Windows is if you want to work with SQL Database on Windows Azure, which requires you to manually build FreeTDS.
There's a couple things that could go wrong that might cause a connection failure:
SQL Express doesn't install a default instance, but instead installs a 'sqlexpress' instance. Maybe try connecting to 'servername\sqlexpress'.
SQL Express may not allow network connections. If you're trying this over the network you may have to enable networking.
TCP/IP and named pipes may not be enabled. I think Tiny_TDS uses TCP/IP.
SQL Express might be using a dynamic port rather than the expected 1433, so maybe check ports.
Here's an article that might help:
http://blogs.msdn.com/b/sqlexpress/archive/2005/05/05/415084.aspx.

Related

RoR app deployed on Heroku and working with SQL Server database

Is it feasible to have a Ruby on Rails app, which is:
a) deployed on Heroku, and
b) working with a remote SQL Server database?
I take it that I'll need unixODBC installed on Heroku, but I cannot find a way to do so. Is this possible?
Or, is there any other way (without ODBC?) to accomplish this?
Thank you very much for any guidance or tip.
Updated:
Some info on the subject:
1) Heroku pre-installs both unixODBC and FreeTDS by default, so you already have them.
2) Also, it is possible to run shell commands via Heroku Console in backticks, e.g.:
heroku console
`odbcinst`
(runs "odbcinst" command in Heroku shell and shows the result)
3) You do not have access to filesystem outside of your slice where the packages are installed. If you only need a driver path, Heroku support can provide it (/usr/lib/odbc/libtdsodbc.so in my case).
4) You cannot run sudo commands in Heroku shell.
At the moment, to connect to MS SQL Server you at least need to append ‘freetds.conf’ file. Even when using tinyTDS (there is an open ticket#2 in tinyTDS gitgub issue page). DSN-less connection instructions from "wiki.rubyonrails.org SLASH database-support SLASH ms-sql" didn’t work for me, I guess this connection requires some extra-configuration either.
‘freetds.conf’ cannot be modified without sudo. Therefore, I conclude that currently there is no way to make MS SQL and Heroku work together.
I’ve managed to set up this connection with EngineYard and activerecord-sqlserver-adapter.
I followed these instructions:
https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Platform-Installation---Ubuntu
(there are only some filepath differences, e.g. ‘odbc.ini’ is located in ‘/etc/unicodbc’, not in ‘/etc’ - this is easy to work out).
I installed 'unixODBC' and 'freetds' packages using EY Unix Packages feature, and made all configurations manually through SSH. Sudo is available in EY (no password required). There is also Chef Recepes feature to automate those configurations (seems to be pretty easy, I'm going to try it tomorrow).
Hope this is helpful.
It is possible.
Because Heroku copies/symlinks its own config/database.yml over whatever you supply in your repository, you may need to take additional steps (e.g. in config/environments/production.rb or in config/initializers/remote_mssql_from_heroku.rb) to set up your application appropriately.
You will face the challenge, however, that traffic from Heroku to your MSSQL database will traverse the public internet. By default, this traffic will not be encrypted. Potentially everyone in the world will be able to monitor your traffic between your Heroku application and your database, and even alter the traffic in-flight, whether for benign or malicious purpose, without you being able to detect it. MS SQL offers the capability to connect over SSL. This capability requires explicit configuration in the MSSQL server, so you must be able to access and modify that configuration. Additionally, this configuration requires that your client library be up-to-date and capable of talking with MSSQL over SSL. Note that MSSQL server will enforce that your server certificate list a Common Name or Subject Alternative Name exactly matching or wildcard-matching the server's FQDN (at least, the FQDN that the server knows about), and that the client use an FQDN for the server exactly matching or wildcard-matching one of the names on the certificate.
I've successfully used the following article which uses Heroku's newer buildpack feature to use TinyTDS and connect remotely to SQL Server 2008 R2. I'm still investigating how I could encrypt traffic. Hope this helps others!
http://blog.firmhouse.com/connecting-to-sql-server-from-heroku-with-freetds-here-is-how-on-cedar#
We're having a similar problem where we're needing to import old data from a SQL Server database into our new app. The data isn't a straight table import, but needs to undergo some processing and conversions. We've built an import layer for this which lives in a private gem, so as to not pollute the new app with the old data conversion issues. This approach is also designed to permit incremental updates, as we get closer to launch we'll keep syncing records up to the moment of switch-over.
Heroku told us that it's not trivial to connect to SQLServer, in particular as they don't support FreeTDS. Their support staff recommended to run an instance with the import gem from a laptop in our office and configure it to connect to their database (which requires a dedicated DB, not the free shared one). This sounded like the most palatable approach to us.
Secondly, regarding security that was mentioned by #Justice, we discussed configuring SSL for SQLServer with the hosting company and they pointed out the complexities of this. They recommended VPN as an easier solution. As we don't have office-side VPN hardware, the simplest and free solution proved to be an SSH tunnel.
We've set up an SSH tunnel from the laptop to the SQLServer Windows box. That was straightforward. We had CopSSH installed on Windows (which comes with a Linux shell, by the way) and we were able to simply set up a tunnel, having the laptop talk to localhost for its SQLServer connection, i.e.:
ssh -L 1433:localhost:1433 user#windows_server_name
I did not know Heroku has FreeTDS on it? I was told they did not. TinyTDS if used with FreeTDS 0.91 can have a zero freetds.conf dependency and be driving by runtime connection args. We are looking into building an Ubuntu 10.4 native gem that statically links 0.91 with OpenSSL so you can just drop it into Heroku and us it to connect to Azure and/or you own outside DB.

Connecting to SQL Server 2005 from a ROR application in Ubuntu

I tried to connect to SQL Server from a ROR application in Ubuntu. For that I did the following things.
I installed the following libraries in my Ubuntu 10.04
unixodbc
unixodbc-dev
freetds-dev
libdbd-odbc-ruby
tdsodbc
After installing these, I created the dsn and made the required changes in odbc.ini and freetds.conf files.
Then I tested the connection using "tsql" like below
tsql -S <dsn name> -U <username> -P <pwd>
For this command, I am getting the following error
Adaptive Server is unavailable
I also checked the freetds log; it is saying "connection timedout".
I am sure that we are fine with the configurations (remote) in our SQL Server side.
When I run tsql -C it is saying TDS Version is 5. I am not sure how it is saying TDS 5, because I installed the latest FreeTDS version. And I don't know how to update my TDS version.
FYI, I heard that TDS version 5 can't be used for making connections with SQL Server. Is that right?
Please guide me
Thanks,
Neo
freetds.conf allows you to specify which version of the TDS protocol you want to use. Just add a tds version = 8.0 under the [global] section or the section you added for your server. If not specified, it defaults to version 5.0, which seems to be your case. For more info, look at http://www.freetds.org/userguide/freetdsconf.htm
I realize this is not an answer to your specific question, but it is some advice from the last time I tried to go from Linux to SQL Server. It was back in 2009, so it's possible something has changed since then.
Anyway, we had so much trouble with it we gave up and decided to use JRuby.
It resulted in very little effort to get the connection up and running using activerecord-jdbc-adapter and we've run into no problems with compatibility. (I take that back, there was one problem I had to fix where we were selecting limited rows in mssql from table with no primary key, identity column, or column named "id")
I have been able to get it working in the past doing it like you're trying to, but it was always a lot more effort than I had to go through with JRuby.

How to run a win32 native application that requires sql server native client on MacOSX with winebottler?

I am experimenting with WineBottler and I would like to try to run my win32 native application written in Delphi on OSX.
The application runs, but I stop at login screen since I cannot connect to SQL Server.
Does anyonw know how to install and configure SQL Server native client on OSX so that it is usable with WineBottler?
Note: I put "wine" as tag since "winebottler" is not available.
I have a Delphi application that uses MDAC 2.8 for ADO connection to the Jet provider. I use Winetricks to install MDAC 2.8, and it works great. If you can't get SQL Server Native Client to install, perhaps your application can use the OLEDB SQL Server provider by tweaking your connection strings. Are you using any features that are only in SQL Server Native Client?
You would have a lot less trouble if you put in some middleware like kbmMW, Remote Objects, or DataSnap. All of them can use plain TCP/IP (via http or like higher level protocol), and don't require client side libs. You will need an extra server, but it is easy to create one that just forwards your SQL and data between clients and SQL server. Note that SQL server licensing remains.
On the other hand, you can try to install SQL Server native client, some older version of it - eg. for SQL Server 2005, in that "bottle" with your application. Yet, I'm not sure if that is legal thing to do. I think that MS prohibits native client installation on OS other than Windows.
There is FreeTDS native client that works with MSSQL from unices, but it is not ported to be usable from Delphi (like dbx driver).

How to connect to a legacy Informix database?

I have to connect my app to a customer's Informix 7.2 legacy database.
From what I was able to find out, in theory there should be a database service running on port 50000. The problem is that I cannot find any database service in the Operative System.
So far I'm only able to use dbaccess and perform queries from the command line.
I would like to use a database driver (such as http://code.google.com/p/ibm-db/) so my app can connect and query the database using a cursor, but since I cannot find any database service, apparently I can't...
Am I missing something here? Are there options I'm not considering?
Is it possible to have an Informix database in which the only interface is dbaccess?
See connection strings for Informix
If you use Python you can look at: Python wiki but I would like to extend it a little.
If you work on Windows and have Client SDK then there should be ODBC driver installed on your machine. There is also Linux and other unix versions of such client software. If you install that you can use ODBC to connect to database. On Windows you can use Active State Python 2.6 with win32 extensions which has odbc module included. On other Python implementations you can use win32 extensions or other ODBC module such as mxODBC.
I work also with Jython where I use both JDBC and ODBC drivers. You can see this "in action" in my SO questions like: Problem with Informix JDBC Money format
BTW, if you want to connect to a remote legacy Informix database using Python from a Mac, pypyodbc-informixcsdk could be your only (free) choice. Check this wiki.
On a Windows box, pyodbc + Informix Client SDK + ODBC do the job nicely.

Ruby on Rails + Sql Server 2005

This has been addressed some time ago, but I've not had any luck following the steps outlined or advice suggested. Here's my situation:
I've installed SQL Server '05 and have another (non-Ruby) application utilizing it successfully.
I've got Rails up and running successfully (but only for MySQL.)
I've installed the Rails sqlserver adapter gem (as well as its dependencies.)
I've downloaded ADO.rb (now only available on older builds of Ruby-DBI) and placed it into c:\ruby\lib\ruby\site_ruby\1.8\DBD\ADO\ADO.rb.
I've configured database.yml to use the sqlserver adapter and pointed it towards my database with valid login information.
When I attempt to run a migration, I get the ugly 'Unable to load driver ADO (uninitialized constant DBI::DBD::ADO)' error.
Thanks immensely for any assistance.
So just make sure if you're working on Windows or Mac to set up an ODBC connection. You must indicate this explicitly in your database configuration for Rails.

Resources