home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Unleashed / Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso / sfi / vbxctdem / logon.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-12-23  |  6.7 KB  |  206 lines

  1. VERSION 2.00
  2. Begin Form logon 
  3.    BackColor       =   &H00C0FFC0&
  4.    Caption         =   "Logon For SQL Server System 10"
  5.    ClientHeight    =   1665
  6.    ClientLeft      =   1665
  7.    ClientTop       =   3285
  8.    ClientWidth     =   5580
  9.    ControlBox      =   0   'False
  10.    Height          =   2070
  11.    Left            =   1605
  12.    LinkTopic       =   "Form2"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   1665
  16.    ScaleWidth      =   5580
  17.    Top             =   2940
  18.    Width           =   5700
  19.    Begin CommandButton cancelbut 
  20.       Cancel          =   -1  'True
  21.       Caption         =   "Cancel"
  22.       Height          =   615
  23.       Left            =   3600
  24.       TabIndex        =   9
  25.       Top             =   840
  26.       Width           =   1695
  27.    End
  28.    Begin CommandButton logonbut 
  29.       Caption         =   "Logon to Server"
  30.       Default         =   -1  'True
  31.       Height          =   615
  32.       Left            =   3600
  33.       TabIndex        =   8
  34.       Top             =   120
  35.       Width           =   1695
  36.    End
  37.    Begin TextBox dbase 
  38.       Height          =   285
  39.       Left            =   1440
  40.       TabIndex        =   7
  41.       Text            =   "pubs2"
  42.       Top             =   1200
  43.       Width           =   1935
  44.    End
  45.    Begin TextBox serverid 
  46.       Height          =   285
  47.       Left            =   1440
  48.       TabIndex        =   6
  49.       Text            =   "10NT"
  50.       Top             =   840
  51.       Width           =   1935
  52.    End
  53.    Begin TextBox password 
  54.       Height          =   285
  55.       Left            =   1440
  56.       TabIndex        =   5
  57.       Top             =   480
  58.       Width           =   1935
  59.    End
  60.    Begin TextBox uid 
  61.       Height          =   285
  62.       Left            =   1440
  63.       TabIndex        =   4
  64.       Text            =   "sa"
  65.       Top             =   120
  66.       Width           =   1935
  67.    End
  68.    Begin Label Label4 
  69.       Alignment       =   1  'Right Justify
  70.       Caption         =   "DataBase :"
  71.       Height          =   195
  72.       Left            =   200
  73.       TabIndex        =   3
  74.       Top             =   1200
  75.       Width           =   1000
  76.    End
  77.    Begin Label Label3 
  78.       Alignment       =   1  'Right Justify
  79.       Caption         =   "Server Id :"
  80.       Height          =   195
  81.       Left            =   200
  82.       TabIndex        =   2
  83.       Top             =   840
  84.       Width           =   1000
  85.    End
  86.    Begin Label Label2 
  87.       Alignment       =   1  'Right Justify
  88.       Caption         =   "PassWord :"
  89.       Height          =   195
  90.       Left            =   200
  91.       TabIndex        =   1
  92.       Top             =   480
  93.       Width           =   1000
  94.    End
  95.    Begin Label Label1 
  96.       Alignment       =   1  'Right Justify
  97.       Caption         =   "User Id :"
  98.       Height          =   195
  99.       Left            =   200
  100.       TabIndex        =   0
  101.       Top             =   120
  102.       Width           =   1000
  103.    End
  104. Sub cancelbut_Click ()
  105. '   User does not wish to connect
  106.     Unload Me
  107. End Sub
  108. Sub change_database (cp As Long, db As String)
  109.     Dim restype As Long
  110.     Dim ncols As Long
  111.     Dim rinfo As Long
  112. '   Set up the command buffer for processing
  113.         ret = VBCT_command_str(cmd_pointer, CS_LANG_CMD, "use " & db, CS_UNUSED)
  114.         
  115. '   Send the command(s) to the server for processing
  116.         ret = VBCT_send(cmd_pointer)
  117.         
  118. '   Process the result sets comming back from the server
  119.         result_ret = VBCT_results(cmd_pointer, restype)
  120.         res$ = ""
  121.         While result_ret = CS_SUCCEED
  122.         
  123.             Select Case restype
  124.             
  125.             Case CS_CMD_DONE, CS_CMD_SUCCEED, CS_CMD_FAIL
  126.                 Select Case restype
  127.                 Case CS_CMD_DONE
  128.                     rt$ = "CS_CMD_DONE"
  129.                 Case CS_CMD_SUCCEED
  130.                     rt$ = "CS_CMD_SUCCEED"
  131.                 Case CS_CMD_FAIL
  132.                     rt$ = "CS_CMD_FAIL"
  133.                 End Select
  134. '                MsgBox "Command status " & rt$ & " recieved"
  135.             Case Else
  136.                 MsgBox "This command should never reach here"
  137.             End Select
  138.         result_ret = VBCT_results(cmd_pointer, restype)
  139.     Wend
  140. End Sub
  141. Sub logonbut_Click ()
  142.     Dim version As Long
  143.     Dim sbuf As String
  144.     Dim buflen As Long
  145.     Dim outlen As Long
  146. '   If the application has not already initialized the
  147. '   CT-Library then use the following code to init
  148. '   the CT-Library
  149.     If ctx_pointer = 0 Then
  150.         ret = VBCS_ctx_alloc(CS_VERSION_100, ctx_pointer)
  151.         ret = VBCT_init(ctx_pointer, CS_VERSION_100)
  152.         ret = VBCT_install_callbacks(ctx_pointer, CS_SERVERMSG_CB)
  153.         ret = VBCT_install_callbacks(ctx_pointer, CS_CLIENTMSG_CB)
  154.     End If
  155. '   This form solicits from the user the following
  156. '   information
  157. '   Userid
  158. '   Password
  159. '   Database to be used -   this should be 
  160. '                           or pubs2 for this application
  161. '                           to function property
  162.     usid = uid.Text
  163.     If usid = "" Then
  164.         MsgBox "You must enter a userid"
  165.         Exit Sub
  166.     End If
  167.     pword = password.Text
  168.     sid = serverid.Text
  169.     If sid = "" Then
  170.         MsgBox "You must enter the server name"
  171.         Exit Sub
  172.     End If
  173.     datbase = dbase.Text
  174.     If datbase = "" Then
  175.         MsgBox "You must enter the database name - pubs for SqlServer 4.2 or pubs2 for System 10"
  176.         Exit Sub
  177.     End If
  178.     If datbase <> "pubs2" Then
  179.         MsgBox "Your database name should be - pubs2 for SqlServer System 10"
  180.     End If
  181. '   Once the information needed to open a connection is
  182. '   obtained from the user open a connection with the server
  183. '   using the following code. This code allocates a connection
  184. '   sets the connection properties, connects to the server,
  185. '   allocates a command and changes the database to pubs2
  186.     sbuf = uid
  187.     buflen = Len(sbuf)
  188.     ret = VBCT_con_alloc(ctx_pointer, con_pointer)
  189.     ret = VBCT_con_props_str(con_pointer, CS_SET, CS_USERNAME, sbuf, outlen)
  190.     If pword <> "" Then
  191.         ret = VBCT_con_props_str(con_pointer, CS_SET, CS_PASSWORD, pword, outlen)
  192.     End If
  193.     ret = VBCT_con_props_str(con_pointer, CS_SET, CS_APPNAME, "TestCTLib", outlen)
  194.     ret = VBCT_con_props_str(con_pointer, CS_SET, CS_HOSTNAME, "TestCTLib", outlen)
  195.     ret = VBCT_connect(con_pointer, "")
  196.     ret = VBCT_cmd_alloc(con_pointer, cmd_pointer)
  197.     ret = process_no_rows("use " & datbase)
  198. '   If the connection has been made and the database changed
  199. '   to pubs/pubs2 then hiding the connect button will allow
  200. '   the application to run
  201.     If ret = 99 Then
  202.         mainform!multibut.Visible = False
  203.         Unload Me
  204.     End If
  205. End Sub
  206.