在 VBA 中创建与 Pervasive 的 DSNless 连接

发布于 2024-11-30 17:05:12 字数 674 浏览 4 评论 0原文

我在连接数据库方面非常陌生,因此如果我不熟悉某些术语,我深表歉意。

我想使用 VBA 打开与通用数据库的 DSNless 连接,但我遇到了各种问题。我遇到的论坛都提供了各种有用的代码,但我希望看到一个完整的子例程,看看它们是如何组合在一起的。通过尝试将不同的代码位应用到我的代码中,我最终遇到了各种错误代码。

因此,有人可以发布完整代码的示例来打开连接并创建记录集。这

是我收到的

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 

错误:运行时错误'-2147217837(80040e53)':模式、保护级别或未知参数已在连接字符串中设置(错误)

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 bits 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪心 2024-12-07 17:05:12

无论如何,我看到你的问题:

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

如果你在连接字符串中使用“driver=”,则无法使用路径。您必须在连接字符串中指定数据库名称(或使用 ServerDSN= 和 ServerName= 进行远程连接的引擎 DSN)。使用 ODBC 驱动程序时也不指定提供程序。

如果不至少创建一个通用数据库名称,则无法连接到 PSQL 数据库。您不需要 ODBC DSN,但它会有所帮助。不支持使用 PSQL ODBC 或 OLEDB 连接到路径的方法。

您可以使用 DTO 在代码中创建数据库名称。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文