(计算机科学与技术专业论文)移动数据库同步模型的研究与应用.pdf_第1页
(计算机科学与技术专业论文)移动数据库同步模型的研究与应用.pdf_第2页
(计算机科学与技术专业论文)移动数据库同步模型的研究与应用.pdf_第3页
(计算机科学与技术专业论文)移动数据库同步模型的研究与应用.pdf_第4页
(计算机科学与技术专业论文)移动数据库同步模型的研究与应用.pdf_第5页
已阅读5页,还剩57页未读, 继续免费阅读

(计算机科学与技术专业论文)移动数据库同步模型的研究与应用.pdf.pdf 免费下载

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

武汉理工大学硕士学位论文 摘要 伴随着移动通信与计算技术的结合发展,移动终端拥有了更广泛的用途, 移动终端被人们使用来处理和存储各种数据比如名片、日程安排、邮件乃至文 档、目录等各种结构化或非结构化的数据,同时这些数据又通常需要在不同用 户之间进行交换以完成复杂的交互与合作。为了保证这种协作任务的正确完成, 必须有一种手段确保不同设备上的数据信息与中央服务器上的数据信息的及时 性与一致性,我们把这种手段定义为数据同步,数据同步已经成为移动计算的 一种基础应用模式,目前一些国际著名的数据库厂商也纷纷推出了自己的移动 数据库系统。 目前移动设备由于受网络条件和本身资源等因素的影响不能和中央服务器 保持实时通信,移动用户在网络断开状态下对数据的存取需求不能得出满足, 需要实现在无论何时何地都能获取和处理信息。移动数据库的数据同步解决方 案显得格外重要,本文正是围绕这一课题展开。 目前s q ls e f v e r 数据库同步的解决方案一般分为两种,一种是合并复制,它 允许移动应用程序对复制的数据自行更改,然后再将这些更改与s q ls e e r 数据 库进行合并,并在必要时解决数据冲突。另外一种是远程数据访问( r d a ) , 它使得移动应用程序能够方便地将远程m i c r o s o ns q ls e n ,e r 数据库表中的数据 读取( 拉) 到本地s q ls e r v e rm o b i l e 数据库表中,或者将移动数据库数据表中 的数据发送( 推) 到远程m i c r o s o rs q ls e r v e r 数据库表中。 使用r d a 解决方案时安装和进行安全设置的过程相对简单,这种方案在简单 表上工作得很好,但是如果需要在关联表或在用户间分割数据则可能会涉及到大 量的编程。本文将通过r d a 和r e p l i c a t i o n 两种不同解决方案之间的对比以及对 t a b l c c o w 表应用i a 同步的实例来介绍r d a 解决方案的优点以及这种方案所存 在的问题。 关键词:数据同步,合并复制,r d a 武汉理工大学硕士学位论文 a b s 仃a c t 心m o b i l ec 0 删嘶o n s 锄dc o m l 她t e c :b n o l o g ) ,砷锷m t 嗣d e v e l o p m e n t , m 0 b i l et a m i l l a lh 勰ab r o a d e r 瑚g co f l l s 鹤,p c o p l e 潞em o b i l ed e v i c e st 0h a n d l e 跹d s t o r ev a r i o l 塔一c a r d s ,s c h “l u l i n 岛争m a i la n de v e nd o c 啪咖s ,d i r e c t o r i 锚a l l d o m e rs t r i l c t u 】矧o r 瑚l s 协l c t u | 司d a t a ,t l l e s ed a t aa l s oo r e i ln d st 0b ee x c h a i l g e d b e t w 嘲d i f f e r e n tl 塔e r s t 0c o m p l e t et 1 1 ec o m p l e xi n t e f 剃o n 觚dc 0 h d l 删o n 。t o e l :峪u r em ep r o p e rc o m p l e t i o no fm i sc o l l a b o r a :t i v et a l s b ,w em _ i l s th a 、吧am 髓i 峪t 0 伽【鲫t l l a t 吐l ed a t as e t so fd i 丘l e 僦td e v i c 岱a i l dm ec 0 船i s t 既l c yo f l et i i n e l i 懈so f t l l ec o n t e n t ,w l l i c hw eh a _ v et 0d e 矗n ed a t as y n c h r 0 】1 i z a t i o n d a t as y n c h r 0 i l i z a l i o nh 弱 b e c o m eab 嬲i ca p p l i 刚o no fm o b i l ec o m p u 血l gm o d c l ,c 1 盯c l :i n y m eo ft l l e w o r l d sl e a d i n gd a 缸出鹤ev d o 璐h a v ea l s 0l 籼c h e di t so w nm o b i l cd 比出a s es y s t 锄 c u n c n tm o b i l ed e 、,i c e sc a nn o tm a i n t a i nar e a l - t i n l ec o m m u n i c a t i o nc a 删 s e r 、,e r i u et of a c t ss uc _ ha so w nr e s o u 】呛e sa n dn e t w o r kc o n d i t i o n s 。t l l ed 豇n a n d so f d a t aa c c e s s c 趾n o tb es a t i s 6 e di n 廿l ed i s c o 衄e c t e dn e t 、) i ,o r k t h ed a t aa c c 鼯s i n g 锄dp r o c 鼯s i n g n m s t b er e a l i z e du r g e i l t l yn om a t t e ri n 觚”m e r ea n da t 觚蛳m e m o b i l ed a t a b a s ed a t a s y n c h r o n i z a t i o nm e t l l o di sp 枷c u l 砌yi m p o r t a n t t h ep a p c rf o c u s e so nm i si s s u e c 1 埘铋t l ys q ls e n ,e rd a t a b 嬲es y i l c h r o n i z a t i o ns o l u t i o ni sd i v i d e di i l t 0t w o , o n ei st l l em 鸭er 印l i c a t i o n ,w i l i c ha l l o w sm o b i l ea p p l i c a t i o n st 0c o p yd a t ao nt h e i r o w nc h a i l g 鼹,l e nt h e s ec h a n g 懿c 0 如b i l l e dw i t l lt h es q ls e e rd a t a b 弱e 觚dd a t a n e c e s s a 巧t or e s o l v ec o n n i c t a n o t h e ri sm er e m o t ed a t aa c c e s s ( r d a ) ,w l l i c ha 1 1 0 w s i n o b i l ea p p l i c a t i o n st 0e 嬲i l yr e m o t em i c r o s o f is q ls e r v e rd a t a b a s et a b l ed a t ar e a d ( p u l l ) t ot l l el o c a ls q ls e r v e rm o b i l ed a t a b a s et a b l e ,0 rm o v ed a _ t ai i lad a t a b a s et a b l e t 0s 锄d ( p u s h ) t oai e m o t em i c r o s o f s q ls e r v e rd a t a b a s et a b l e u s i n gt l l er d as o l u t i o nf o rs e c u r e ,i n s t a l l a t i o na i l ds e t u pp f o c e s si sr e l a t i v e l y s i m p l e ,t l l i sp r o 黟a mw o r k sw e u o nas i m p l et a b l e ,b u ti fw o r k so na s s o c i a t i o nl i s t0 r t 1 1 eu s e rd a 妇m a yi i l v o l v eal a r g en u m b e ro fp r 0 争a i 】咖i n g 1 1 1t l l i s 枷c l e ,w ew i l l d e s 面b em ea d v a n t a g e so fr d as o l u t i o na 1 1 dt l l ep r o b l e i i l so f 眦c hp r 0 蓼a m s 岫u g l l 细od i 脏獭l ts o l u t i o n so fr d aa i l dr e p l i c a t i o na n ds p e c i 6 ce x 锄p l c so fc o m p 耐s o n k e y w o r d s :d a t as y n c h r o n i z a t i o n ,r e p l i ca _ t i o n ,r d a u 原创性声明和关于论文使用授权的说明 原创性声明 本人郑重声明:所呈交的学位论文,是本人在导师的指导下, 独立进行研究所取得的成果。除文中已经注明引用的内容外,本 论文不包含任何其他个人或集体己经发表或撰写过的科研成果。 对本文的研究做出重要贡献的个人和集体,均已在文中以明确方 式标明。本声明的法律责任由本人承担。 论文作者签名:旅徵 日期:二。p 多 关于学位论文使用授权的声明 本人完全了解武汉理工大学有关保留、使用学位论文的 规定,同意学校保留或向国家有关部门或机构送交论文的复 印件和电子版,允许论文被查阅和借阅;本人授权武汉理工 大学可以将本学位论文的全部或部分内容编入有关数据库 进行检索,可以采用影印、缩印或其他复制手段保存论文和 汇编本学位论文。 ( 保密论文在解密后应遵守此规定) 论文作者签名:孑艮敝导师签名 日期: 2 。p , “配置w e b 同 步向导”项,打开s q l c e 连接配置管理工具。 ( 2 ) 单击“下一步”按钮,进入“订阅服务器类型”对话框,这里选择s q ls e r v c r m ( 炮i l ee d i t i o n 。 武汉理工大学硕士学位论文 ( 3 ) 单击“下一步”按钮,进入设置w e ;b 服务器”页,这里输入运行l i s 的计算 机名( 即本计算机的网络名) ,选择“创建新的虚拟目录”单选按钮,选中“默认 网站”。 ( 4 ) 单击“下一步”按钮,进入“虚拟目录信息”页,这里将别名设置为t c s t ,路径 设置为“c :、t c s t ,这个默认路径包含了s q l c 骼a 3 0 d n 文件。 ( 5 ) 单击“下一步”按钮,进入设置“安全通信”页,选择默认项。 ( 6 ) 单击“下一步”按钮,进入设置“客户端身份验证”页,该示例中设置为匿名 方式。 ( 7 ) 单击“下一步”按钮,设置“匿名方位”变量,默认即可。 ( 8 ) 单击“下一步”按钮,设置“快照共享访问”,这里需要一个共享文件目录。 在c 盘中建立一个新目录t e s t ,并将其设置成共享,具备读写权限,共享名为t e s t 。 正因为如此在共享目录中输入迪墨三q 5 2 2 过煎 ( 9 ) 单击下一步按钮完成配置。 2 ) 安装s q l c e 3 o 在使用s q ls e r y 盯c e 3 o 之前,先介绍一下安装过程。这里包括两个部分的 安装,一个部分是服务器环境安装,用于实现服务器同客户端机器的s q l c e 数 据同步、订阅等工作;另外一个部分是客户端环境安装,即在嵌入式p c 机上或 者p d a 上安装s q l c e 3 0 环境。 3 ) s q l c e 3 o 服务器端安装 这里的服务器可以是普通p c ,也可以是服务器。操作系统能够是w i n d o w s , s p 2 、w i n d o w s2 0 0 0s e c r 、w i n d o w s2 0 0 3s e r v e r 等。如果s q l c e 3 o 应用程序要 求在m i c r o s o f ts q ls e r v e r 数据库和s q l c e 数据库之间交换数据,则需要在服务 器上安装如下软件: ( 1 ) i i s ( m i c r o s o ri n t 锄e t 信息服务) ( 2 ) s q ls e r v e r 2 0 0 5 或s q ls e r v e r2 0 0 0 ( 3 ) s q l c e 3 0 服务器工具 4 ) s q l c e 3 o 客户端安装 s q l c e 3 0 安装文件能够从微软官方网站上进行下载,也能够从v i s u ms t u d i o 2 0 0 5 安装之后的目录中获取。在安装v i s u a ls t u d i o2 0 0 5 时,默认目录下会包含 s q l c e 3 o 安装文件。 在默认目录下包含了9 个c a b 安装文件。这9 个安装文件对应3 组:一组是针 对s m a r q p h o n e 智能手机的;一组是针对p o c k e tp c 智能p d a 的;一组是针对w i n c e 5 武汉理工大学硕士学位论文 通用系统的 将s q l c e 3 0 p p c 、s q l 3 0 r 印l 和s q l c c 3 0 d e y 这3 个文件拷贝到p d a 中,并依次安 装 其中s q l c e 3 0 p p c 安装文件是s q l c e 3 0 核心安装文件;s q l c e 3 0 啊,l 安装文件 是服务于复制、订阅等相关服务;s q l c e 3 0 d e v 是安装一愕s q l c e 查询分析器,便 于管理和操作s q l c e 。这3 个文件安装完毕,s q l c e 3 o 客户端就算安装完毕了。 5 3 建立数据库 在服务器上建立一个曲c o w 数据库,在d b c o w 数据库中建立一个t a b l e c o w 表, 在s q ls e e r 2 0 0 0 中的查询分析器中添加如下代码: u s e m a s t c r ; g o e x i s t s ( s e l e c t f r o ms y s d 砒l b 硒岱w h e r en 锄舱= d b c o w ) b e g i n d r o pd a l a b 弱ed b c o w ; e n d g o c r e a t ed a t a b a s ed b c o w ; g o u s e d b c o w ; g o c r e a t ew 出l et a b l e c o w ( s o w i dn v 们h a r ( 8 ) p r i m a r yk e y ,t y p e n v a 以h a r ( 12 ) ,w e i g h tn o a t ) ; i n s e r ti n t ot a b l e c o w ( s o w i d ,t ) ,p e ,w e i 出) v a l u e s ( o 0 0 0 0 0 0 l ,a b d a f d s , 2 3 4 7 ) ; i n s e i 汀i n t ot a b l e c o w ( s o w i d ,t y p e ,w e i 曲t ) v a l u e s ( o o o o o 0 0 2 ,g 均c g g g , 1 1 0 3 ) ; i n s e r ti n t o t a b l e c o w ( s o w i d ,t y p e ,w e i g l l t ) v a l u e s ( 0 2 5 0 0 0 0 1 ,t os d y f , 2 2 2 7 ) ; g o 最后在p d a 上,通过i s q l w 3 0 工具建立一个数据文件d b g o w s d f o 武汉理r 。犬学硕l 学位论文 54 新建项目 1 1 使用v s 2 0 0 5 - v c 一 智能设备- m f c 智能设备应用程序向导创建一个 基于对话框的应用程序r d a g f d b ,编译环境设置为w l n d o w sm o b l l e 5 op o c k e t p cs d k f a r m v 4 n ,设备选择w i n d o w s m o b i l e5op o c k e t p c d e v i c e ,把窗口字体 改成宋体小托号。 2 、在i d dr d a g f d bd i a l o g 对话框r 放置二个按钮,如图5 2 所示,分 别用 实现s u b m i t 、p u l l 和p u s h 三大功能,将它们的标识依次设为 山cb t ns u b m i t 、1 d cb t np u l l 、i d cb t np u s h 按钮的名称分别为“执 行远程s o l 语句( s u b m i t ) ”、一f 载服务器数据( p u l l ) ”、“向服务器上 传数据( p u s h ) ”。 削5 2 r d a 示例界嘶 山1 。这。p 需要川到r d a 定义的接r f 类,j f 因为如此迹要在r d a g f d b d l gh 文件中0 c am e 。g e x 3 0h 丈什。 # i n c l u d e ( c l m c r g c 3 0h ) 55 初始化c o m 环境 s q l c e 近程数捌访m ,是通过s q l c e 提供的c o m 接l j 函数柬实现的棚应功 武汉理工大学硕士学位论文 能。正因为如此需要在c r d a g f d b d l g :嘣t d i a l o g 函数里初始化c o m 环境, 即在o n h l i 妇) i a l o g 函数中添加如下代码即可: 初始化c o m 环境 c o h l i t i a l i z e e x ( n u l l ,c o i t 胍j l t i t h r e a d e d ) ; 最后,还需要在对话框销毁事件中释放c o m 环境,即添加如下代码: 释放c o m 环境 c o u i l i l l i t a l i z e ( ) ; 5 6 实现显示执行i a 错误的方法 在执行远程数据访问的过程中,可能会因为各种各样的原因而发生错误, s q l c e 提供了i s s c e e r r 0 巧接口、i s s c e e r o r 接口、i s s c e p a r a m s 接口和 i s s c e p 姬吼接口以获取发生错误的详细信息。 能够使用i s s c e e r r 0 璐接口、i s s c e e n d r 接口、i s s c e p a 棚:i l s 接口和 i s s c e p 娥吼接口封装一个显示r d a 错误方法的s h o w e n o 璐,该方法将通过弹出 对话框的形式来提示错误信息。 为c r d a g f d b d l g 类添加私有方法s h o w e n | o 瑙,该方法的定义如下: p r i v a t e : 显示远程数据访问时的错误 v o i ds h o w e n d r s ( i s s c e e r r o r s 木p i s s c e e n d r s ) ; 下面给出实现s h o w e 仃0 r s 的程序代码: v o i dc r d a g f d b d l g :s h o w e r r o r s ( i s s c e e r r o r s 奉p i s s c e e f r o f s ) h r e s u i t l o n g l o n g l o n g l o n g l o n g l o n g v a r i a n t v a r i a n t w c h a r h r : c b b u i ; l e r r o 疋。岫t ; l e r f o r i l l d e x : l p a r 锄c o u i l t ; l p a r a m i i l d e x ; v a r ; v a r p a r a m : w s z b u 4 0 9 6 】; 3 2 武汉理工大学硕士学位论文 w c m 姐p w s z b u f | 咿;& w s z b u 趣o 】; b s t rb s 虻 i s s c e e n d r p i s s c e e 聊 = n u l l ; i s s c e p a r i u n s p i s s c e p 翻黝s= m l l ; i s s c e p 锄彻p i s s c e p 扣砸n= n u l l ; b o o lf s u c c e s s = f a l s e : 初始化变量 v 撕趾t h l i t ( & v 砷; v 稿姐t i i l i t ( v a r p a r 锄) ; 通过i i s s c e e n o 姆接口得到发生错误的数量 i 坟f a i l e d ( h r = p i s s c e e n d r s 一 g e l c o 吡n t ( & l e f l o r c o u n t ) ) ) 9 0 t 0 e x i t ; i f ( 1 e r r o 疋0 r u 呲 g e t - d e s 嘶p t i o n ( & b s 仃) ) ) 9 0 t 0e x i t ; c b b u f = s w p r i n t f ( p w s z b u f 伊o s ,l ”d e s c r i p t i o n :s 、讧,b s 呻; p w s z b u 仰o s + = c b b u 武汉理工大学硕士学位论文 s y s f 澈s t r i l 蜘s 哪; | | 姥误挂息编号 i fo a i l e d ( 1 l r = p i s s c e e n d r - 鳓n u m b e & i ) ) ) g o t 0e x i t ; c b b u f = s 、伸r i n t f d w s z b u 丘p o s ,l ”n u m b e r :8 8 x ”,i ) ; p w 妯u 卯o s + 篁c b b u f f 本地错误 i f ( f a i l e d ( h r = p i s s c e e r i o r - g 删a 吐v e 】巳1 州i ) ) ) g o t oe x i t ; c b b u f = s 、】i ,】硒n t f w s z b u 妇f p o s l n a t e - 上r r o r :曲u 什,i ) ; p w s z b u 仰o s + = c b b u 府到错误源 i f ( f a j l e d = p i s s c e e 玎o r - g 戗胁u r c e ( & b ) ) g o t 0e x i t ; c b b u f = s w 面i l t 妇w s z b u f | f p o s ,l s o u r c e :s f ”,b s 缸,; p w s z b u f i p o s 扣c b b u s y s f r e e s t r i n g ( b s 曲; 得到错误参数信息 i f ( f a i l e d ( h r = p i s s c e e n o r - g e l l = - p a r 锄s ( & p i s s c e p 铀急m s ) ) ) g o t o e x i t ; 得到错误参数的个数 i f ( f a i l e d ( h f = p i s s c e p a 眨吼s 一 g e i c o u n t ( l pa r a m c o u n t ) ” g o t 0 e x i t ; l | 显示每一个参数 蠡) r ( 1 p 娥l i i l i n d e x = 0 ;l p 缸锄h l d e x g e l n e i l l ( v a r ,& p i s s c e p a r 锄) ) ) g o t 0e x i t ; 得到并显示错误参数值 i f ( f a i l e d = p i s s c e p a r 锄一 g e t j a r 撇( & v 种蝴n ) ) ) g o t 0 e x i t ; i f ( v t 1 4 一v 种砌圳1 4 一v 种删m 呻 武汉理工大学硕士学位论文 c b b l l f = 咖坻p w s 国u f j 田0 8 l p d :乱蛔一,l p 嬲腿h l d e x , ( l o n g ) r p 锄瓶1 v a l ) ; e l s ei f ( v t1 2 一v 种a r 锄0 1 2 一v 种鼬m 咖 c b b u f = 唧r i n t 如w s z b u 艘o s ,l ”p d :d n 什,1 p a r a m i i l d e x , ( l o n g ) v a r p 孤锄i v a l ) ; ) e l s ei f ( - b s t r v 种a r a m 呻 c b b u f = s w p r m t 妇曲w s z b u f 护o s ,l ”p d :s ,l p 嬲吼i n d e x , v a r p a r a m b s 缸v a l ) ; ) p w s z b u 卯o s 忙c b b u 清空参数变量 v 撕a n t c l e 叫& v a r p a r a m ) ; 释放参数对象 p i s s c e p 躐啪一 r e l e a s e ( ) ; p i s s c e p m 锄= n u l l ; ) c b b u f = s w p d n t f b w s z b u f 即o s ,l ”姚l f ) ; p w s z b u 脚o s + - c b b u 霉 ) 用弹出框显示错误信息 :m e s s a g e b o x ( n u l l ,w s z b u 堰l f t e 册,m b _ p k ) ; f s u c 宅e s s = t r u e : e x i t : 释放错误参数对象 i f ( p i s s c e p a r 踟n ) p i s s c e p 觚吼- r e l e a s e ( ) ; p i s s c e p 锄锄= n u l l ; ) 3 5 武汉理工大学硕士学位论文 释放错误参数集对象 i fq i s s c e p a r 锄s ) p i s s c e p 觚锄s - r e l e 嬲e o ; p i s s c e p 锄墨m s = 卜m l l ; ) 释放错误对象 i f ( p i s s c e e 玎o f ) p i s s c e e 船d r l r e l e a s e ( ) ; p i s s c e e r l l 0 i r = n u l l ; , 如果获取错误信息失败 i f ( ! f s u c c 懿s ) :m e s s a g e b o x ( n u l l l t t 得到错误信息失败! ”,l ”显示错误,m b - - o k ) ; , r e t l l m : 5 7 实现s u b m i t 利用m f c 类向导,新建c d l g s u b i i l i t 对话框。该对话框供用户输入执行远程 s q l 语句的变量,窗口样式如图5 3 所示。 武汉理t 大学碗士学位论文 圆圈墨圆 吼n nr 匣垂垂垂亘垂画 月p g - 二二二二二 日一 二二二二二二 4 目十 巨三! , t m $ e 三三 婴 卫 墨i 图53 “执行远程s o l 语句”窗n 对话框上的主要控件搜其属性设置如下表5 2 所示 j ; j 于输入w l n d o w sc e 代理i i s 的u r l 地址对应 i d c - e d l 一i n t e r n e t u r l 成员变甘为t n _ i n t 耶e i u r l ,类型为c s m “& 设置 其默认值为b 婶:加8 3 0 5 2 2 b q l c c s q l c c s a 3 0d n 川丁输入w i n d o w s c e 代理i l s 鸯隶川户对应成 i d ce d t _ i n t e r n e t u s e r n a m e 员变培为。j n f e m e t u e ,类型为c s t n “g 川于输入w l n d o w 宴c e 代理s 赞录密码时麻成 】d c _ e d t _ 聃t e r n 盯队s s w o r d员变蚺为m m l e a 8 9 w o 坩,类型为c s n ”默认值 为n u l l 。 川丁输入连接服务器数据库的连接串,时j 姻茂员 变量为m i s e 类型c s 研n e 。选中其 m u l t l l i n e 属性,支持多行操作。设置其默认值为 i d c e d l o n n e c t s t r p r o 州e r = 8 q j o i e d b ,d a n s o u * d 8 3 0 5 2 2 ,i n m i c ac a l o g = g f d b ,l d j s a ; d a s s w o r d = 1 2 3 r 匹庄远 ¥服务器l 执 r 的s o l l 自j ,时砸成 i d t e d t _ q u e r y s t r员_ 蹙蛀为“u c r y s t r ,类删c s m “g 。选巾其 i n u l t l l m e 属性,支持多行操作。 按钮柠件标题设为“确定。在其单击旰什方法 i d cb t no k 里,橱川0 n o k 一洁艽训刊活框。 拄q 【控什,标题吐为j 坟洲。在其竹- lr 事制冉法 i d cb r nc a n c e l 咀矾川o n c a n c e l 盯 父川列i 扯 武汉理工大学硕士学位论文 变量i j l 也地址的值必须输入正确,默认值是h t t p :d 8 3 0 5 2 删s q l c 髂a 3 0 m l , 这里的d 8 3 0 5 2 2 是服务器名称 变量连接串表示访问服务器数据库的连接字符串,默认值是讧o v 涨:l 皇s q l o l e d b ; d a t a觥d 8 3 0 5 2 2 ;i n i t i a l c a t a l o g = 班l b ; l l s e r i d s a ;p 硒s w o r i 忙1 2 3 ”, 这里 d 8 3 0 5 2 2 指的是服务器网络名,大家应设置自己服务器的网络名,并将访问的用 户名、密码设置正确。 最后,切换到i d dr d a g f d bd 队l o g 对话框上,即在主窗口上添加“执行 远程s q l 语句( s u b i i l i t ) ”按钮的单击事件代码。在此单击方法里,先是通过打 开d dd l g s u b m r rd i i ,a o g 对话框来设置执行远程s q l 的相关属性,然后再 执行远程s q l 语句,下面给出实现此过程的程序代码: v o i dc l a g f d b d l g :q 1 b n c l i 幽e d b 恤s u b m i t o t o d o :在此添加控件通知处理程序代码 i s s c e r d a 奎p c e r d a = n u l l ; b s t r b s 仃= n u l l : b s l rb c o 衄e c t s 仃2nul l ; b s t rb q u 哪仃= n u l l ; s y s t e m t i m e s y s t e i i l t i m e ; d o u b l et i m e t o t a l : i 1 1 t 6 4 妇1 e s t a r t = o ; 缸6 4 缸l e s t o p ; w c h a rw s z b u 毹r 【5 1 2 】; c s u b m i t d l gd l g s u b m i t ; d l g s u b m i t d o m o d a l o ; 系统时间 总共消耗的时间 开始操作时的时间 结束操作时的时间 得至0 p c e r d a 接口 h r e s u i jh r = c o c r e a t e i n s t a i l c e ( c l s i dr e m o t e d a t a a c c e s s ,n u l l , c l s c t x j n p r o c s e r v e r ,d i ss c e r d a ,( l p v o i d 木) & p c e r d a ) ; a s s e r t ( 1 l r s _ o k ) ; a s s e r t ( p c e r d a ! = n u l l ) ; l 、设置i n t 锄e tu r l b s 仃= s y s a l l o c s t f i n g ( d l g s u b m i t n l j n t e n l e t u r l ) ; 3 8 武汉理工大学硕士学位论文 p c e r d a 印i l l ;m 嘧鹏t u l 江o s ; s y s f r o e s 幽g ( b s 呻; 2 、设j i n t 咖e t 懈a n 锄c b s 仃= s ”灿l o c s t r i n g ( d l g s u b l m t n o n t 锄列s 锄锄c ) ; p c e l a - p u t e t l 0 9 i n ( b s 锄; s y s f r s t r i n g ( b s 仃) ; 3 、设置h l t 锄e tp 嬲s w o m b s 廿= s y 蹦l o c s 仃岖( d l g s l i 喊t ,m - j n t 黜e t p a s s w o r d ) ; p c e r d a p t n :h n 锄e t p 锻w o r d ( b s 的; s y s f r e e s 山g ( b s 田; 4 、设置服务器连接串 b c o 锄e c t s 缸= s y s a l l o c s t r i n 烈d l g s u b m i t mc 0 i l i l e c t s 仃) ; 5 、设置执行的远程s q l 语句 b q i l e r y s 扛= s y s a l l o c s t r i n 颤m g s u b i n i t i n :q u e 蜩仃) ; 记录执行s q l 语句前的时间 g e t l o c a l t i m e ( & s y s t 锄t i m e ) ; s 蹦伽t i i n e t o f i l e t i l i l e ( & s y s t 锄t i m e ,( f i l e t i m e 事) t i m e s t a n ) ; 执行远程s q l 语句 l l r = p c e r d a - s u b m i t s q l ( b q l l e 啪仃,b c o m e c t s 仃) ; s y s f r e e s t r i n g ( b q u e r y s 仃) ; s y s f d s t d n g ( b c o 衄e c t s ; i f ( s u c c e e d e d ( h r ) ) 记录执行s q l 语句后的时间 g e t l o c a l t i m e ( s y s t e m t i m e ) ; s y s t e 玎r i m e t o f i l e t i m e ( s y s t 锄t i m e ,( f i l e t l m e 牛) t i m e s t o p ) ; 记录执行s q l 语句总共消耗的时间 缸m e l r o t a l l = ( ( d o u b l e ) ( t i m e s t o p 一石m e s t a n ) 10 0 0 0 0 0 0 ) ; s 、p 血l t 冰i r s z b u f 衔,t ( ”执行远程s q l 语句成功总共消耗= 8 3 f 秒”) ,t i m e t o t a l ) ; a f x m e s s a g e b o x ( w s z b u f 五神; 3 9 武汉理工大学硬士学位论文 e b e 显示执行远程s q l 语句错误 i s s c l 强r 棚 + p i s s c e e r = n u u 一; i 郧u c c e 即e d 恤;卿胁薛e r r o f r 僦i d s ( 却i s s c e e 删) s h o w e f r o f s 衄s s c ; p i s s c l 强m _ r d c o ; ) ) 脾i 放远程访问接口 p c e r d a - ) r d e e o ; ) j 由于这里引用了c s u b l i 唧g 类,正因为如此要在r n a g f d b d l g c p p 文件中引 用s 删t d 培h 。 执行效果如图5 _ 4 。当然在执行远程s o l 时,要确保服务器u i t l 地址、服务器 数据库连接串正确,还要确保执行的s o l 语句的合法性。 二垂二 量! 笪堑鎏萄一 图5 4 执行s l n m i t 效果图 5 8 实现从服务器下载数据( p u l l ) 武汉理工大学硬士学位论文 利用c 类向导,新建c p l l l 肼g 对话框。此窗口主要供用户输入执行p u l l 时 的变量,窗口样式如图5 5 。 图5 - 5 “从服务器下载数据”界面 窗体上的主要控件及其属性如表5 3 所示。 表5 3 从服务器下载数据界面控件及属性设簧 描述 j 1 】于输入w i d d o w s c e 代理s 的u r l 地蚰,对应成员 i d c e d t _ i n r n e l u r l变量为n u n 【盯n d u r l ,类型为c s 晡n 设置其默认值 为h i t p :m 8 3 0 5 2 2 佃k “q l c c s a 3 0d l l 用于输入w h d 0 肌c e 代理s 登录用户名,对应成员 i d c d t _ i n t e r n 刚s e r n a m e 变晕为mm 蛐d 【u s e r r i a m e ,类型为c s 吣 用于输入w i n d q w sc e 理l i s 登录密码对应成员变 i d c 。e d t 珊t e 孙舶a s s w o r d 量为mi m e m 6 口拈g w 毗类型为c s h i 哩 组台框,用于设置获取数据时的跟踪类型对应成员 变量为m c k m 自类型为c s 耐“g 同时将此缩台框设 置成d r o p l i s t ,井且将下拉框的内容设为: t r a c k 【n 0 0 【d c c m b - t r a c j ( i n g t r a c i n g o f f t r a c 刚0 0 n 州d e x e s 1 r a c l ( 1 n g o f fi n d e 垭s 最后去掉排序( s o n ) 属性 用于输入连接服务器数据库的连接串,对应成

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论