简体   繁体   English

在C#控制台应用程序中访问数据库

[英]Access database in C# console application

The current problem I'm having is an error message that it could not find file C: now I dont know what the problem is because the file is in that location. 我当前遇到的问题是一条错误消息,它找不到文件C:现在我不知道问题出在哪里,因为文件位于该位置。 I have I tried in both .accbd and .mbd. 我已经在.accbd和.mbd中都尝试过。

private static OleDbConnection GetConnection()    
{
    OleDbConnection conn = new OleDbConnection();
    String connectionString = 
            @"Provider=Microsoft.JET.OlEDB.4.0;"
            + @"Data Source= C:\Temp\F1\Docs\Expeditors Project\Table1.accbd";

    conn = new OleDbConnection(connectionString);
    conn.Open();
    return conn;
}

Do you tried another Provider? 您是否尝试过其他提供商? For example: 例如:

Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=C:\Temp\F1\Docs\Expeditors Project\Table1.accbd;

try \\\\ in Data Source Path Data Source路径中尝试\\\\

like below - 像下面-

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Data\test.mdb;Persist Security Info=False");

try this ` 试试这个`

    `private static OleDbConnection GetConnection() throws SQLException{
        { 
    if (conn==null) 
{ 
            try{                                                                                    OleDbConnection conn = new OleDbConnection();
            String connectionString = @"Provider=Microsoft.JET.OlEDB.4.0;"
                                      + @"Data Source= C:\Temp\F1\Docs\Expeditors Project\Table1.accbd";
            conn = new OleDbConnection(connectionString);
            conn.Open();

            return conn;
        }}
    catch(Exception e){
    e.printStackTrace();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM