提问者:小点点

部署过程中出现连接字符串错误C#[已关闭]


OleDbConnection MyConN= new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\3d_ServeR\Documents\Visual Studio 2013\Projects\POS\POS\POSDb.accdb");

程序部署时出现连接字符串错误是否有解决此问题的方法?

试过了,但我想这是不是只适用于sql

OleDbConnection MyConN_Deploy = new OleDbConnection
    {
        ConnectionString = "Data Source=" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\POSDb.accdb"
    };

错误


共1个答案

匿名用户

您必须指定数据库文件的正确路径,如下所示:

//If it's on the same folder as the executable then 
//you can set it to the file name without specifying a path.
var dbPath = "Path\\To\\Your\\DB\\POSDb.accdb";

OleDbConnection MyConN= new OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={dbPath}");