开发者

Creating a DSNless connection to Pervasive in VBA

I'm very new at connecting to databases so I apologise if I'm not familiar with some of the terminology.

I would like to open up a DSNless connection to the pervasive database using VBA and I'm running into various issues. The forums that I have come across all give various bits of code which are helpful but I would like to see one full subroutine to see how it all fits together. By trying to apply different bit开发者_如何学JAVAs of code to my code I end up running into various error codes.

Therfore could someone please post an example of the full code to open a connection and create a recordset. It would be most appreciated

FROM COMMENTS

Sub pervasiveExample() 
Dim adoConn As ADODB.Connection 
Set adoConn = New ADODB.Connection 
adoConn.Provider = "PervasiveOLEDB" 
adoConn.ConnectionString = "driver={Pervasive ODBC Client Interface};Data Source=C:\TestData" 
adoConn.Open 
If adoConn.State = adStateOpen Then 
    MsgBox "Welcome" 
Else MsgBox "Error connecting to Database." 
End If 
End Sub 

This is the error I then get: run-time error'-2147217837(80040e53)': Mode, Protection Level, or unknown parameter has been set (incorrectly) in the connection string


Anyway, I see your problem:

Sub pervasiveExample()
Dim adoConn As ADODB.Connection
Set adoConn = New ADODB.Connection
adoConn.ConnectionString = "driver={Pervasive ODBC Client Interface};DBQ=DEMODATA"
adoConn.Open
If adoConn.State = adStateOpen Then
    MsgBox "Welcome"
Else
    MsgBox "Error connecting to Database."
End If
End Sub

If you are using the "driver=" in the connection string, you cannot use a path. You must specify the database name (or engine DSN by using ServerDSN= and ServerName= for remote connections) in the connection string. You also do not specify a Provider when using the ODBC driver.

You cannot connect to a PSQL database without creating at least a Pervasive Database Name. You don't need an ODBC DSN but it helps. There is no supported way to connect to a path with PSQL ODBC or OLEDB.

You can create the Database Name in code though using DTO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜