首页 > 编程技术 > php

win98 PWS环境下连接读取远程SQLServer

发布时间:2016-11-25 16:44

from: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=6518
Connect/Read Remote SQL server Using PWS in win 98
I had to test Microsoft's Personal Webserver (PWS) in win 98 to access Remote SQL server 7.0
installed in a NT server. The clients to win 98 had LAN connections. Easy one , don't vote, have fun with
PWS. In fact I tested my connection with this script, before I created an out of process server demo with
VB.





code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

Terms of Agreement:
By using this code, you agree to the following terms...
1) You may use this code in your own programs (and may compile it into a program and distribute it in
compiled format for langauges that allow it) freely and with no charge.
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the
original author. Failure to do so is a violation of copyright laws.
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the code or
code's description.

'**************************************
' Name: Connect/Read Remote SQL server U
' sing PWS in win 98
' Description:I had to test Microsoft's
' Personal Webserver (PWS) in win 98 to ac
' cess Remote SQL server 7.0 installed in
' a NT server. The clients to win 98 had L
' AN connections. Easy one , don't vote, h
' ave fun with PWS. In fact I tested my co
' nnection with this script, before I crea
' ted an out of process server demo with V
' B.
' By: Manas Mukherjee
'
这里有几个关于SQL SERVER的问题想向您请教(服务器端脚本编程):
(1)如何在SQL SERVER中用SQL语句获得当前的数据库名称?
(2)如何在定义一个全局变量而不是局部变量,因为我在这里定义了
一个循环,在这个循环里有对一个临时表加字段和对临时表插入数据
的操作。但这两个操作必须放在不同的批次里.(需要用GO语句分开)。
这时控制循环的变量参数就不起作用了,因为变量参数只能在一个
批次里起作用,到下一个批次就要重新定义了。真头疼!能不能定义
全局变量,让它在所有批次中都起作用?
这两个问题,其实并不具有一定的普遍性,但是解决这两个问题的 思路和方法 却有一定的 普遍性,所以我专门把这两个问题拿出来 讲一下
(1)首先 这个当前 所在 DataBase 肯定需要用到 系统存储过程 这一点是 十分肯定的,我自然想到了sp_who 执行后,列出了当前所有的 系统进程的 所有信息,我一看 有 Runnable,有 Slepping 肯定应该是 runnable 了,一看 他的 spid 想起来了,有个系统的 全局变量@@SPID,先试一下,sp_who @@spid 哈哈 成功了这个问题的解决之道 是 一定要熟悉 系统的存储过程和系统全局变量,并且要善于观察和思考
(2) 至于 第二个问题,则纯粹是一种 t-sql 编程的思路问题,首先我不赞同用一个规则去判断两个 存储过程,因为这不符和 t-SQL 编程的规范,但是既然问题出来了,就要想办法 解决,我们知道在 两个批次里 是不可能共巷数据的,所以 我想到了 cursor 游标,最终 经过测试,也成功了。

在SQL Server中提供了这种恢复方式的存储过程。
一个数据库包括两个文件,mdf数据库文件和ldf日志文件
1.sp_attach_db [@dbname =] 'dbname',[@filename1 =] 'filename_n'
给系统添加一个数据库,在dbname指定数据库名称,filename_n指定数据库的文件和日志文件。比如我有一个ji的库,停止SQL Server服务备份ji_data.mdf,ji_log.ldf,启动SQL server,删除掉这个库,然后再把这两上文件拷到sql server DATA目录中,在Query Analyzer中执行如下语句:
EXEC sp_attach_db @dbname = N'ji',
@filename1 = N'd:mssql7dataji_data.mdf',
@filename2 = N'd:mssql7dataji_log.ldf'
就会把这个库加入到SQL Server Group中.

如果你用的是sql server数据库!你不想用后台操作你可以看看这个
下面是对text的操作你可以看看
1. 写操作(WRITETEXT)
这里一般要用到的函数有TextPtr获得文本字段的指针,和TextVaild检验指针的有效性,@@RowCount判断返回记录的条数。
其基本方法是:用Textptr函数得到指针,判断其有效性,用Writetext写数据
函数说明:Textptr(字段名)。Writetext tablename。Fieldname @textptr(指针) [With Log] data(数据)
例如:
Begin Tran
Declare @Mytextptr VarBinary(16)
Select @mytextptr=textptr(pr_info)
From Pub_Info (updlock)
Where pud_id=’9999’
IF @Mytextptr Is Not Null
Writetext pub_info.pr_info @mytextptr with log 'data’
Commit Tran
2. 读操作
常用函数
PatIndex('%exp%’,var|fieldname。。)
Datalength()
@@TextSize 文本大小
SettextSize N 设置文本大小
ReadText {TableName。FieldName} {@textptr} Offet Size [HoldLock]
例如:
begin tran
Declare @mytextptr Varbinary(16),@Totalsize int,@Readsize int,@lastread int
Set textsize 100
Select @mytextptr=textptr(pr_info), @totalsize=datalength(pr_info)
@lastread=0,
@readsize= case when (textsize<datalength(pr_info) then textsize
eles datalength(pr_info)
end
From Pub_info
Where Pub_id=’1622’
IF @mytextptr Is not Null and @readsize>0
While (@lastread<@totalsize)
ReadText pub_info.pr_info @mytextptr @lastread @readsize holdlock
If (@@error<>0)
Break
Select @lastread=@lastread @readsize
If ((@readsize @lastread)>@totalsize)
Select @readsize=@totalsize-@lastread
End
Commit Tran
3.数据更新UpdateText
更新数据代替了写操作,其基本语法是:
UpdateText Table_Name.Col_Name Text_Ptr Offest(偏移量) Deleted_Length
[With Log] [Inserted_Data|Table_Name.Scr_Column_name Str_Text_Ptr]
说明:
Offest:0说明从开头开始,Null表示你向当前内容追加数据。
Deleted_Length:0表示不删除任何内容,Null表示删除所有内容。
解决SQL2k降序索引上使用对比条件更新或删除的bug我在SQL server 2000 enterprise 和 personal 都试过了, 每次都这样。:(
详细情况看我的回贴:
SQl server 7.0 中的确没有问题, sql 2000 中(enterprise 和 personal版本都可以),
表要有聚簇索引,并且索引的顺序是降序,
例如 按下列DDL sql 建立的表
CREATE TABLE [AType] (
[AID] [int] NOT NULL ,
[name] [varchar(20)] NOT NULL ,
CONSTRAINT [PK_DateType] PRIMARY KEY CLUSTERED
([AID] DESC) ON [PRIMARY] ,
) ON [PRIMARY]
添一些数据后, AID 分别分布在1-100之间
INSERT INTO [AType] VALUES(1,'a')
INSERT INTO [AType] VALUES(50,'b')
INSERT INTO [AType] VALUES(100,'c')

select from atype where Aid < 50
go
delete from Atype where AID < 50
go
select from atype where Aid < 50
最后一句查询仍然有记录输出. :(
by 怡红公子
报告已经发送给MSSQL开发小组,他们承认这一错误。
在没有新的补丁出来之前,给出以下建议:
不要在单列上使用降序索引,因为这并没有在性能上带来好处,仅仅是省略了Order by field desc几个字而已,用qa的show plan看一下就知道了,不管有没有order by或者不管是asc还是desc,都没有这项开销的(在聚簇索引上)。
降序索引一般是用于复合索引的,这可能是这个bug出现的原因。
原文:
Note that there is no need to create a descending index on a single column because SQL Server can traverse
an ascending index backwards when appropriate. Descending is normally used only in composite indexes.
This is probably why the bug surfaces here

标签:[!--infotagslink--]

您可能感兴趣的文章: