Hi,
Here is what I do.
I have created a text file which has the .Ini extension. It contains the following line:
127.0.0.1,sa,
The IP address could be replaced with the remote server name and you can add the database password after the last comma.
I use the following code to connect my application to the database server:
Call this sub first. It will call the other function it self.
Sub Establish_Connection()
On Error GoTo Err_Handler
Dim mResponse As String
Set dbConnection = New ADODB.Connection
dbConnection.Open getDBString
If dbConnection.State = adStateOpen Then
frmSplash.Show
Else
mResponse = MsgBox("Unable to open connection.", vbCritical, "Critical Error"

End If
Exit Sub
Err_Handler:
MsgBox Err.Number & Chr(13) & Err.Description & Chr(13) & "Try to run the application again", vbExclamation + vbOKOnly, "Connection: Connection Failure"
End
End Sub
Public Function getDBString() As String
On Error GoTo Err_Handler
Dim fso As New FileSystemObject
Dim fileObj As TextStream
Dim locAry As Variant
If fso.FileExists(App.Path & "\" & "Hrs.ini"

Then
Set fileObj = fs

penTextFile(App.Path & "\" & "database.ini", ForReading)
'DB Name = 0
'User ID = 1
'Password = 2
locAry = fileObj.ReadAll
locAry = Split(locAry, ","
getDBString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbHRS;Data Source=" & Trim(locAry(0)) & "; User ID=" & Trim(locAry(1)) & ";Password=" & Trim(locAry(2))
End If
Exit Function
Err_Handler:
MsgBox Err.Number & Chr(13) & Err.Description & Chr(13), vbExclamation + vbOKOnly, "Connection: getDBString"
End Function
You will have to include Microsoft Scripting Run Time liabrary to make it work.
This example works with Sql Server only. You will need to change the connection string in your vb code a bit to connnect you appliaction to other Databases.
Send me an email if you need further help.
Regards,
- krshaikh -