This technique is useful when writing utilities or services which do not require interaction with the user.
It's pretty simple - but keep in mind connecting to the database is only the first step if you wish to use our business logic objects - most of our objects require a database object, a system profile object, a JiwaLib object and a JiwaCommonLib object.
- Code: Select all
Public Function GetDatabase(ByVal ServerName As String, ByVal DatabaseName As String, ByVal SQLLogin As String, ByVal SQLPassword As String, ByVal JiwaLogin As String, ByVal JiwaPassword As String, ByVal XMLProfileFile As String) As JiwaODBC.database
Dim Database As New JiwaODBC.database
Database.ConnectionDetails = "Provider=SQLOLEDB; Data Source=" & ServerName & ";Initial Catalog=" & DatabaseName & ";User ID=" & SQLLogin & ";Password=" & SQLPassword & ";"
Database.IniFile = XMLProfileFile
If Database.MakeConnections(0) Then
If Database.DoLogOn(JiwaLogin, JiwaPassword) = False Then
Throw New Exception(Database.ErrorMessage)
Else
End If
Else
Throw New Exception(Database.ErrorMessage)
End If
Return Database
End Function
And here's the code to use the above function :
- Code: Select all
Dim Database As JiwaODBC.database
Dim SystemProfile As JiwaSysProfile.clsSysProfile
Database = GetDatabase("JiwaMike", "JiwaDemo_060513", "sa", "jiwa", "Admin", "password", "C:\Program Files\Jiwa Financials\Jiwa\Jiwa.XML")
' Create a system profile object, and load the xml file
SystemProfile = New JiwaSysProfile.clsSysProfile
SystemProfile.Load(Database.IniFile)
' You may like to create other support objects at this point - eg : JiwaCommonLib, JiwaLib, JiwaSearch, etc
' Do your processing here...
Database.BreakConnections()
Database = Nothing