I'm trying to connect Rails to SQL Server. I installed the activerecord-sqlserver-adapter and ruby-odbc gems, but I'm not sure what to put in my database.yml file.
What exactly is a DSN, and why do I need it? (Is this some windows-specific thing?)
What do I do if I want to use Windows Authentication, instead of specifying a username and password?
I tried creating a DSN, specifying Windows NT authentication, and put the following in my config.yml:
development:
adapter: sqlserver
dsn: myDsn
mode: odbc
but I get a "The specified DSN contains an architecture mismatch between the Driver and Application" error. [I tried creating the DSN from Windows/system32/odbcad32.exe as well, since a Google search said this would create a 32-bit DSN instead, but I get the same error.]
Am I missing something in my database.yml file?
UPDATE:
I tried using
development:
adapter: sqlserver
mode:odbc
dsn: Provider=SQLOLEDB; Data Source=.\SQLEXPRESS; Integrated Security=SSPI
but I get a "Data source name not found and no default driver specified" error. Is it possible my Provider is not SQLOLEDB? [I don't know what a provider is or how to figure out what it's supposed to be -- I just copied it from another connection string I found.] I do know that I can connect to .\SQLEXPRESS using Windows Authentication from my actual SQL Server Management Studio program.
A DSN is a "Database Source Name." It contains the information that an ODBC driver needs to connect to a specific database.
Perhaps this SO Q&A will help you: Connect rails application to SQL Server 2005 from Windows
Also see connectionstrings.com for general help with connection strings.
Related
I want to connect my Ruby On Rails Application ( developed with ruby mine ) with a MS SQL Server 2008 R2 running on an external PC.
I can connect with Microsoft SQL Server Management Studio running on the same PC where Ruby mine is running to the remote Database in this way:
Server name is: domain.de,PORT\SQLServerName
Then I am connected to this remote database :
In rubymine I use the Gems:
Now I can use adapter: sqlserver in the database.yml without an error.
But I have no clue how to connect to the remote database:
I tired several example configurations like:
When I run the app in development mode I get this error:
C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/tiny_tds-0.6.1-x86-mingw32/lib/tiny_tds/client.rb:77:in `connect': Server name not found in configuration files (TinyTds::Error)
Can Anybody help me with the syntax for the database.yml that it can use the input data I
also use to connect with MS SQL Server Management Studio to the remote Database
I fixed it on myself:
Just replace the comma with a double point
dataserver: 'domain.de:50021\xxxxxxSQLServer'
DAMN YOU WINDOWS
I'm trying to use Rails 3.1. with the activerecord-sqlserver-adapter (3.1.1) and tiny_tds (0.4.5) on a Windows machine. In reading about TinyTDS and it's use of FreeTDS it looks like I can use Integrated Security (aka Windows Integrated security/NTLM) by putting a domain-qualified name as the user name (e.g. DOMAIN\userbob). But the docs still want me to type my domain user's password in the database.yml file. That's bad practice because it's insecure and doesn't take advantage of single-sign on, which is part of the point for Integrated Security.
Can I connect without saving a password in plain text in a file? e.g.
developement:
adapter: sqlserver
mode: dblib
dataserver: localhost
database: dev_db
username: DOMAIN\userbob
# password: no_no_please_dont_make_me_type_it_here
But, even if I put a password I get the following error:
TinyTds::Error: Unable to connect: Adaptive Server is unavailable or does not exist
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/tiny_tds-0.4.5-x86-mingw32/lib/tiny_tds/client.rb:60:in `connect'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/tiny_tds-0.4.5-x86-mingw32/lib/tiny_tds/client.rb:60:in `initialize'
I know my server is running and the current user context can connect because this works:
sqlcmd -S localhost -d dev_db -E
Any insights? Is it possible? If not, it should be.
Enable TCP/IP in "SQL Server Network Configuration" in SQL Server Configuration Manager utility.
Then restart SQL Server service.
Regarding security you will need to supply your own credentials otherwise it will use sa account.
Apparently SQL Server 2008 is setup by default to ONLY allow Windows Authentication. To change that you have to open the Management Studio, Right click on your server and select Properties. Select Security and click the "SQL Server and Windows Authentication mode" under Server authentication. This will at least allow you to connect directly to the server until TinyTDS makes the needed changes to allow Windows Authentication.
I think the code making the connection is trying to make the process impersonate the security context supplied by the credentials instead of passing the default credentials through to SQL server.
This would allow you to specify different credentials to the current security context. I've used this trick to connect to a server requiring SSIS from an untrusted domain.
I don't know TinyTDS/FreeTDS, perhaps null or empty credentials would make it use the default security context. Try:
developement:
adapter: sqlserver
mode: dblib
dataserver: localhost
database: dev_db
or
developement:
adapter: sqlserver
mode: dblib
dataserver: localhost
database: dev_db
username:
password:
Try to use
developement:
adapter: sqlserver
mode: dblib
dataserver: localhost\SQLEXPRESS
database: dev_db
username: DOMAIN\userbob
or else do you set 2 variant authentification in your's sql server? then try to connect with sa user...
I have an application made with Delphi 2006 and Firebird 2.5. For connection a use Interbase components from Delphi. I setting up in design time a TIBDatabase with username, password tc, and work ok, but when i want to run application in another pc (first i install Firebird 2.5 on it), i received this error:
Statement failed, SQLSTATE = 28000
Your user name and password are not defined. Ask your database administrator to set up a Firebird login.
What is this? How can I resolve that?
The message clearly states the username and password you're using to connect at design time in your development machine are not valid to the database server you're trying to connect on the other machine (let's call it production). From your message it seems it is not the same server you connect to at design time.
I suggest you to test this issue with ease to put the LoginPrompt property to true on the TIBDatabase component to allow it to ask the user for propper credentials before connecting. You will be able to connect using any valid username/password combination for that server. To be sure the combination are valid, try to connect using the isql command line tool, for example the command
c:\test>isql test.fdb -u sysdba -p masterkey
will connect to c:\test\test.fdb using default username and password. (the firebird root directory must be in the path environment variable for this to work)
Also, you can use the gsec command line tool to adjust the password for this engine or you can provide the create users and change passwords on that production machine before trying to connect to it.
On Windows, firebird default sysdba password is masterkey.
The solution that finally worked for me on windows was starting cmd.exe as administrator and running "C:\Program Files (x86)\Firebird\Firebird_3_0\gsec.exe" -user sysdba -password masterkey -mo sysdba -pw masterkey
This error is because the credentials for Firebird db is simply not stored in the database file. It's stored in the configuration file on the Firebird Server. If you copy over the DB file, and not the password -- you will have a different password.
On Ubuntu machines you can find out the password and username in the file, /etc/firebird/<version>/SYSDBA.password
It'll look something like,
ISC_USER=sysdba
ISC_PASSWORD="password"
Use those credentials to connect to the database file.
At 'isql-fb' from linux terminal and after the 'CONNECT' on database:
- I solved after delete(drop) and recreate the 'SYSDBA' user.
Observation: I had problems with file and folder permission at '/tmp/firebird' and I needed to use 'sudo' or root to open 'isql-fb'
Thanks.
I once got this error trying to connect to a Firebird 3.0.3 database using the Firebird 2.5 client libraries. I just forgot to update the client libraries to 3.0.3. Maybe this will help someone.
I (sadly) have to deploy a rails application on Windows XP which has to connect to Microsoft SQL Server 2005.
Surfing in the web there are a lot of hits for connect from Linux to SQL Server, but cannot find out how to do it from Windows.
Basically I followed these steps:
Install dbi gem
Install activerecord-sql-server-adapter gem
My database.yml now looks like this:
development:
adapter: sqlserver
mode: odbc
dsn: test_dj
host: HOSTNAME\SQLEXPRESS
database: test_dj
username: guest
password: guest
But I'm unable to connect it. When I run rake db:migrate I get
IM002 (0) [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I'm not a Windows user, so cannot understand really well the meaning of dsn element or so.
Does someone have an idea how to solve this?
Thanks in advance
With Alexander tips now I've modified my database.yml to:
development:
adapter: sqlserver
mode: odbc
dsn: Provider=SQLOLEDB;Data Source=SCADA\SQLEXPRESS;UID=guest;PWD=guest;Initial Catalog=test_dj;Application Name=test
But now rake db:migrate returns me:
S1090 (0) [Microsoft][ODBC Driver Manager] Invalid string or buffer length
Am I missing something?
this is a sample DSN, that connects to the database using the Windows user account (best when corporate network with domain login)
Provider=SQLOLEDB;Data Source=MyServer\MyInstance;Integrated Security=SSPI;Initial Catalog=MyDatabase;Application Name=My Application Name that will show up in the trace
So this uses the OLEDB provider for SQL Server. SQLNCLI can also be used, haven't tried it with ODBC. Actually this DSN isn't quite tested (have to wait for my admin to give me the necessary rights), but it was copied from a working script, that used SQLNCLI as the provider. The Data source is the server, and if it has a named instance, it has to be specified, so it's either just Server or Server\Instance. The Integrated Security=SSPI tells it you want to use Windows Authentication. Otherwise you specify the user and password to use using UID=MyUser;PWD=MyPassword. UID, User, Username, Password - I think all of these parameters work.
There is a great site over the internet that provides all kinds of DSN samples, just can't find it anywhere. If I find it, I will let you know.
If you haven't got any provider in Rails, check out if Rails supports Windows Component Object Model (COM). And if it does, you can even initialize the ADODB.Connection COM class, work with ADO thereon.
Ah, here is that site I was talking about: http://www.connectionstrings.com/
I have an older database Oracle RDB. I used ODBC on Windows with .net, but I'm not sure how to proceed on RoR on a Mac OS X server. I don't know how I do it on Windows either with RoR.
I was hoping for general direction.
EDIT: I searched for activerecord and rdb but have nto found it yet. I saw references to rdb$database and so on in code for firebird but that's it.
How old? because there are some resources for Rails and Oracle, like this
http://www.oracle.com/technology/pub/articles/haefel-oracle-ruby.html
or maybe you could try with JRuby and JDBC, it's super easy, you have to copy the oracle jdbc jar file in the jruby/lib folder, and then in the rails project setup your database (config/database.yml) like this
production:
adapter: jdbc
driver: oracle.jdbc.OracleDriver
url: jdbc:oracle:thin:#you_server_address:1521:instanceName
username: user
password: pass
You need to use the Oracle Rdb specific JDBC driver. Go to http://www.oracle.com/technetwork/database/rdb/index-090638.html
This question shows how to configure RoR with Oracle on linux and mac:
How to configure Ruby on Rails with Oracle?
Oracle RDB is different from Oracle RDBMS