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 / blogin.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-04-03  |  4.5 KB  |  140 lines

  1. VERSION 2.00
  2. Begin Form login 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "SQL Server Login"
  5.    Height          =   2685
  6.    Icon            =   0
  7.    Left            =   1035
  8.    LinkMode        =   1  'Source
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    MinButton       =   0   'False
  12.    ScaleHeight     =   2280
  13.    ScaleWidth      =   6690
  14.    Top             =   1020
  15.    Width           =   6810
  16.    Begin TextBox password_field 
  17.       Height          =   375
  18.       Left            =   1320
  19.       TabIndex        =   5
  20.       Text            =   "Text1"
  21.       Top             =   1440
  22.       Width           =   3495
  23.    End
  24.    Begin CommandButton CANCEL_BUTTON 
  25.       Cancel          =   -1  'True
  26.       Caption         =   "Cancel"
  27.       Height          =   495
  28.       Left            =   5160
  29.       TabIndex        =   7
  30.       Top             =   840
  31.       Width           =   1335
  32.    End
  33.    Begin TextBox login_id_field 
  34.       Height          =   375
  35.       Left            =   1320
  36.       TabIndex        =   3
  37.       Text            =   "Text1"
  38.       Top             =   840
  39.       Width           =   3495
  40.    End
  41.    Begin CommandButton OK_BUTTON 
  42.       Caption         =   "OK"
  43.       Default         =   -1  'True
  44.       Height          =   495
  45.       Left            =   5160
  46.       TabIndex        =   6
  47.       Top             =   240
  48.       Width           =   1335
  49.    End
  50.    Begin TextBox Server_name_field 
  51.       Height          =   375
  52.       Left            =   1320
  53.       TabIndex        =   1
  54.       Text            =   "Text1"
  55.       Top             =   240
  56.       Width           =   3495
  57.    End
  58.    Begin Label Label3 
  59.       Caption         =   "&Password:"
  60.       Height          =   255
  61.       Left            =   120
  62.       TabIndex        =   4
  63.       Top             =   1440
  64.       Width           =   975
  65.    End
  66.    Begin Label Label2 
  67.       Caption         =   "&Login ID:"
  68.       Height          =   255
  69.       Left            =   120
  70.       TabIndex        =   2
  71.       Top             =   840
  72.       Width           =   975
  73.    End
  74.    Begin Label Label1 
  75.       Caption         =   "&Server:"
  76.       Height          =   255
  77.       Left            =   120
  78.       TabIndex        =   0
  79.       Top             =   240
  80.       Width           =   975
  81.    End
  82. '$INCLUDE: 'VBQUERY.BI'
  83. '$INCLUDE: 'VBDSQL.BI'
  84. Sub CANCEL_BUTTON_Click ()
  85.     ExitApplication
  86. End Sub
  87. Sub Form_Load ()
  88.     Server_name_field.Text = DefServer$
  89.     Login_id_field.Text = DefLogin$
  90.     PASSWORD_FIELD.Text = ""
  91.     password$ = ""
  92. End Sub
  93. Sub OK_BUTTON_Click ()
  94. Rem Get the server name, login Id, & password from the form
  95.    Servername$ = Server_name_field.Text
  96.    LoginID$ = Login_id_field.Text
  97. Rem Note-- allow null servername becuase you might be running on the same
  98. Rem machine as SQL Server.  Allow null userid because server might be running
  99. Rem integrated security.
  100. Rem Open select connection for browse mode:
  101.     If LoginToServer() = FAIL Then
  102.         PASSWORD_FIELD.Text = ""
  103.         password$ = ""
  104.         Exit Sub
  105.     End If
  106. Rem Now Open update connection for browse mode:
  107. Rem Check to see if the connection is live, if so, then close it
  108. Rem Set the max time to login to 30 seconds
  109. Rem Open the new connection
  110. Rem Change the caption of the application to reflect the server name and the database
  111. Rem Set the max time we will wait for a SQL Server response
  112.     If SqlUpdConn <> 0 Then SqlClose (SqlUpdConn)
  113.     Status% = SqlSetLoginTime%(LoginTimeout)
  114.     SqlUpdConn = SqlOpenConnection(Servername$, LoginID$, password$, ProgramName$, ProgramName$)
  115.     If SqlUpdConn <> 0 Then
  116.         DatabaseName$ = SqlName(SqlUpdConn)
  117.         ChangePrimaryWindowCaption
  118.         Result5 = SqlSetTime%(QueryTimeout)
  119.     Else
  120.         DatabaseName$ = ""
  121.         Servername$ = ""
  122.     End If
  123.     Unload Login
  124. End Sub
  125. Sub password_field_KeyPress (keyascii As Integer)
  126. Rem This will keep the key from being seen
  127. '   if key pressed is a letter or a number, add it to password and show *
  128. If (keyascii >= 48 And keyascii <= 57) Or (keyascii >= 65 And keyascii <= 90) Or (keyascii >= 97 And keyascii <= 122) Then
  129.         password$ = password$ + Chr$(keyascii)
  130.         keyascii = Asc("*")
  131. ElseIf (keyascii = 8) Then   'if backspace
  132.         If Len(password$) > 0 Then
  133.         password$ = Left$(password$, Len(password$) - 1)
  134.         End If
  135. Else                        'if anything else, throw out
  136.         keyascii = 0
  137.         Beep
  138. End If
  139. End Sub
  140.