Source code Server
Trang 1Source code Server
Sub connectserver(ddriver As String, sserver As String, uuid As String, ppw As String, ddb As String)
On Error GoTo loi
If UCase$(ddriver) = "ORACLE ODBC DRIVER" Then If oracleconn.State = 0 Then
showstatus "Connectting to Oracle server ", True
oracleconn.ConnectionString = "Driver=" & ddriver & ";Server=" & sserver & ";UID=" & uuid & ";PWD=" & ppw & ";DBQ=" & ddb & ";"""
oracleconn.ConnectionTimeout = 20 oracleconn.Open
Else
MsgBox "This server connected", vbInformation, "Connected" showstatus "Server not ready", False
Exit Sub End If Else
If sqlconn.State = 0 Then
showstatus "Connectting to SQL server ", True
sqlconn.ConnectionString = "Driver=" & ddriver & ";Server=" & sserver & ";UID=" & uuid & ";PWD=" & ppw & ";Database=" & ddb & ""
sqlconn.ConnectionTimeout = 20 sqlconn.Open
Else
MsgBox "This server connected", vbInformation, "Connected" showstatus "Server not ready", False
Trang 2If oracleconn.State = 1 And sqlconn.State = 1 Then showstatus "Connectting fail, server not ready", False If oracleconn.State = 1 Then oracleconn.Close
If sqlconn.State = 1 Then sqlconn.Close End Sub
Private Sub MDIForm_Load() Dim makeable As Boolean Dim autotimes As Integer Dim autoconn As Integer On Error GoTo loi
showstatus "Server startting ", False 'Hien thi Ip cua Middleware
status.Panels("ip").Text = status.Panels("ip").Text & socket(0).LocalIP makeable = True
Trang 3'Khoi tao 2 duong truyen co dinh toi 2 server Set oracleconn = New ADODB.Connection Set sqlconn = New ADODB.Connection 'Lay thong tin khoi dong
Set sysdb = OpenDatabase(App.Path & "\sysserver.mdb") Set connectre = sysdb.OpenRecordset("connect")
Set settingre = sysdb.OpenRecordset("setting")
If connectre.RecordCount > 0 And settingre.RecordCount > 0 Then
ElseIf settingre.RecordCount = 0 Then 'Set default values
Trang 4'Tao database luu thong tin he thong
Dim ser As String Dim uid As String 'Connect toi Oracle
connectserver drv, ser, uid, pw, cdb
If oracleconn.State = 0 And sqlconn.State = 0 Then Exit Sub 'Tiep tuc connect toi Sql server
If oracleconn.State = 1 Then
Trang 5connectre.MoveNext GoTo re
End If
Set orauserre = New ADODB.Recordset Set oradbre = New ADODB.Recordset Set sqluserre = New ADODB.Recordset Set sqldbre = New ADODB.Recordset
showstatus "Testting query executing ", True
'Thuc hien cac cau query cap nhat va tham do server down If orauserre.State = 1 Then orauserre.Close
If oradbre.State = 1 Then oradbre.Close If sqluserre.State = 1 Then sqluserre.Close If sqldbre.State = 1 Then sqldbre.Close
orauserre.Open "Select username,user_id,created From all_users", oracleconn, adOpenStatic, adLockBatchOptimistic, adCmdText
'oradbre.Open "Select From", oracleconn, adOpenStatic, adLockBatchOptimistic, adCmdText
sqluserre.Open "Select name,suid,password,accdate From syslogins", sqlconn, adOpenStatic, adLockBatchOptimistic, adCmdText
sqldbre.Open "Select name,dbid,crdate From sysdatabases", sqlconn, adOpenStatic, adLockBatchOptimistic, adCmdText
Exit Sub loi:
autotime.Enabled = False
If Err.Number = 94 Or Err.Number = -2147217865 Then
MsgBox "Can't auto connect", vbInformation, "Can't connect" mnudisconnect_Click
Trang 6
End If
' if err.Number = then
' If oracleconn.State = 0 Then MsgBox "Oracle server died", vbInformation, "Server died"
' If sqlconn.State = 0 Then MsgBox "SQL server died", vbInformation, "Server died"
'close all socket