在 VBA 中创建与 Pervasive 的 DSNless 连接
我在连接数据库方面非常陌生,因此如果我不熟悉某些术语,我深表歉意。
我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论如何,我看到你的问题:
如果你在连接字符串中使用“driver=”,则无法使用路径。您必须在连接字符串中指定数据库名称(或使用 ServerDSN= 和 ServerName= 进行远程连接的引擎 DSN)。使用 ODBC 驱动程序时也不指定提供程序。
如果不至少创建一个通用数据库名称,则无法连接到 PSQL 数据库。您不需要 ODBC DSN,但它会有所帮助。不支持使用 PSQL ODBC 或 OLEDB 连接到路径的方法。
您可以使用 DTO 在代码中创建数据库名称。
Anyway, I see your problem:
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.