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
相关文档:
http://support.microsoft.com/default.aspx/kb/237980/zh-cn
将 Access 数据库转换为 SQL Server 的最简便方法是使用升迁向导。升迁向导:
保留数据库结构,包括数据、索引和默认设置。
自动将 Access 有效性规则和默认设置转换为适当的 SQL Server 等效内容。
在升迁后保持表关系和参照完整性。
要在 Access 2000 ......
SQL Server 2005 镜像构建手册(2)
3、 建立镜像
由于是实验,没有为服务器配置双网卡,IP地址与图有点不一样,但是原理一样。
--主机执行:
1ALTER DATABASE shishan SET PARTNER = 'TCP://10.168.6.45:5022';
--如果主体执行不成功,尝试在备机中执行如下语句:
1ALTER DATABASE ......
--测试表
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','七月'
......
在SQL Server中, 我们有时需要在清空数据表之后,重新添加记录时,标识列重新从1开始计数。
我们只需要在插入记录之前,执行下面的命令:
DBCC CHECKIDENT (表名, RESEED, 0)
如果是清空表中内容再重置标识列可以选择使用 Truncate Table 命令:
Truncate Table tablename
TRUNCATE TABLE 在功能上与不带 WHERE 子句的 ......
select * from sq_donglong.achi_news where ID in (select ID from (select top 6 ID from sq_donglong.achi_news where SortID=82)a union all select ID from (select top 6 ID from sq_donglong.achi_news where SortID=84)b)
......