gpt4 book ai didi

c# - 使用 OLE DB 连接 Pervasive DB

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:50 27 4
gpt4 key购买 nike

我们有一个使用 Pervasive PSQL 数据库的现有闭源第三方应用程序。例如,PSQL 位于目录 c:\test 中,名称如 holiday.dat、offers.dat 等。我想在没有安装 Pervasive Workstation Engine 的情况下阅读并尽可能写入这些文件。使用工作站引擎和 ODBC 连接,它可以毫无问题地运行。但是我们不会在任何客户端上安装工作站引擎,第三方应用程序也不会。

关于 connectionsstrings.com我找到了连接字符串:

"Provider=PervasiveOLEDB;Data Source=C:\datafilesDirectory;"

使用指令:

using Pervasive.Data.SqlClient;using System.Data.OleDb;using System.Xml.Serialization;

测试连接片段:

string strAccessConn = "Provider=PervasiveOLEDB;Data Source=C:\datafilesDirectory;"string strAccessSelect = "SELECT * FROM holidays";// Create the dataset and add the Categories table to it:DataSet myDataSet = new DataSet();OleDbConnection myAccessConn = null;try{    myAccessConn = new OleDbConnection(strAccessConn);}catch(Exception ex){    Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message);    return;}try{    OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect,myAccessConn);    OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(myAccessCommand);    myAccessConn.Open();    myDataAdapter.Fill(myDataSet,"Categories");}catch (Exception ex){    Console.WriteLine("Error: Failed to retrieve the required data from the DataBase.\n{0}", ex.Message);    return;}finally{    myAccessConn.Close();}

应用程序无法打开数据库连接。

最佳答案

在连接字符串中,您应该替换 C:\datafilesDirectory;用 C:\test;.

关于c# - 使用 OLE DB 连接 Pervasive DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1464313/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com