Thursday, August 23, 2007

Ruby and SQL Server

Just some quick notes for me to remember. When using DBI to connect to SQL Server 2005, use a connection string like:

db=DBI.connect("DBI:ADO:Provider=SQLNCLI;Data Source=.\\SQLEXPRESS;Initial Catalog=databasename;User Id=user;Password=password")

I also ran into a problem with the ADO.rb file. I was getting the following error message when trying to run a second query:

OLE error code:80004005 in Microsoft OLE DB Provider for SQL Server
Cannot create new connection because in manual or distributed transaction mode.

It was starting transactions automatically. I'd rather do that explicitly anyways, so i created a new begin method and commented out all the default BeginTrans() calls. Seems to have solved the problem.

No comments: