How do I automatically publish an MS SQL Server database?

Source: Internet
Author: User
Tags goto trim
server| Data | database


' Program writing: Chen Linmao

' Date of preparation: 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 Explicit


' Define the SQL connect
Dim oSQLServer as SQLDMO. Sql server
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 SQL Server 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. Sql server
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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.