从Windows将Rails应用程序连接到SQL Server 2005 [英] Connect rails application to SQL Server 2005 from Windows

查看:88
本文介绍了从Windows将Rails应用程序连接到SQL Server 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(不幸)我必须在Windows XP上部署 rails 应用程序,该应用程序必须连接到 Microsoft SQL Server 2005 .

I (sadly) have to deploy a rails application on Windows XP which has to connect to Microsoft SQL Server 2005.

在网上冲浪时,从Linux到SQL Server的连接颇受关注,但找不到从Windows进行连接的方法.

Surfing in the web there are a lot of hits for connect from Linux to SQL Server, but cannot find out how to do it from Windows.

基本上,我按照以下步骤操作:

Basically I followed these steps:

  • 安装 dbi gem
  • 安装 activerecord-sql-server-adapter gem
  • Install dbi gem
  • Install activerecord-sql-server-adapter gem

我的 database.yml 现在看起来像这样:

My database.yml now looks like this:

development:
  adapter: sqlserver
  mode: odbc
  dsn: test_dj
  host: HOSTNAME\SQLEXPRESS
  database: test_dj
  username: guest
  password: guest

但是我无法连接它.当我运行 rake db:migrate 时,我会得到

But I'm unable to connect it. When I run rake db:migrate I get

IM002 (0) [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

我不是Windows用户,所以不能很好地理解 dsn 元素的含义. 有人知道如何解决这个问题吗?

I'm not a Windows user, so cannot understand really well the meaning of dsn element or so. Does someone have an idea how to solve this?

预先感谢

现在有了亚历山大(Alexander)的技巧,我已经将我的database.yml修改为:

With Alexander tips now I've modified my database.yml to:

development:
  adapter: sqlserver
  mode: odbc
  dsn: Provider=SQLOLEDB;Data Source=SCADA\SQLEXPRESS;UID=guest;PWD=guest;Initial Catalog=test_dj;Application Name=test

但是现在 rake db:migrate 返回了我:

S1090 (0) [Microsoft][ODBC Driver Manager] Invalid string or buffer length

我想念什么吗?

推荐答案

这是一个示例DSN,它使用Windows用户帐户连接到数据库(最好是使用域登录的公司网络)

this is a sample DSN, that connects to the database using the Windows user account (best when corporate network with domain login)

Provider=SQLOLEDB;Data Source=MyServer\MyInstance;Integrated Security=SSPI;Initial Catalog=MyDatabase;Application Name=My Application Name that will show up in the trace

因此这将OLEDB提供程序用于SQL Server.也可以使用SQLNCLI,但尚未在ODBC上尝试过.实际上,此DSN尚未经过充分测试(必须等待我的管理员为我提供必要的权限),但是它是从使用SQLNCLI作为提供程序的工作脚本中复制的.数据源是服务器,如果它具有命名实例,则必须指定它,因此它只能是ServerServer\Instance. Integrated Security=SSPI告诉您要使用Windows身份验证.否则,您可以使用UID=MyUser;PWD=MyPassword指定要使用的用户和密码. UID,用户,用户名,密码-我认为所有这些参数都有效.

So this uses the OLEDB provider for SQL Server. SQLNCLI can also be used, haven't tried it with ODBC. Actually this DSN isn't quite tested (have to wait for my admin to give me the necessary rights), but it was copied from a working script, that used SQLNCLI as the provider. The Data source is the server, and if it has a named instance, it has to be specified, so it's either just Server or Server\Instance. The Integrated Security=SSPI tells it you want to use Windows Authentication. Otherwise you specify the user and password to use using UID=MyUser;PWD=MyPassword. UID, User, Username, Password - I think all of these parameters work.

互联网上有一个很棒的网站,提供各种DSN样本,只是在任何地方都找不到.如果找到它,我会让你知道.

There is a great site over the internet that provides all kinds of DSN samples, just can't find it anywhere. If I find it, I will let you know.

如果Rails中没有任何提供程序,请检查Rails是否支持Windows组件对象模型(COM).如果可以的话,您甚至可以初始化ADODB.Connection COM类,并在其上使用ADO.

If you haven't got any provider in Rails, check out if Rails supports Windows Component Object Model (COM). And if it does, you can even initialize the ADODB.Connection COM class, work with ADO thereon.

啊,这是我正在谈论的站点: http://www.connectionstrings.com/

Ah, here is that site I was talking about: http://www.connectionstrings.com/

这篇关于从Windows将Rails应用程序连接到SQL Server 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆