欢迎光临
我们一直在努力

如何自动发布MS SQL SERVER数据库?-数据库专栏,SQL Server

建站超值云服务器,限时71元/月

 

程序编写: 陈林茂

‘编写日期:2003-01-01

当您的mis系统开发好以后,您如何尽快的分发您的数据库呢?

下面我将提供vb代码的具体实现:

option explicit

define the sql connect
dim osqlserver as sqldmo.sqlserver
dim ocurrentdb as sqldmo.database
dim ocurrenttable as sqldmo.table
dim otestidx as sqldmo.index

sqldmo is connected yes or no
public sname as string
private isconnected as boolean

connect to local database server
public function connectdmo() as boolean
   on error goto handleerror
   if were connected, then disconnect and clear lists.
   if isconnected = true then
        osqlserver.disconnect
        isconnected = false
   end if
   begin connect to sqlserver or msde
   attempt a connection, then fill the properties stuff.
    osqlserver.applicationname = “sql-dmo index test”
    osqlserver.loginsecure = true
   
    connect
    osqlserver.connect “(local)”, “sa”, “”
   
    isconnected = true
    connectdmo = true
  
handleerror:
    connect failth
    if isconnected = false then
      isconnected = false
      connectdmo = false
    end if
   
end function

add a exists database to server
public function adddatabase(byval dbname as string, byval dbpath as string, byval rstr as string) as boolean
   dim rstring
   rstring = osqlserver.attachdbwithsinglefile(dbname, dbpath)
   rstring = osqlserver.attachdb(dbname, dbpath)
   adddatabase = true
  
  
   rstr = rstring
end function

delete the exists database
public function deldatabase(byval dbname as string) as boolean
  dim rstring
  rstring = osqlserver.detachdb(dbname)
  deldatabase = true
end function

private sub usercontrol_initialize()
  on error goto merror
    set osqlserver = new sqldmo.sqlserver
    osqlserver.logintimeout = 15
    osqlserver.odbcprefix = false
    name = “msdeconn1”
merror:
end sub

public function isdbexists(byval dbname as string) as boolean
  dim odb as sqldmo.database
  dim rc as boolean
  reconnect to database
  osqlserver.disconnect
  osqlserver.reconnect
 
  rc = false
  for each odb in osqlserver.databases
    if odb.systemobject = false then
        if trim(ucase(odb.name)) = trim(ucase(dbname)) then
          rc = true
        end if
    end if
  next odb
 
  set the return value
  isdbexists = rc
 
end function

private sub usercontrol_terminate()
  end connect the database
  osqlserver.close
end sub

public function startserver()
  osqlserver.start true
end function

public sub stopserver()
  osqlserver.stop
end sub

 

public property get name() as variant
  name = sname
end property

public property let name(byval vnewvalue as variant)
  sname = vnewvalue

end property

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何自动发布MS SQL SERVER数据库?-数据库专栏,SQL Server
分享到: 更多 (0)

相关推荐

  • 暂无文章