问题描述
我正在尝试设置一个Rails应用程序来查询远程托管的SQLAnywhere 16数据库并以HTML形式显示一些查询信息。我在Mac El Capitan上使用的是Ruby和Rails的当前版本。远程服务器正在运行Windows。该服务器位于我的建筑物中,并且位于同一局域网中,因此,如果有一个更简单的解决方案,涉及物理上访问机箱本身,那么我很乐意。
在Windows机器上,我可以连接到服务器并使用SQL客户端在数据库上进行查询。
我有 sqlanywhere
和 activerecord-sqlanywhere-adapter
宝石已安装。我的Mac机器上也安装了SQL Anywhere 16客户端。远程数据库在我的 database.yml
文件中设置为另一个数据库:
my_external_database:
适配器:sqlanywhere
编码:utf-8
用户名:(用户名)
密码:(密码)
服务器:(服务器名称)
数据库:(数据库名称)
主机:(服务器IP)
I
class MyExternalModel< ActiveRecord :: Base
建立连接(:my_external_database)
self.table_name ='<数据库中的特定表>'
self.primary_key ='primarykey'
结束
当我进入Rails控制台并执行 MyExternalModel.first
测试连接,我得到:
LoadError:无法加载SQLAnywhere DBCAPI库
在执行一些谷歌搜索之后,这似乎是配置SQLAnywhere的问题。但是,我相信我已经正确配置了它(使用bin64配置在bash中),如下所示:
。 /Applications/SQLAnywhere16/samples/sample_config64.sh
输入样本副本的目标目录[/ Users /(user)/ sa16_samples]:
复制样本...
完成
设置数据源...
SQL Anywhere数据源实用程序版本16.0.0.2041
配置将 SQL Anywhere 16演示写入文件/ Users /(user)/ .odbc.ini
SQL Anywhere数据源实用程序版本16.0.0.2041
配置将 SQL Anywhere 16 CustDB写入文件/Users/(user)/.odbc.ini
完成
设置sample_env脚本...
完成
尽我所能。任何建议,不胜感激!
我将SQLAnywhere用于生产服务器,并且使用与您使用的相同的gem可以正常工作。我使用Mac进行开发,并且数据库在Windows(或Linux)上运行。
为了摆脱此错误,请尝试命令(在Mac上):
#将SQLAnywhere调整为您的版本-> 16
源/Applications/SQLAnywhere12/System/bin64/sa_config.sh
我
之后,尝试加载控制台(rails c)并在那里进行一些测试。 / p>
I am trying to set up a Rails app to query a remotely hosted SQLAnywhere 16 db and to display some query information as HTML. I'm using current versions of Ruby and Rails on Mac El Capitan. The remote server is running Windows. The server is located in my building and I am on the same LAN, so if there's a simpler solution that involves accessing the box itself physically I'm open to that.
On my Windows machine I am able to connect to the server and do queries on the db using a SQL client.
I have sqlanywhere
and activerecord-sqlanywhere-adapter
gems installed. I also have the SQL Anywhere 16 client installed on my (Mac) machine. The remote db set up in my database.yml
file as another db:
my_external_database:
adapter: sqlanywhere
encoding: utf-8
username: (username)
password: (password)
server: (name of server)
database: (db name)
host: (IP of server)
I'm calling it like so:
class MyExternalModel < ActiveRecord::Base
establish_connection(:my_external_database)
self.table_name = '<a particular table in the db>'
self.primary_key = 'primarykey'
end
When I go into the rails console and do MyExternalModel.first
to test the connection, I get:
LoadError: Could not load SQLAnywhere DBCAPI library
After doing some googling, this seems to be a problem with configuring SQLAnywhere. However, I believe I configured it properly (in bash using bin64 config), like so:
. /Applications/SQLAnywhere16/samples/sample_config64.sh
Enter destination directory for copy of the samples [/Users/(user)/sa16_samples]:
Copying samples...
Done
Setting up data sources...
SQL Anywhere Data Source Utility Version 16.0.0.2041
Configuration "SQL Anywhere 16 Demo" written to file /Users/(user)/.odbc.ini
SQL Anywhere Data Source Utility Version 16.0.0.2041
Configuration "SQL Anywhere 16 CustDB" written to file /Users/(user)/.odbc.ini
Done
Setting up sample_env script...
Done
This is as far as I'm able to get. Any recommendations are greatly appreciated!
I use SQLAnywhere for a production server and it works fine using the very same gem you're using. I use a Mac for development and my database is running in Windows (or Linux).In order to get rid of this error, try the command (on your Mac):
# adjust SQLAnywhere to your version -> 16
source /Applications/SQLAnywhere12/System/bin64/sa_config.sh
I'm using Rails 4 and SQLAnywhere 12 (but tested with 16 and it works too).
After that, try to load console (rails c) and do some tests there.
这篇关于如何使用Rails查询远程SQLAnywhere16数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!