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)
3、 建立镜像
由于是实验,没有为服务器配置双网卡,IP地址与图有点不一样,但是原理一样。
--主机执行:
1ALTER DATABASE shishan SET PARTNER = 'TCP://10.168.6.45:5022';
--如果主体执行不成功,尝试在备机中执行如下语句:
1ALTER DATABASE ......
下列语句部分是Mssql语句,不可以在access中使用。
SQL分类:
DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
首先,简要介绍基础语句:
1、说明:创建数据库
......
准备工作
首先,操作系统中安装好SQL Server 2000/2005,如果系统中都装有2000和2005版,记得停用一个,只开一个行了。
然后,到微软网站下载Microsoft SQL Server 2005 JDBC Driver 1.1
,也可以使用这个地址直接下载
。
解压sqljdbc_1.1.1501.101_chs.exe,把sqljdbc_1.1复制到%ProgramFiles%(如果系统在C盘则为C:\ ......
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 ......