首页 > 数据库 > SQL Server > 正文

如何自动发布MS SQL SERVER数据库?

2024-08-31 00:48:54
字体:
来源:转载
供稿:网友


 

'程序编写: 陈林茂

‘编写日期: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 we're 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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表