<p>So basically I'm building an app for my company and it NEEDS to be built using MS Access and it needs to be built on SQL Server.</p>

<p>I've drawn up most of the plans but am having a hard time figuring out a way to handle the auditing system.</p>

<p>Since it is being used internally only and you won't even be able to touch the db from outside the building we are not using a login system as the program will only be used once a user has already logged in to our internal network via Active Directory.  Knowing this, we're using <a href="https://stackoverflow.com/questions/9052/is-there-a-way-for-ms-access-to-grab-the-current-active-directory-user">a system to detect automatically the name of the Active Directory user</a> and with their permissions in one of the DB tables, deciding what they can or cannot do.</p>

<p>So the actual audit table will have 3 columns (this design may change but for this question it doesn't matter); who (Active Directory User), when (time of addition/deletion/edit), what (what was changed)</p>

<p>My question is how should I be handling this.  Ideally I know I should be using a trigger so that it is impossible for the database to be updated without an audit being logged, however I don't know how I could grab the Active Directory User that way.  An alternate would be to code it directly into the Access source so that whenever something changes I run an INSERT statement.  Obviously that is flawed because if something happens to Access or the database is touched by something else then it will not log the audit.</p>

<p>Any advice, examples or articles that may help me would be greatly appreciated!</p>

[{'answer_id': 12644, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 0, 'selected': False, 'text': '<p>How many users of the app will there be? Is there possibility of using windows integrated authentication for SQL authentication?</p>\n\n<p><strong>Updated</strong>: If you can give each user a SQL login (windows integrated) then you can pickup the logged on user using the SYSTEM_USER function. </p>\n'}, {'answer_id': 12650, 'author': 'Jay Mooney', 'author_id': 733, 'author_profile': 'https://Stackoverflow.com/users/733', 'pm_score': 2, 'selected': False, 'text': '<p>Does this work for you?</p>\n\n<pre><code>\nselect user_name(),suser_sname()\n</code></pre>\n\n<hr>\n\n<p>Doh!  I forgot to escape my code.</p>\n'}, {'answer_id': 12653, 'author': 'SQLMenace', 'author_id': 740, 'author_profile': 'https://Stackoverflow.com/users/740', 'pm_score': 0, 'selected': False, 'text': '<p>It should be</p>\n\n<pre><code>select user name(),suser sname()\n</code></pre>\n\n<p>replace spaces with underscores</p>\n'}, {'answer_id': 12660, 'author': 'Jay Mooney', 'author_id': 733, 'author_profile': 'https://Stackoverflow.com/users/733', 'pm_score': 1, 'selected': False, 'text': '<p>If you specify SSPI in your connection string to Sql, I think your Windows credentials are provided.</p>\n'}, {'answer_id': 12672, 'author': 'SQLMenace', 'author_id': 740, 'author_profile': 'https://Stackoverflow.com/users/740', 'pm_score': 0, 'selected': False, 'text': '<p>you need to connect with integrated security aka trusted connection see (<a href="http://www.connectionstrings.com/?carrier=sqlserver" rel="nofollow noreferrer">http://www.connectionstrings.com/?carrier=sqlserver</a>)</p>\n'}, {'answer_id': 12679, 'author': 'Jay Mooney', 'author_id': 733, 'author_profile': 'https://Stackoverflow.com/users/733', 'pm_score': 1, 'selected': False, 'text': '<p>I tried playing with Access a bit to see if I could find a way for you.  I think you can specify a new datasource to your SQL table, and select Windows NT Authentication as your connection type.  </p>\n'}, {'answer_id': 12687, 'author': 'Jay Mooney', 'author_id': 733, 'author_profile': 'https://Stackoverflow.com/users/733', 'pm_score': 1, 'selected': False, 'text': '<p>Sure :)</p>\n\n<p>There should be a section in Access called "External Data" (I\'m running a new version of Access, so the menu choice might be different).</p>\n\n<p>Form this there should be an option to specify an ODBC connection.</p>\n\n<p>I get an option to Link to the datasource by creating a linked table.</p>\n\n<p>I then created a Machine datasource. I selected SqlServer from the drop down list.  Then when I click Next, I\'m prompted for how I want to authenticate.</p>\n'}, {'answer_id': 12724, 'author': 'Andrew G. Johnson', 'author_id': 428190, 'author_profile': 'https://Stackoverflow.com/users/428190', 'pm_score': 1, 'selected': False, 'text': '<pre><code>CREATE TRIGGER testtrigger1\nON testdatatable\nAFTER update\nAS \nBEGIN\n    INSERT INTO testtable (datecol,usercol1,usercol2) VALUES (getdate(),user_name(),suser_sname());\nEND\nGO\n</code></pre>\n'}, {'answer_id': 12731, 'author': 'Jay Mooney', 'author_id': 733, 'author_profile': 'https://Stackoverflow.com/users/733', 'pm_score': 2, 'selected': False, 'text': '<p>Ok, it\'s working here.  I\'m seeing my windows credentials when I update my tables.  So, I bet we missed a step.  Let me put together a 1,2,3 sequence of what I did and maybe we can track down where this is breaking for you.</p>\n\n<hr>\n\n<ol>\n<li>Create a new MSAccess database (empty)</li>\n<li>Click on the tables section</li>\n<li>Select external data</li>\n<li>Pick ODBC database</li>\n<li>Pick Link to the datasource by creating a linked table</li>\n<li>Select Machine datasource</li>\n<li>Pick New...</li>\n<li>System Datasource</li>\n<li>Pick SQL Server from the list and click Next, Finish.</li>\n<li>Give the new datasource a name and description, and select (local) for the server. Click Next.</li>\n<li>Pick "With Windows NT authentication using the network login ID".  Click Next.</li>\n<li>Check Change the default database to, and pick the DB. Click Next. Click Finish.</li>\n<li>Test the datasource.</li>\n<li>Pick the table that the Trigger is associated with and click OK.</li>\n<li>Open the table in Access and modify one of the entries (the trigger doesn\'t fire on Insert, just Update)</li>\n<li>Select * from your audit table</li>\n</ol>\n'}, {'answer_id': 67920, 'author': 'Mark Plumpton', 'author_id': 10422, 'author_profile': 'https://Stackoverflow.com/users/10422', 'pm_score': 1, 'selected': False, 'text': '<p>We also have a database system that is used exclusively within the organisation and use Window NT logins.  This function returns the current users login name:</p>\n\n<pre><code>CREATE FUNCTION dbo.UserName() RETURNS varchar(50)\nAS\n    BEGIN\n    RETURN  (SELECT nt_username FROM master.dbo.sysprocesses WHERE spid = @@SPID)\n    END\n</code></pre>\n\n<p>You can use this function in your triggers.</p>\n'}, {'answer_id': 69057, 'author': 'Ricardo C', 'author_id': 232589, 'author_profile': 'https://Stackoverflow.com/users/232589', 'pm_score': 0, 'selected': False, 'text': '<p>My solution would be not to let Access modify the data with linked tables. </p>\n\n<p>I would only create the UI in Access and create an ADO connection to the server using windows authenticated in the connection string. Compile you Access application as dbe to protect the VB code. </p>\n\n<p>I would not issue SQL statement, but I would call stored procedures to perform the changes in the database, and create the audit log entry in an atomic transaction.</p>\n\n<p>The UI (Access) does not need to know the inner works on the server. All it needs to do is request and update/insert/delete using the stored procedures you would create for this purpose. The server should handle the work.</p>\n\n<p>Retrieve a record set with ADO using a view with the hint NOLOCK implemented in the server and cache this data in Access for local display. Or retrieve a single record and lock only that row for editing. </p>\n\n<p>Using linked tables your users will be locking each other.</p>\n\n<p>With ADO connections you will not have the trouble to set ODBCs on every single client. </p>\n\n<p>Create a table to set the server status. You application will check it before any action. you can use it to close the server to the application in case that you need to perform changes or maintenance.</p>\n\n<p>Access is a great tool. But it should only handle its local data and not be allowed to mess with the precious server.</p>\n'}]
['https://Stackoverflow.com/questions/12638', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/428190/']