My app (ruby on rails) is in linux and I need connect in a Sql Server database.
Testing in command line I get:
$tsql -LH 10.10.10.10
ServerName MYCOMPSRV10
InstanceName SQL2008R2
IsClustered No
Version 10.50.4000.0
tcp 58891
And I can access database in command line using:
$tsql -S 10.10.10.10\\SQL2008R2 -U username
So, in my Ruby on Rails app I have database.yml with this code:
development:
adapter: sqlserver
host: 10.10.10.10
database: MyDatabase
username: username
password: password
port: 1433
pool: 5
timeout: 5000
But when I try run the app I get:
TinyTds::Error: Unable to connect: Adaptive Server is unavailable or does not exist
If I change config an try to add Database Instance Name:
development:
adapter: sqlserver
host: '10.10.10.10\SQL2008R2'
database: MyDatabase
username: username
password: password
port: 1433
pool: 5
timeout: 5000
And try run the App:
TinyTds::Error: Server name not found in configuration files
I did a research and don't found how to solve this problem. I even don't found how to set the instance name of database. Can someone help me ?
I found a solution:
install: unixodbc unixodbc-bin unixodbc-dev
sudo apt-get install unixodbc unixodbc-bin unixodbc-dev
uninstall freetds-bin
freetds-dev
freetds-common
sudo apt-get purge freetds-bin freetds-dev freetds-common
download freetds current and install:
tar -xzf freetds-patched.tar.gz
cd freetds-1.00.15/
./configure
make
sudo make install
I discovered the dinamic port of my db instance trough this query:
SELECT local_tcp_port
FROM sys.dm_exec_connections
WHERE session_id = @@SPID
and change database.yml config adding this port instead default 1433
development:
<<: *default
host: 10.10.10.10
username: myuser
password: mypwd
port: 58891
after that I run:
rake db:migrate
Everything worked fine
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.