Link to home
Start Free TrialLog in
Avatar of matherson_bill
matherson_bill

asked on

Urgent - DSN Connection

Hello. In the following example, to open an Access DB I use the following statement: Set dbBiblio = OpenDatabase(C:\video.mdb). This works fine but the problem is that I dont want to use Access but Pervasive 2000.(It is a RDBMS similar to SQL Server). So, I made my Pervasive DB, then I made a machine data source and I named it "video". Finally I'm trying to open my Pervasive DB like this: Set dbBiblio = OpenDatabase(video). The problem is that it doesn't open automatically. When I run the application I first receive a "Select Data Source" window,then I select "video" DSN and then it runs. How can I connect without having to choose my DSN from the prompt window?


Dim dbVideo As Database
Dim rsTitles As Recordset

Private Sub Command1_Click()
List1.Clear
SQLQuery = "Name LIKE '*" & Text1 & "*'"
rsTitles.FindFirst SQLQuery
If rsTitles.NoMatch = True Then Exit Sub
List1.AddItem rsTitles.Fields("Name")
Do Until rsTitles.NoMatch = True
    rsTitles.FindNext SQLQuery
    List1.AddItem rsTitles.Fields("Name")
Loop
End Sub

Private Sub Form_Load()
Set dbVideo = OpenDatabase(video)

SQLQuery = "SELECT * FROM Customers"
Set rsTitles = dbVideo.OpenRecordset(SQLQuery)
Do Until rsTitles.EOF = True
    List1.AddItem rsTitles.Fields("Name")
    rsTitles.MoveNext
Loop
End Sub
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richie_Simonetti
If you have the driver, try to use ADO instead.
I am giving you an example with respect to SQL Server and MS Access using ADO OLE DB, you can use the same (by changing the provider name).

    Dim con As New ADODB.Connection
    con.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" & strUser & ";Password=" & strPWD & ";Initial Catalog=" & strDB & ";Data Source=" & strServer)

Same way for MS ACCESS

    Dim conLocal As New ADODB.Connection
    conLocal.Open "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\LocalDB.mdb"

Cheers

Narayanan
Avatar of matherson_bill
matherson_bill

ASKER

It worked. Thanks Tim. Thanks everybody for the help.