home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / dbmsg / sql / vbsql / rpclogin.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-04-03  |  5.5 KB  |  183 lines

  1. VERSION 2.00
  2. Begin Form login 
  3.    BackColor       =   &H00FFFFFF&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "SQL Server Login"
  6.    ForeColor       =   &H00000000&
  7.    Height          =   2640
  8.    Left            =   975
  9.    MaxButton       =   0   'False
  10.    MinButton       =   0   'False
  11.    ScaleHeight     =   2235
  12.    ScaleWidth      =   6720
  13.    Top             =   2055
  14.    Width           =   6840
  15.    Begin CommandButton LIST_BUTTON 
  16.       Caption         =   "List Servers..."
  17.       Height          =   495
  18.       Left            =   5160
  19.       TabIndex        =   8
  20.       Top             =   840
  21.       Width           =   1335
  22.    End
  23.    Begin TextBox password_field 
  24.       BackColor       =   &H00FFFFFF&
  25.       ForeColor       =   &H00000000&
  26.       Height          =   375
  27.       Left            =   1320
  28.       PasswordChar    =   "*"
  29.       TabIndex        =   5
  30.       Text            =   "Text1"
  31.       Top             =   1440
  32.       Width           =   3480
  33.    End
  34.    Begin CommandButton CANCEL_BUTTON 
  35.       BackColor       =   &H00C0C0C0&
  36.       Cancel          =   -1  'True
  37.       Caption         =   "Cancel"
  38.       Height          =   480
  39.       Left            =   5160
  40.       TabIndex        =   7
  41.       Top             =   1440
  42.       Width           =   1320
  43.    End
  44.    Begin TextBox login_id_field 
  45.       BackColor       =   &H00FFFFFF&
  46.       ForeColor       =   &H00000000&
  47.       Height          =   375
  48.       Left            =   1320
  49.       TabIndex        =   3
  50.       Text            =   "Text1"
  51.       Top             =   840
  52.       Width           =   3480
  53.    End
  54.    Begin CommandButton OK_BUTTON 
  55.       BackColor       =   &H00C0C0C0&
  56.       Caption         =   "OK"
  57.       Default         =   -1  'True
  58.       Height          =   480
  59.       Left            =   5160
  60.       TabIndex        =   6
  61.       Top             =   240
  62.       Width           =   1320
  63.    End
  64.    Begin TextBox Server_name_field 
  65.       BackColor       =   &H00FFFFFF&
  66.       ForeColor       =   &H00000000&
  67.       Height          =   375
  68.       Left            =   1320
  69.       TabIndex        =   1
  70.       Text            =   "Text1"
  71.       Top             =   240
  72.       Width           =   3480
  73.    End
  74.    Begin Label Label3 
  75.       BackColor       =   &H00FFFFFF&
  76.       Caption         =   "&Password:"
  77.       ForeColor       =   &H00000000&
  78.       Height          =   240
  79.       Left            =   120
  80.       TabIndex        =   4
  81.       Top             =   1560
  82.       Width           =   960
  83.    End
  84.    Begin Label Label2 
  85.       BackColor       =   &H00FFFFFF&
  86.       Caption         =   "&Login ID:"
  87.       ForeColor       =   &H00000000&
  88.       Height          =   240
  89.       Left            =   120
  90.       TabIndex        =   2
  91.       Top             =   960
  92.       Width           =   960
  93.    End
  94.    Begin Label Label1 
  95.       BackColor       =   &H00FFFFFF&
  96.       Caption         =   "&Server:"
  97.       ForeColor       =   &H00000000&
  98.       Height          =   240
  99.       Left            =   120
  100.       TabIndex        =   0
  101.       Top             =   360
  102.       Width           =   960
  103.    End
  104. '$INCLUDE: 'VBQUERY.BI'
  105. '$INCLUDE: 'VBDSQL.BI'
  106. Sub CANCEL_BUTTON_Click ()
  107.  Unload Login
  108. End Sub
  109. Sub Form_Load ()
  110.     Server_name_field.Text = DefServer$
  111.     Login_id_field.Text = DefLogin$
  112.     Password_field.Text = ""
  113. End Sub
  114. Sub LIST_BUTTON_Click ()
  115. NL$ = Chr$(13) + Chr$(10)
  116. nullchar$ = Chr$(0)
  117. '  First look for locally defined servers in Win.ini
  118. serverlist$ = Space(1000)
  119. retcode% = SqlServerEnum(LOCSEARCH%, serverlist$, numservers%)
  120. If retcode% <> ENUMSUCCESS% Then
  121.     msg$ = "SQLServerEnum for LOCSEARCH failed, return code " + Str$(retcode%) + NL$
  122.     'parse out the names
  123.     msg$ = "Locally defined servers: " + NL$
  124.     work$ = serverlist$
  125.     scount = 0
  126.     While Len(work$) > 0
  127.     nullcharpos% = InStr(work$, nullchar$)
  128.     If nullcharpos% <> 0 Then
  129.           srvname$ = Left$(work$, nullcharpos% - 1)
  130.         If Len(srvname$) <> 0 Then
  131.         scount = scount + 1
  132.         msg$ = msg$ + "Server" + Str$(scount) + ": '" + srvname$ + "'" + NL$
  133.         work$ = Right$(work$, Len(work$) - nullcharpos%)
  134.         Else
  135.         work$ = ""
  136.         End If
  137.     End If
  138.     Wend
  139.     msg$ = msg$ + NL$
  140. End If
  141. 'Now look for servers announced on the network
  142. serverlist$ = Space(1000)
  143. retcode% = SqlServerEnum(NETSEARCH%, serverlist$, numservers%)
  144. If retcode% <> ENUMSUCCESS% Then
  145.     msg$ = msg$ + "SQLServerEnum for NETSEARCH failed, return code " + Str$(retcode%) + NL$
  146.     'parse out the names
  147.     msg$ = msg$ + "Network defined servers: " + NL$
  148.     work$ = serverlist$
  149.     scount = 0
  150.     While Len(work$) > 0
  151.     nullcharpos% = InStr(work$, nullchar$)
  152.     If nullcharpos% <> 0 Then
  153.           srvname$ = Left$(work$, nullcharpos% - 1)
  154.         If Len(srvname$) <> 0 Then
  155.         scount = scount + 1
  156.         msg$ = msg$ + "Server" + Str$(scount) + ": '" + srvname$ + "'" + NL$
  157.         work$ = Right$(work$, Len(work$) - nullcharpos%)
  158.         Else
  159.         work$ = ""
  160.         End If
  161.     End If
  162.     Wend
  163.     msg$ = msg$ + NL$
  164. End If
  165. MsgBox msg$, 0, "Search for Servers"
  166. End Sub
  167. Sub OK_BUTTON_Click ()
  168. Rem Get the server name, login Id, & password from the form
  169.    Servername$ = Server_name_field.Text
  170.    LoginID$ = Login_id_field.Text
  171.    Password$ = Password_field.Text
  172.     If Servername$ = "" Then
  173.         MsgBox "Must supply a server name"
  174.         Exit Sub
  175.     End If
  176.     If LoginID$ = "" Then
  177.         MsgBox "Must supply a login id"
  178.         Exit Sub
  179.     End If
  180. Rem Connect to the server
  181.     If LoginToServer() = SUCCEED Then Unload Login
  182. End Sub
  183.