"undefined method `database'" 使用 TinyTDS 客户端时出错
"undefined method `database'" error using TinyTDS client
代码如下:
client = TinyTds::Client.new username: 'sa', password: 'secret', host: 'mydb.host.net, database: MYDB, dataserver: MYDS'
我想测试连接并报告它是否存在:
if client.active?
puts "Connection to #{client.database} on #{client.dataserver} is alive"
else
puts "Unable to establish connection to #{client.database} on #{client.dataserver}"
end
这是错误:
<main>': undefined method `database' for #<TinyTds::Client:0x007f8b9384d840> (NoMethodError)
如果客户端是一个对象,我如何访问database
和dataserver
?
在我看来你做不到。 tiny_tds 非常低级,并且有一个非常基本的 API。考虑使用 sequel as a higher-level database access layer that will give you a more convenient API to work with. Sequel can use tiny_tds 访问适当的数据库。
代码如下:
client = TinyTds::Client.new username: 'sa', password: 'secret', host: 'mydb.host.net, database: MYDB, dataserver: MYDS'
我想测试连接并报告它是否存在:
if client.active?
puts "Connection to #{client.database} on #{client.dataserver} is alive"
else
puts "Unable to establish connection to #{client.database} on #{client.dataserver}"
end
这是错误:
<main>': undefined method `database' for #<TinyTds::Client:0x007f8b9384d840> (NoMethodError)
如果客户端是一个对象,我如何访问database
和dataserver
?
在我看来你做不到。 tiny_tds 非常低级,并且有一个非常基本的 API。考虑使用 sequel as a higher-level database access layer that will give you a more convenient API to work with. Sequel can use tiny_tds 访问适当的数据库。