Connection Database Option Explicit
' local variable (s) to hold property value (s)
Private lsserver as String ' local copy
Private Lsdatabase as String
' local variable (s) to hold property value (s)
Private lsusername as String ' local copy
Private Lspassword as String ' local copy
Private Lsselectsql as String ' local copy
' local variable (s) to hold property value (s)
Private lstable as String ' local copy
Public Property Let Table (ByVal vdata as String)
' used when assigning a value to the ' and on the left side of a assignment.
' syntax:x.table = 5
Lstable = Vdata
End Property
Public Property Get Table () as String
' used when retrieving value of a, on the right side of a assignment.
' Syntax:Debug.Print x.table
Table = lstable
End Property
Public Property Let Selectsql (ByVal vdata as String)
' used when assigning a value to the ' and on the left side of a assignment.
' Syntax:x.selectsql = 5
Lsselectsql = Vdata
End Property
Public Property Get Selectsql () as String
' used when retrieving value of a, on the right side of a assignment.
' Syntax:Debug.Print X.selectsql
Selectsql = Lsselectsql
End Property
Public Property Let Password (ByVal vdata as String)
' used when assigning a value to the ' and on the left side of a assignment.
' Syntax:x.password = 5
Lspassword = Vdata
End Property
Public Property Get Password () as String
' used when retrieving value of a, on the right side of a assignment.
' Syntax:Debug.Print X.password
Password = Lspassword
End Property
Public Property Let UserName (ByVal vdata as String)
' used when assigning a value to the ' and on the left side of a assignment.
' Syntax:x.username = 5
Lsusername = Vdata
End Property
Public Property Get UserName () as String
' used when retrieving value of a, on the right side of a assignment.
' Syntax:Debug.Print x.username
UserName = Lsusername
End Property
Public Property Let Server (ByVal vdata as String)
' used when assigning a value to the ' and on the left side of a assignment.
' Syntax:x.server = 5
Lsserver = Vdata
End Property
Public Property Get Server () as String
' used when retrieving value of a, on the right side of a assignment.
' Syntax:Debug.Print x.server
Server = Lsserver
End Property
Public Property Let Database (ByVal vdata as String)
' used when assigning a value to the ' and on the left side of a assignment.
' Syntax:x.database = 5
Lsdatabase = Vdata
End Property
Public Property Get Database () as String
' used when retrieving value of a, on the right side of a assignment.
' Syntax:Debug.Print x.database
Database = Lsdatabase
End Property
Public Function Connectdatabasebyodbcdns (Lsdns as String) as ADODB. Connection
On Error GoTo Errhandle
Dim Conn as New ADODB. Connection
Dim strconn as String
strconn = "dsn=" & Lsdns & _
"; Uid= "& Lsusername & _
"; Pwd= "& Lspassword
If conn.state = adStateOpen Then
Conn.close
End If
Conn.Open strconn
Conn.cursorlocation = adUseClient
Set Connectdatabasebyodbcdns = Conn
Exit Function
Errhandle:
Err.Raise 102, "Dbconn.cls", "Can ' t Connect to" & Database & "database!"
End Function
Public Function Connectdatabasebyodbc () as ADODB. Connection
On Error GoTo Errhandle
Dim Conn as New ADODB. Connection
Dim strconn as String
strconn = "Provider=msdasql.1" & _
"; User id= "& Lsusername & _
"; Password= "& Lspassword & _
"; Persist Security Info=false "& _
"; Initial catalog=" & Lsdatabase & _
";D ata source=" & Lsserver
If conn.state = adStateOpen Then
Conn.close
End If
Conn.Open strconn
Conn.cursorlocation = adUseClient
Set CONNECTDATABASEBYODBC = Conn
Exit Function
Errhandle:
Err.Raise 10