易截截图软件、单文件、免安装、纯绿色、仅160KB

ruby 连接操作 sql2005


The following is improved version of the code created by David Mullet, from
http://rubyonwindows.blogspot.com/2007/03/ruby-ado-and-sqlserver.html
require 'win32ole'
class SqlServer
# This class manages database connection and queries
attr_accessor :connection, :data, :fields
attr_writer :username, :password
def initialize(host, username = 'sa', password='')
@connection = nil
@data = nil
@host = host
@username = username
@password = password
end
def open(database)
# Open ADO connection to the SQL Server database
connection_string = "Provider=SQLOLEDB.1;"
connection_string << "Persist Security Info=False;"
connection_string << "User ID=#{@username};"
connection_string << "password=#{@password};"
connection_string << "Initial Catalog=#{database};"
connection_string << "Data Source=#{@host};"
connection_string << "Network Library=dbmssocn"
@connection = WIN32OLE.new('ADODB.Connection')
@connection.Open(connection_string)
end
def query(sql)
# Create an instance of an ADO Recordset
recordset = WIN32OLE.new('ADODB.Recordset')
# Open the recordset, using an SQL statement and the
# existing ADO connection
recordset.Open(sql, @connection)
# Create and populate an array of field names
@fields = []
recordset.Fields.each do |field|
@fields << field.Name
end
begin
# Move to the first record/row, if any exist
recordset.MoveFirst
# Grab all records
@data = recordset.GetRows
rescue
@data = []
end
recordset.Close
# An ADO Recordset's GetRows method returns an array
# of columns, so we'll use the transpose method to
# convert it to an array of rows
@data = @dat


相关文档:

SQL Server 2005 镜像构建手册(2)

SQL Server 2005 镜像构建手册(2)
3、 建立镜像
由于是实验,没有为服务器配置双网卡,IP地址与图有点不一样,但是原理一样。
--主机执行:
1ALTER DATABASE shishan SET PARTNER = 'TCP://10.168.6.45:5022';
--如果主体执行不成功,尝试在备机中执行如下语句:
1ALTER DATABASE ......

SQL经典行转列

--测试表
create table tb_month
(monthid varchar(2),mongthName varchar(50))
insert into tb_month
select '01','一月'
union all select '02','二月'
union all select '03','三月'
union all select '04','四月'
union all select '05','五月'
union all select '06','六月'
union all select '07','七月'
......

在XP上安装SQL 2000 Server(摘转)

今天从网络上找到了在XP上安装SQL 2000 Server的方法,此前我一直认为这是行不通的,后面google一查,还真是可以,有很多网站都说这个方法可行,我就让lp试试看,结果真行,转载一下吧: 在Windows XP上安装SQL Server 2000的主要流程为:
一、在SQL服务器的安装盘中找到MSDE这个目录,并且点击setup.exe安装它,过程 ......

Sql分页代码

select * from books
where 1=1
and categoryid=29
and title like('%ASP.NET%')
and unitprice>10
order by id
Select top 20 * from books order by id
--m:每页显示行数 n:当前页数
select Top m * from books
where id not in
(Select top m(n-1) id from books order by id)
order by id
select * fro ......

SQL分组排序

今天遇到个有意思的问题,是一个分组排序的问题,不过要求分组和分组间也要排序,如果这个组内有一条数据是最近更新的,那么这整个组都应该排在前面。
下面以Oracle的HR示例Schema中的employees表为例:
语句按部门分组,分组之间的排序是这样的:如果整个分组中有一个员工的hire_date是最新的,那么这个分组就应该排在其 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号