Biasanya kita kesulitan untuk membuat connection string ke SQL Server. Ini contoh script dan file text yg di baca.
Taruh di Modules
' All variables for data connection
Global DB As New ADODB.Connection
Global ConnectS As String
Global ConnectRpt As String
Global rpt1 As String
Global sConn, asik As String
Global mDB1 As New ADODB.Connection
'Variable for Users
Global USRIDX As String
Global USRID As String
Global USRPWD As String
Global USRNAME As String
Global USRGRP As String
Global USRAUTH As String
Global USRDESC As String
Global USRRPT As String
' for edit INI file
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private gstrKeyValue As String * 256
iniFile = Trim(Command())
If iniFile = "" Then iniFile = "HRD.ini"
Server = GetIni("Connect", "Server")
If Server = "" Then
frmConnect.Show vbModal
GoTo 10
End If
Userid = GetIni("Connect", "Userid")
Password = LCase(Decrypt(GetIni("Connect", "Password")))
Database = GetIni("Connect", "Database")
AttcDir = GetIni("Attachment", "Folder")
TempDir = Environ("TEMP")
ConnectS = "Provider=SQLOLEDB.1;" _
& "Persist Security Info=False;" _
& "User ID=" & Userid & ";" _
& "Password=" & Password & ";" _
& "Initial Catalog=" & Database & ";" _
& "Data Source=" & Server
DB.CursorLocation = adUseClient
DB.Open ConnectS
Public Sub SetIni(iSection As String, iKey As String, iValue As String)
Dim lonSts As String
lonSts = WritePrivateProfileString(iSection, iKey, iValue, App.Path & "\" & iniFile)
End Sub
Public Function GetIni(iSection As String, iKey As String, Optional iDefault As String)
Dim lonSts As String
lonSts = GetPrivateProfileString(iSection, iKey, iDefault, gstrKeyValue, 256, App.Path & "\" & iniFile)
If lonSts > 0 Then
GetIni = Left(gstrKeyValue, lonSts)
Else
GetIni = ""
End If
End Function
Public Function LPAD(iInp As String, iL As Long, iCH As String)
Dim sT As String
If Len(iInp) < st =" iInp" st =" iCH">= iL
If Len(sT) > iL Then
sT = Right(sT, iL)
End If
LPAD = sT
Else
LPAD = iInp
End If
End Function
Public Function RPAD(iInp As String, iL As Long, iCH As String)
Dim sT As String
If Len(iInp) < st =" iInp" st =" sT">= iL
If Len(sT) > iL Then
sT = Left(sT, iL)
End If
RPAD = sT
Else
RPAD = iInp
End If
End Function
buat text file dengan nama HRD.ini, dan isinya sbb
[Connect]
Server=(nama server SQL SERVER)
Userid=sa
Password=(password sa)
Database=(Nama Databasenya)
Kamis, 08 November 2007
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar