Results 1 to 13 of 13
  1. #1
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70

    Question Unanswered: VB6 - How I cant get determine server name?

    In vb6:

    Public ServerName As String
    Public DataBaseName As String
    Public UserName As String
    Public Pass As String

    I use a Login form where user input the SeverName, DataBaseName, UserName and Pass.

    How I can determine if the Server and DataBase exist ?

  2. #2
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    For the database you can do select from master.dbo.sysdatabases

    For the server part : i ll have to search around and get back
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  3. #3
    Join Date
    Nov 2003
    Location
    Edinburgh
    Posts
    149
    select * from master.dbo.sysservers

  4. #4
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Originally posted by aldo_2003
    select * from master.dbo.sysservers
    Aldo ... He is creating a login screen ... so i presume you cannot take the server information from sysservers. Moreover, that would not provide a list of all the servers

    My Own Opinion ... will have for the owner of thread to get back
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  5. #5
    Join Date
    Nov 2003
    Location
    Edinburgh
    Posts
    149
    For a login screen....

    I presume for a server drop down or combo box.

    Because the server list should be fairly static I would create a custom lookup table and then reference that.

    Cheers

  6. #6
    Join Date
    Nov 2003
    Location
    Edinburgh
    Posts
    149
    If you want to check if the server is valid then you could cmd shell a ping command to the server - provided that your Network is working OK then you should be able see the server.

  7. #7
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Originally posted by aldo_2003
    For a login screen....

    I presume for a server drop down or combo box.

    Because the server list should be fairly static I would create a custom lookup table and then reference that.

    Cheers
    Custom Lookup Table ... where ???
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  8. #8
    Join Date
    Nov 2003
    Location
    Edinburgh
    Posts
    149
    Wherever you want - On any of your Servers running SQL , create an access db and reference that , txt file (ini file for your programme), hard code the server names into the combo box , excell spreadsheet

    Up to you mate ....

  9. #9
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    I think if I was the programmer , I would like to have the current active servers in my dropdown box ... just like SQL Query Analyzer login box.
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  10. #10
    Join Date
    Nov 2003
    Location
    Edinburgh
    Posts
    149
    From books online:

    sysservers

    Contains one row for each server that Microsoft® SQL Server™ can access as an OLE DB data source.

    --But if you want to get fancy then you can go and manipulate Windows API to get lists of Servers on your network

  11. #11
    Join Date
    Nov 2003
    Posts
    76
    If you are looking for source to retrive SQL server name then you could use this..

    'Cut and paste

    Attribute VB_Name = "getserver"
    Option Explicit

    Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long

    Private Declare Function NetServerEnum Lib "netapi32" ( _
    strServername As Any, _
    ByVal level As Long, _
    bufptr As Long, _
    ByVal prefmaxlen As Long, _
    entriesread As Long, _
    totalentries As Long, _
    ByVal servertype As Long, _
    strDomain As Any, _
    resumehandle As Long) As Long

    Private Declare Function NetApiBufferFree Lib "Netapi32.dll" (ByVal lpBuffer As Long) As Long

    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

    Private Const SV_TYPE_SERVER As Long = &H2
    Private Const SV_TYPE_SQLSERVER As Long = &H4

    Private Type SV_100
    platform As Long
    name As Long
    End Type

    Public Sub GetSQLServers()
    Dim l As Long
    Dim entriesread As Long
    Dim totalentries As Long
    Dim hREsume As Long
    Dim bufptr As Long
    Dim level As Long
    Dim prefmaxlen As Long
    Dim lType As Long
    Dim domain() As Byte
    Dim i As Long
    Dim sv100 As SV_100

    level = 100
    prefmaxlen = -1

    lType = SV_TYPE_SQLSERVER
    domain = "DOMAINNAME" & vbNullChar
    l = NetServerEnum(ByVal 0&, _
    level, _
    bufptr, _
    prefmaxlen, _
    entriesread, _
    totalentries, _
    lType, _
    domain(0), _
    hREsume)

    If l = 0 Or l = 234& Then
    For i = 0 To entriesread - 1
    CopyMemory sv100, ByVal bufptr, Len(sv100)
    Debug.Print Pointer2stringw(sv100.name)
    bufptr = bufptr + Len(sv100)
    Next i
    End If
    NetApiBufferFree bufptr
    End Sub

    Private Function Pointer2stringw(ByVal l As Long) As String
    Dim buffer() As Byte
    Dim nLen As Long
    nLen = lstrlenW(l) * 2
    If nLen Then
    ReDim buffer(0 To (nLen - 1)) As Byte
    CopyMemory buffer(0), ByVal l, nLen
    Pointer2stringw = buffer
    End If
    End Function


    Private function GetDomain()
    'You could create a function to pull your domainname
    Set objNet = CreateObject("WScript.NetWork")

    DOMAINNAME= objNet.UserDomain
    Set objNet = Nothing
    end function

  12. #12
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Sysservers table has a list of only those servers that have been registered as linked servers or remote servers.

    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

  13. #13
    Join Date
    Nov 2003
    Location
    Romania
    Posts
    70
    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •