'Programming: Chen Linmao
'Writing date: 2003-01-01
How do you distribute your database as soon as your MIS system is developed?
Below I will provide the specific implementation of VB code:
Option expedition
'Define the SQL Connectdim OsqlServer As SqldMo.sql ServerDim Ocurrentdb As SqldMo.databaseDim OcurrentTable As SqldMo.tabledim Otestidx As SqldMo.index
'sqldmo is connected Yes or Nopublic Sname as stringprivate isconnected as boolean
'Connect to local database serverPublic 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 kiln componNECted = false connectdmo = false endiff
'Add a exists database to serverPublic 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 = rstringend function
'delete the exists databasepublic function Deldatabase (byval dbname as string) as boolean dim r = osqlserver.detachdb (dbname) Deldatabase = trueEnd Function
Private Sub UserControl_Initialize () On Error GoTo merror Set oSQLServer = New SQLDMO.SQLServer oSQLServer.LoginTimeout = 15 oSQLServer.ODBCPrefix = False Name = "msdeconn1" merror: End SubPublic 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.closend Sub
Public function startserver () OSQLServer.Start TrueEnd Function
Public sub stopserver () osqlserver.stopend Sub
Public property get name () as variant name = snameend property
Public property let name (byval vnewvalue as variant) sname = vnewvalue
End Property