简体   繁体   English

UNC上的Windows服务和MS Access

[英]Windows service and MS Access on UNC

I am trying to get my Windows service to connect to an MS Acces database that is located on a UNC 我试图让我的Windows服务连接到UNC上的MS Acces数据库

private static void InsertData(string sql)
    {
        System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();

        conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;" +
                                @"Data source=\\svr\Users\XXXX\XXXXX\db.accdb";


        try
        {
            conn.Open();
            OleDbCommand cmd = new OleDbCommand(sql, conn);
            cmd.ExecuteNonQuery();

            WriteToFile("Data saved successfuly...!");
        }
        catch (Exception ex)
        {
          WriteToFile("Failed due to: " + ex.Message);
        }
        finally
        {
            conn.Close();
        }
    }

This is the error I get "The Microsoft Access database engine cannot open or write to the file '\\svr\\Users\\XXXX\\XXXXX\\db.accdb'. It is already opened exclusively by another user, or you need permission to view and write its data." 这是我收到的错误,“ Microsoft Access数据库引擎无法打开或写入文件'\\ svr \\ Users \\ XXXX \\ XXXXX \\ db.accdb'。它已由另一个用户独占打开,或者您需要查看和查看文件的权限。写入其数据。”

The permissions are set to domain users, read, write and modify etc. The database is not open by anyone. 权限设置为域用户,读取,写入和修改等。任何人都不可以打开数据库。

I have tried the exact code in a console app and it works fine. 我已经在控制台应用程序中尝试了确切的代码,并且工作正常。 Any ideas? 有任何想法吗?

I just remembered where you could have an issue. 我只记得您可能在哪里遇到问题。 I remember having issues with the 64-bit ODBC vs. 32-bit ODBC! 我记得64位ODBC与32位ODBC出现问题!

If you are running 32-bit Ms Access you have to use 32-bit ODBC executable at path C:\\Windows\\SysWOW64\\odbcad32.exe ! 如果您正在运行32位Ms Access,则必须在路径C:\\Windows\\SysWOW64\\odbcad32.exe使用32位ODBC可执行文件!

You have to setup the connecting first: 您必须先设置连接:

1) C:\\Windows\\SysWOW64\\odbcad32.exe started as administrator and clicking on button add : 1) C:\\ Windows \\ SysWOW64 \\ odbcad32.exe以管理员身份启动,然后单击添加按钮

ODBC数据源

2) Then enter your connection here: 2) 然后在此处输入您的连接:

连接

First edit An example of filling the ODBC Data Source: 首先编辑一个填充ODBC数据源的示例:

一个如何填充数据源的示例

Don't forget that afterwards you are addressing your newly create data source. 不要忘记,此后您将解决新创建的数据源。

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

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