我的工程是用MSSQL做后台数据库,,装后要创建数据库,,
请问怎样判断机子上是否装有,若没有则提示后退出???请高手赐教~~~~~~~

解决方案 »

  1.   

    看这篇文章对你有用没,
    如何列举出网络上所有的SQL Server服务器
    http://www.zahui.com/html/14/33315.htm
      

  2.   

    http://www.yesky.com/129/1895629.shtml
      

  3.   

    Private Sub Command1_Click()
    Dim cnn As New ADODB.Connection
    cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs"
    cnn.Open
    If cnn.State <> 1 Then
    MsgBox "没有安装SQL Server!"
    Unload Me
    End IfEnd Sub
      

  4.   

    Private Sub Command1_Click()
    On Error Resume Next
    Dim cnn As New ADODB.Connection
    cnn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=pubs"
    cnn.OpenIf cnn.State <> 1 Then
      MsgBox "没有安装SQL Server!"
      Unload Me
    End IfEnd Sub
      

  5.   

    Option Explicit
    '测试一下代码
    Private Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long
    Private Declare Function GetLastError Lib "kernel32" () As Long
    Private Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
    Private Const ServiceName = "MSSQLSERVER"'安装了MSSQL肯定会在系统中注册这个服务
    Private Const SERVICES_ACTIVE_DATABASE = "ServicesActive"
    Private Const GENERIC_READ = &H80000000
    Private Const ERROR_SERVICE_DOES_NOT_EXIST = 1060&
    Private Sub Command1_Click()
        Dim getManager As Long
        getManager = OpenSCManager("", "ServicesActive", GENERIC_READ)
        If OpenService(getManager, "MSSQLSERVER", GENERIC_READ) Then
            MsgBox "有MSSQLSERVER服务,安装了MSSQLSERVER"
        Else
            If GetLastError = ERROR_SERVICE_DOES_NOT_EXIST Then
                MsgBox "指定的服务不存在, 没有安装MSSQLSERVER"
            End If
        End If
    End Sub
      

  6.   

    用winsock 连1433 看能连上不
      

  7.   

    获得系统的环境变量呢 . 里面也存储 SQL的信息
      

  8.   

    Private Declare Function NetServerEnum Lib "netapi32" _
    (lpServer As Any, ByVal lLevel As Long, vBuffer As Any, _
    lPreferedMaxLen As Long, lEntriesRead As Long, lTotalEntries As Long, _
    ByVal lServerType As Long, ByVal sDomain$, vResume As Any) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination _
    As Any, Source As Any, ByVal Length As Long)
    Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As LongPrivate Type SV_100
      platform As Long
      name As Long
    End Type
    Private Sub Form_Load()
    Combo1.ClearDim sv100 As SV_100, nRet As Long, i As Long, lServerInfo As Long
    Dim lPreferedMaxLen As Long, lEntriesRead As Long
    Dim lTotalEntries As Long, sDomain As String, vResume As Variant
    Dim buffer() As Byte, nLen As Long
    lPreferedMaxLen = 65536
    nRet = NetServerEnum(0, 101, lServerInfo, lPreferedMaxLen, lEntriesRead, lTotalEntries, 4, sDomain, vResume)
    If nRet = 0 Or nRet = 234& Then
      For i = 0 To lEntriesRead - 1
        CopyMemory sv100, ByVal lServerInfo, Len(sv100)
        nLen = lstrlenW(sv100.name) * 2
        If nLen Then
          ReDim buffer(0 To (nLen - 1)) As Byte
          CopyMemory buffer(0), ByVal sv100.name, nLen
        End If
        Combo1.List(i) = buffer '服务器名
        lServerInfo = lServerInfo + 24
      Next i
    End If
    end sub
    这段代码我在用的,VB6 - sql2000