Tag: sql server

使用ActiveRecord连接到SQL Server

您是否曾经使用ActiveRecord连接到SQL Server? 这可能吗? 任何人都可以提供一些起点吗?

使用ActiveRecord更新不是主键的旧“ID”列

我正在使用Rails和activerecord-sqlserver-adapter gem来尝试将数据添加到旧的MS SQL数据库,其中dbo.Condition表具有名为ConditionSeq的主键和存储用户ID的外键列ID。 class Condition < ActiveRecord::Base # using lowercase_schema_reflection = true self.table_name = :condition self.primary_key = 'conditionseq' end 每次我写Condition.new(conditionseq: nil, id: 12345) (或甚至Condition.new(id: 12345) ),希望让MS SQL自动增加conditionseq列,ActiveRecord无益地假设我实际上想要设置主要12345的关键。 基于类似的问题 ,特别是@cschroed的回答和后续评论 ,我尝试重新打开ActiveRecord :: AttributeMethods :: Write( source )来添加一个放弃attr_name ==“id”检查的write_id_attribute方法: # config/initializers/write_id_attribute.rb module ActiveRecord module AttributeMethods module Write extend ActiveSupport::Concern # Add a method to allow us to […]

rake db出错:使用tiny_tds和sqlserver adapter进行迁移

当我尝试使用rake db:migrate此错误: LoadError: cannot load such file — tiny_tds/tiny_tds D:/myrailsapp/config/application.rb:7:in `’ D:/myrailsapp/Rakefile:4:in `require_relative’ D:/myrailsapp/Rakefile:4:in `’ LoadError: 126: The specified module could not be found. – D:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/tiny_tds-1.1.0-x86-mingw32/lib/tiny_tds/2.2/tiny_tds.so D:/myrailsapp/config/application.rb:7:in `’ D:/myrailsapp/Rakefile:4:in `require_relative’ D:/myrailsapp/Rakefile:4:in `’ (See full trace by running task with –trace) 这是我的database.yml文件: # # Ensure the SQLite 3 gem is defined in your Gemfile # gem […]

MS SQL Ruby Gem

我需要编写一个ruby脚本来连接到MS SQL Server数据库,但我发现的所有线程都指向gems以将ActiveRecord绑定到MS SQL。 是否有任何gem可以让我这样做pg(对于postgres https://github.com/ged/ruby-pg )? 我只需要做一些非常简单的远程查询,非常感谢!

TinyTds错误:Adaptive Server连接超时

我们在rails 3.2.12(ruby 1.9.3)上使用当前tinyTDS gem 0.6.2在rails应用程序上运行ruby。 我们使用MS SQL 2012或2014,面对更常见的以下错误消息: TinyTds::Error: Adaptive Server connection timed out: EXEC sp_executesql […] 数据库AUTOCLOSE已关闭。 TCP套接字超时是默认的Windows系统。 应用程序服务器位于计算机#1(Windows服务器)上,SQL服务器位于计算机#2(Windows服务器)上。 当我检查连接(netstat)时,我想为大约20-30个用户打开250个连接。 我运行perform.exe来查看SQL服务器上的数据和日志磁盘的空闲时间。 database.yml有连接pool:32并reconnect:true 。 对我而言,看起来tinyTDS失去连接,任何exception都无法重新连接。 问题是,如何调试问题以找出问题所在? UPDATE 我的错误,原始错误消息属于tinytDS 0.5.x. 自从我更新到最新版本后,我得到以下错误: ActiveRecord::LostConnection (TinyTds::Error: DBPROCESS is dead or not enabled: BEGIN TRANSACTION):

Rails使用MS SQL服务器数据库

在我的rails应用程序中,我需要使用现有的MS SQL数据库。 我试过按照本手册: http://rubyrailsandwindows.blogspot.com/2008/03/rails-2-and-sql-server-2008-on-windows_24.html 我不知道如何做模型,脚手架等因为rails不能简单地使用另一个db。 我不想在MS SQL数据库中为我的表运行rake db:migrate。 我还需要在模型中写什么? 如果简单:使用MS SQL服务器数据库中的表,但我也想解决迁移等问题。

rails 4 activerecord TypeError nil不是符号

看来sql server中的表是在select语句中放置nil 。 我不知道如何解决这个问题,如果我切换到任何其他表,我可以很容易地获得第一个记录。 还有其他人处理过这个bug吗? 我把桌子分开并构建了一个视图。 它仍然这样做。 猴子修补这个犹豫不决。 想法? 我是如何连接到SQL Server的: 我的模特: class Deal < ActiveRecord::Base self.table_name = 'vwStorePromosExtSummaryGlobal' end 我的控制器: class V1::DealsController 0.6.1′ gem ‘activerecord-sqlserver-adapter’, github: ‘arthrex/activerecord-sqlserver-adapter’ gem ‘active_model_serializers’, ‘~> 0.8.1’ 当我打开gem中的确切错误时,我看到: 97: def serializable_hash(options = nil) 98: options ||= {} 99: 100: attribute_names = attributes.keys 101: if only = options[:only] 102: attribute_names &= […]

从数据库获取SASS(编译传递的数据而不是从文件中读取)

有没有办法让SASS编译数据从数据库传递? 我可以使用DBI + ODBC从MSSQL Server 2008获取数据,但是如何使SASS编译传递数据而不是文件? 没有找到任何有用的东西,改变sass核心文件听起来不是一个好主意…特别是考虑零Ruby知识。

Rails中与数据库无关的SQL字符串连接

我想在Rails查询中进行数据库端字符串连接,并以与数据库无关的方式进行。 SQL-92指定双栏( || )作为连接运算符。 不幸的是,它看起来像MS SQL Server不支持它; 它用+代替。 我猜测Rails的SQL语法抽象已经解决了特定于db的运算符问题。 如果确实存在,我该如何使用它?