How to leverage SQL Server Application Roles in MsAccess?

Mats 1 Reputation point
2022-05-17T16:50:36.447+00:00

Does anyone know if there is a way to use SQL Server Application Roles from within Ms Access?

I have an Ms Access application with tables linked to SQL Server. Users of the application can access and manipulate data in the linked tables according to their role in the application. I have also granted users access to the tables on SQL Server, since users authenticate via integrated windows authentication. This however means that the users can also connect to the tables on the server directly, bypassing the protection implemented in the Access application, which is of course not ideal. The Application Roles feature in SQL Server seems to offer a nice solution for this problem, however, there seems to be no direct support for this feature in Ms Access.

An option I was considering is to create a proxy ODBC driver which activates the application role using credentials passed to it in the connection string. However, I have no previuos experience with developing such a solution, so am interested to here what other ideas might be out there!

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,706 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
821 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Erland Sommarskog 101K Reputation points MVP
    2022-05-17T21:32:10.49+00:00

    I don't know Access, so I can't say where in Access you would put in the application roles.

    However, I like to point out that you can only achieve security-by-obscurity this way. The password for the application role must be available from the Access application, which means that users how know their ways can find it, and then employ it from SSMS.

    If you want to achieve a fully secure solution, where users only can access the database through the application, you need to have three tiers, so that the middle tier connects to the database in a way that is not available to the user. (This can be achieved in a number of ways, both with networking and application users.)

    Now, Access and three-tier application does not really go together, although you could put the Access application as a Remote Desktop application.

    0 comments No comments

  2. AlphonseG 191 Reputation points
    2023-11-09T14:14:29.33+00:00

    An alternative thought.

    Use SQL Server Authentication. When you create logins in SQL Server, append an obscure set of chars ($%@!x) to the password you supply to the user.

    So, you tell the user their password is marYJane1, when it is actually marYJane1$%@!x.

    Obviously, you will need a login screen in your app. When the user logs in, you append the extra chars to their entered password and make the connection.

    If they try to connect by any method outside of your app, the password they enter won't work.

    Assuming you are distributing an ACCDE, it would be very difficult for anyone to figure out the extra chars.


  3. Albert Kallal 4,651 Reputation points
    2023-11-10T18:31:07.0233333+00:00

    A few things:

    You cannot use multiple connections to the same database for security.

    Now, read the above again nice and slow!!!

    So, if you using windows authentication for logons, then you don't really have different connections, and it does not matter, does it? (either you can use the SQL server, or you can't). When using windows auth, then member ship in roles etc. is managed by windows, and not by sql server.

    If you using SQL server logons, then you can't use DIFFERENT logons with different connections from the ONE access application. I stated this in the first sentence here, and I mean what I say, and I said what I meant.

    The reason for above is that Access will cache ANY valid connection to the database. That means if you opened a form, used code, used a pass-though query, it DOES NOT matter, but ONLY that some place, some how, some where you obtained a valid connection to sql server. The VERY instant you do this, then that user/password + valid connection is now cached by access.

    And once the above occurs, if you THEN say use a table that linked using a read only connection's and logon? Well, since at SOME point in time you connected with a valid read/write logon, then that will be used!!!

    Worse, is you really cant control WHICH cached logon will be used!!

    What the above means is that multiple connections with different rights MUST BE REMOVED from your design assumptions here.

    To be fair, this caching of valid connections is one of the best features of ODBC connections in Access, since this means you can link all of your tables WITHOUT including the user id + password. This means no user id and password exists in the linked tables, and thus someone opening up the application (or even attempting to import the linked tables to another application) will find that those links do NOT work (until such time you execute a valid SQL logon from Access).

    While this is a "huge" increase in security when using linked tables, the downside of this knowledge is that you thus can't have multiple connection to the same database with different rights, and you can't do this, since you have NO control over which connection will be used by Access.

    As for using roles from SQL server? I suppose if this is a compiled Access application (accDE),then a function to test/check for membership in a sql server role could be adopted, and thus forms could be prevented from being open by users without membership in such roles.

    As for how the cached user + password system works, and how you can use this greatly to your advantage is explained here:

    https://www.microsoft.com/en-us/microsoft-365/blog/2011/04/08/power-tip-improve-the-security-of-database-connections/#:~:text=Power%20Tip%3A%20Improve%20the%20security%20of%20database%20connections,one%20more%20hole%20...%207%20Extra%20reading%20