iT邦幫忙

0

Access問題

請教各位先進:

公司的Access做為前端的存取介面使用ODBC去連線MSSQL Server 為後端的資料庫,

目前想加入一項功能, 就是當使用者登錄時或存取資料時, 系統會自動新增使用者的名字,

有嘗試使用過網路上提供說的CurrentUser, 但回傳的值都是Admin,

在使用者權限上還需做什麼特別的設定嗎? 或者有更好的解法呢?

作業系統:Windiws10 , Office2016, MS SQL Server2012

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

4
賽門
iT邦超人 1 級 ‧ 2016-08-31 11:19:42
最佳解答
The CurrentUser function returns the name of the current Access user. In a secured database, this would be the name of the user who has logged in. If the database is unsecured, this function would return Admin (the default account) as the name of the user.

從這段話,你應該可以瞭解Access的CurrentUser()只會回傳Admin是因為資料庫沒有設置Security。

因為你們用ODBC連SQL Server,如果ODBC連線選用的是整合式Windows驗證,如下圖:

http://ithelp.ithome.com.tw/upload/images/20160831/20017649rnRgEF6sKV.png

如果你們使用AD驗證機制,CurrentUser()應該會顯示登入帳號。

如果是本機帳號,CurrentUser()還是顯示Admin。

如果ODBC是用SQL Server帳號登入,就只會顯示Admin了,因為Access的CurrentUser(),基本上只能回傳Access資料庫的登入訊息。

那麼,根本解決方法是什麼呢?

用一個SQL Server指令回傳:

Select [User ID] from Session Where [My Session]=1

這樣就可以查出SQL Server的真正登入帳號名稱。

尼克 iT邦大師 1 級 ‧ 2016-08-31 13:08:58 檢舉

賽大,十八般武藝。/images/emoticon/emoticon12.gif

我要發表回答

立即登入回答