简体   繁体   English

连接失败,数据库有'。' 在名字中

[英]Connection fails, database has '.' in name

I've been trying to debug a SQL Server database error in one of our rails apps. 我一直在尝试在我们的一个rails应用程序中调试SQL Server数据库错误。 The problem is that the database name, as added in database.yaml, has a '.' 问题是database.yaml中添加的数据库名称有一个'.' in it ( 'testdb.v1' ). 在它( 'testdb.v1' )。 It results in the error: 它导致错误:

TinyTds::Error: Database 'testdb' does not exist. Make sure that the name is entered correctly.

Thinking that this was a YAML vs. Rails issue with quoting of the '.' 认为这是一个YAML与Rails问题引用'。' character, I opened the app in rails console and tried every kind of Ruby quoting I could think of, but I get the same error each time. 我在rails控制台中打开了应用程序并尝试了我能想到的各种Ruby引用,但每次都得到相同的错误。

Somewhere down the line from the assignment of the database name in my model.connection_config , the '.' 在我的model.connection_config分配数据库名称的某个地方,'。' is being interpreted as a format specifier and the suffix is dropped from the name. 被解释为格式说明符,并从名称中删除后缀。 model.connection_config['database'] has 'testdb.v1' , as it should, but clearly that's not what's being handed to SQL Server. model.connection_config['database']'testdb.v1' ,但显然不是那些被传递给SQL Server的东西。

I wasn't sure if this is a rails issue or a SQL Server issue, though a C# app I tossed together manages to open the database without problems. 我不确定这是一个rails问题还是一个SQL Server问题,虽然我一起扔的C#应用​​程序设法打开数据库没有问题。 Thus, I assume it's a rails/ActiveRecord issue. 因此,我认为这是一个rails / ActiveRecord问题。 Unfortunately, I don't have the option of changing the database name. 不幸的是,我没有更改数据库名称的选项。

Is there a way to quote the '.' 有没有办法引用'。' character so that it will maintain the '.' 字符,以便它将保持'。' and the suffix in the database name? 和数据库名称中的后缀?

Further investigation took me to the github page for the activerecord-sqlserver-adapter 进一步的调查把我带到了activerecord-sqlserver-adapter的github页面

There, I found issues 230 and 226 , with similar problems to mine. 在那里,我发现了问题230226 ,与我的问题类似。 Apparently using '.' 显然使用'。' in database, table or column names will present similar problems. 在数据库,表或列名称中会出现类似的问题。 As these were created in 2012 and are still open, it doesn't look like a fix is coming anytime soon. 由于这些是在2012年创建的并且仍处于打开状态,因此看起来不会很快出现修复。 In the comments there are a few ideas to monkey-patch it into working. 在评论中有一些想法可以将其修补到工作状态。 Guess that's the approach I'll have to take to get this working. 猜猜这是我必须采取的方法来实现这一目标。

UPDATE: For anyone stuck with a similar problem, and the database name is the only issue (not tables or columns), the solution we went with was an end-run around the sqlserver-adapter. 更新:对于遇到类似问题的人来说,数据库名称是唯一的问题(不是表或列),我们采用的解决方案是围绕sqlserver-adapter的最终运行。 We created a SQL user for each database, and assigned a default database to that user. 我们为每个数据库创建了一个SQL用户,并为该用户分配了一个默认数据库。 Then, we connected with the user login but left the database name null. 然后,我们使用用户登录进行连接,但将数据库名称保留为null。 SQL Server will connect to the default database in that case. 在这种情况下,SQL Server将连接到默认数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails连接中没有数据库名称 - Rails no database name in connection Rspec失败,因为名称已被使用 - Rspec fails for Name has already been taken Postgres连接失败,使用系统用户代替database.yml中提供的用户 - Postgres connection fails, uses system user instead the one provided in database.yml Rails 自定义 ActiveRecord::Type 在 has_many 中使用 `class_name` 时失败:通过关联 - Rails custom ActiveRecord::Type fails when using `class_name` in has_many :through association 在多服务器环境中,如果站点的闲置时间超过1500万,则服务器将失去与PostgreSQL数据库的连接 - In a multi-server environment, if a site has inactivity for more than 15 mn, the server loses connection to PostgreSQL database 我可以在ActiveRecord(或Mongoid)中为数据库连接和table_name配置线程安全的每个请求配置吗? - Can I have thread safe per-request configuration for database connection and table_name in ActiveRecord (or Mongoid)? Rails Postgresql数据库连接失败 - Rails postgresql DB connection fails Rails 4.2.1无法建立连接 - Rails 4.2.1 fails to establish a connection 将日期时间播种到数据库失败 - Seeding datetime into database fails {model name} 没有连接池 - No connection pool for {model name}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM