473,762 Members | 8,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access SQL Server ODBC MDB File Security

I have a security related question.

I was wondering how i can set up security so that for a table:
a user can read all data in the table but only update and delete their
own data (there is a username field in the table where the user enters
their username)

I am using access 2003 and linking tables odbc from sql server with
windows security.

Any help would be much appreciated.

Apr 20 '06 #1
8 4406
On 20 Apr 2006 05:06:08 -0700, ad*****@gmail.c om wrote:

There is no built-in way to do that, so you'll have to write some
code.
If this was the Northwind Orders form, in Form_Current I would write:
Me.AllowEdits = (Me.txtUserName = g_strLoggedInUs erName)
(I'm comparing the username in the field with a global variable set
when the user logs in)

At the form level we also have AllowAdditions and AllowDeletes you may
want to take advantage of.

-Tom.

I have a security related question.

I was wondering how i can set up security so that for a table:
a user can read all data in the table but only update and delete their
own data (there is a username field in the table where the user enters
their username)

I am using access 2003 and linking tables odbc from sql server with
windows security.

Any help would be much appreciated.


Apr 20 '06 #2
another question regarding linked tables in access 2003 from sql
server:

i have linked sql server tables to access (odbc) and was wondering if I
can automatically update the linked tables when starting access?

Apr 20 '06 #3
Thanks Tom for your reply.
Ok, tried that and it locks the form correctly but users can open the
table and edit any data. i would prefer to do the same thing, use
AllowEdits and AllowDeletes not only for the form but also for the
whole data table.

Apr 20 '06 #4
On 20 Apr 2006 07:02:04 -0700, ad*****@gmail.c om wrote:

Check out the Connect property and RefreshLink method in the help
file.
-Tom.

another question regarding linked tables in access 2003 from sql
server:

i have linked sql server tables to access (odbc) and was wondering if I
can automatically update the linked tables when starting access?


Apr 20 '06 #5
On 20 Apr 2006 07:22:14 -0700, ad*****@gmail.c om wrote:

Users have no business with the raw tables, so don't give them access
to the Database window.
Tools > Startup > Display Database Window
Tools > Startup > Use Special Keys (prevents F11)
These options can also be set in code; see the SetOption method in the
Help file.

-Tom.

Thanks Tom for your reply.
Ok, tried that and it locks the form correctly but users can open the
table and edit any data. i would prefer to do the same thing, use
AllowEdits and AllowDeletes not only for the form but also for the
whole data table.


Apr 20 '06 #6
Br
ad*****@gmail.c om wrote:
I have a security related question.

I was wondering how i can set up security so that for a table:
a user can read all data in the table but only update and delete their
own data (there is a username field in the table where the user enters
their username)

I am using access 2003 and linking tables odbc from sql server with
windows security.

Any help would be much appreciated.

Row level security.

I use a UDF that I insert into a where clause in my views. It returns true
if the record is valid for the current user. By using a UDF the view is
still updatable. It handles returning only the employees own record, or all
records of people the person manages (as defined by an organisation tree
table), or all records if an admin user.

Users have no permissions to tables at all.

I use a User table in my database that matches up an employee record with
the username (I use my own add user security routines in a stored procedure
so that this record is automatically created when new users are added).

Works with Windows and SQL logins.

Hope that makes some sense. I can probably show some examples if needed.
--
regards,

Br@dley
Apr 20 '06 #7
Thanks for the reply Br@dley. I would really appreciate if you could
show me an example of the UDF that you mentioned. I am quite new at
security handling in access and sql server databases and espcially new
to using UDF.

Apr 23 '06 #8
Br
ad*****@gmail.c om wrote:
Thanks for the reply Br@dley. I would really appreciate if you could
show me an example of the UDF that you mentioned. I am quite new at
security handling in access and sql server databases and espcially new
to using UDF.

This is based on an organisation structure held in a table. The function
used to follow the structure for each record to see if it belonged to the
parent (and thus could be viewed by the user). I found a much easier way
(hash table). When adding a new organisation record, the stored procedure
that does that automatically builds a "parent string". So the search up the
tree structure is done once when the record is created/modified. Then it's
very simple to do a text search for your parent.

eg.

OrgID = 200, ParentOrgID=100 , ParentString = ';200;100;50;'
OrgID = 100, ParentOrgID = 50, Parentstring = ';100;50;'
OrdIG = 50, ParentOrgID = NULL, Parentstring = ';50;'

So, to return all records who are below OrgID=50, no matter how far down the
tree structure, I simply search for ';50;'
(Note: I wanted the top unit to be included which is why each parentstring
contains the current record's orgid)

This is the procedure that creates the string:

CREATE Procedure dbo.SetOrgStrin g @OrgID int
AS

DECLARE @PID int
DECLARE @OrgString varchar(400)
DECLARE @Delim as char, @New as varchar(11)
Set @Delim = ';'
Set @OrgString = @Delim + Cast(@OrgID as varchar(10))

SELECT @PID = ParID FROM tblOrgStructure WHERE OrgID = @OrgID

While @PID is not null
BEGIN
SET @New = @Delim + CAST(@PID as varchar(10))
IF len(@OrgString) > 0
BEGIN
SET @OrgString = @OrgString + @New
END
ELSE
BEGIN
SET @OrgString = @New
END
SELECT @PID = ParID FROM tblOrgStructure WHERE OrgID = @PID
END

SET @OrgString = @OrgString + @Delim
UPDATE tblOrgStructure
SET ParentString = @OrgString
WHERE OrgID = @OrgID
RETURN

I use my own security screens and stored procedures to manage users. The
screen prompts for the usual security info but also prompts for an employee
from tblEmployees. The stored procedures create the necessary SQL logins etc
but also adds an entry to a user table. This table tells me if the user is
Windows/SQL security and links them to an Employee record so we know who
they are.

eg. The procedure for Windows security (I have seperate SP for Win and SQL
security as they are different to set up.

CREATE Procedure dbo.spSecurityA ddUserWin @Personnel_no AS NVARCHAR(10),
@UserLevel AS SMALLINT, @UserName AS NVARCHAR(20), @Domain as NVARCHAR(20),
@ReadOnly AS BIT,
@HRAccess AS BIT, @TRNAccess AS BIT, @COVAccess as BIT
As
DECLARE @return_status as INT
DECLARE @DomainUser AS NVARCHAR(40)
IF IS_MEMBER('db_o wner') = 1 /* only database owners can change
security */
BEGIN
EXEC('USE core')
SET @DomainUser = @Domain + '\' + @UserName
EXEC @return_status = sp_grantlogin @DomainUser
if @return_status = 0
BEGIN
EXEC @return_status = sp_defaultdb @DomainUser, 'core'
IF @return_status = 0
BEGIN
EXEC @return_status = sp_grantdbacces s @DomainUser, @UserName
IF @UserLevel = 1 /* admin level */
BEGIN
IF @HRAccess =0 AND @TRNAccess = 0 AND @COVAccess = 0 /* if no
access set default HR access */
BEGIN
SET @HRAccess = 1
END
IF @HRAccess = 1
BEGIN
EXEC @return_status = sp_addrolemembe r 'coreadmin', @UserName
END
IF @TRNAccess = 1
BEGIN
EXEC @return_status = sp_addrolemembe r 'coreadmintrn', @UserName
END
IF @COVAccess = 1
BEGIN
EXEC @return_status = sp_addrolemembe r 'coreadmincov', @UserName
END
END
ELSE IF @UserLevel = 2 /* manager level */
BEGIN
SET @HRAccess = 1
SET @TRNAccess = 0
SET @COVAccess = 0
IF @ReadOnly = 1
BEGIN
EXEC @return_status = sp_addrolemembe r 'coremanagerro' ,
@UserName
END
ELSE
BEGIN
EXEC @return_status = sp_addrolemembe r 'coremanager', @UserName
END
END
ELSE IF @UserLevel = 3 /* employee level */
BEGIN
SET @HRAccess = 1
SET @TRNAccess = 0
SET @COVAccess = 0
IF @ReadOnly = 1
BEGIN
EXEC @return_status = sp_addrolemembe r 'coreemployeero ',
@UserName
END
ELSE
BEGIN
EXEC @return_status = sp_addrolemembe r 'coreemployee', @UserName
END
END
END
END
IF @return_status = 0
BEGIN /* make entry in user table */
INSERT INTO tblUsers
(Personnel_no, CoreUser, CoreLevel, WinNTUser, DBName, ReadOnlyAccess,
HRAccess, TRNAccess, COVAccess)
SELECT @Personnel_no, @UserName, @UserLevel, 1, @DomainUser,
@ReadOnly, @HRAccess, @TRNAccess, @COVAccess
END
END
RETURN

I have several database roles. Two versions of each (eg. ManagerRole can see
all the people they manage as defined by the org structure, and
ManagerRoleRO, a read-only version for manager that can only view data)

(I also have a version of this called IsValidOrg() )

CREATE FUNCTION IsValidEmp (@PID int)
RETURNS bit AS
BEGIN
DECLARE @found bit, @ValidPID int
if IS_MEMBER('db_s ecurityadmin') =1 or IS_MEMBER('db_o wner') = 1
BEGIN
set @found = 1
END
ELSE if IS_MEMBER('Admi nRole') = 1
BEGIN
set @found = 1
END
ELSE IF IS_MEMBER('Mana gerRole') = 1 OR IS_MEMBER('Mana gerRoleRO') = 1
BEGIN
DECLARE @SecurityOrgID int
SET @SecurityOrgID = [core].[dbo].[SecurityGetOrgI D]()
SELECT @ValidPID = Personnel_no From tblEmployee
INNER JOIN tblOrgStructure ON tblEmployee.Org ID =
tblOrgStructure .OrgID
Where tblOrgStructure .ParentString like '%;' + cast(@SecurityO rgID as
varchar(10)) + ';%'
AND Personnel_no = @PID
if @ValidPID <> Null
begin
set @found = 1
end
else
begin
set @found = 0
end
END
ELSE IF IS_MEMBER('Empl oyeeRole') = 1 OR IS_MEMBER('Empl oyeeRoleRO') = 1
BEGIN
DECLARE @SecurityEmpID int
SET @SecurityEmpID = [core].[dbo].[SecurityGetEmpI D]()
if @SecurityEmpID = @PID
begin
set @found = 1
end
else
begin
set @found = 0
end
END
return @found
END
Then in all my views I simple add a WHERE clause..

eg. SELECT * FROM dbo.tblEmployee WHERE IsValidEmp(pers onnel_no)

Hope that all makes sense:) It took me quite a while to come up with
something that worked the way I wanted. It's not he most elegant code but it
works.
--
regards,

Br@dley
Apr 23 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
1866
by: Guy Hocking | last post by:
Hi there, i am creating a database driven login page. I am using code that has been successful in the past, however when i upload it to our web server it displys the following message in the page = ****** Microsoft OLE DB Provider for ODBC Drivers error '80004005' General error Unable to open
11
3764
by: Wolfgang Kaml | last post by:
Hello All, I have been working on this for almost a week now and I haven't anything up my sleeves anymore that I could test in addition or change.... Since I am not sure, if this is a Windows 2003 Server or ADO or ODBC issue, I am posting this on all of the three newsgroups. That's the setup: Windows 2003 Server with IIS and ASP.NET actiavted Access 2002 mdb file (and yes, proper rights are set on TMP paths and path,
0
3537
by: ASP.Confused | last post by:
The old message looked a little stale, so I am re-posting it here. Anybody have any ideas of what I could do?!? The previous responses to this question are below. If you want to look at the original question, the subject line is: ADODB.NET and "Access Denied" I have an ASP.NET page writtein in VB that uses ADODB. I just had to
4
5485
by: aspsql | last post by:
I have a website which runs off a Access database which I am currently converting to sql server database. I would like to still use my access front end for reporting and queries.. I created an odbc connection on my computer to the remote sql server and created a link in access to my sql server tables. All my report and Queries run fine I just have one problem it keeps on prompting me for ther password of the remote sqlserver database. I...
5
3913
by: somersbar | last post by:
hello all, im trying to connect to a microsoft access database from an ASP.NET web form. i keep getting the following error though: ERROR Could not use '(unknown)'; file already in use. ERROR Driver's SQLSetConnectAttr failed ERROR Could not use '(unknown)'; file already in use.
2
4239
by: egoldthwait | last post by:
I need to convert a 17mb access 2000 db to Oracle and house it in a Citrix farm. The issue: we have never converted an Access Db to Oracle but can probably use Oracle's Workbench to assist with this. Also - the citrix folks do not want us to keep the FE in Access as the queries and other activities consume a lot of power. The users will be in 3 different offices across the globe all accessing the 1 Oracle DB in Citrix. Does anyone have...
6
6267
by: onnodb | last post by:
Hi all, While working on an Access UI to a MySQL database (which should be a reasonable, low-cost, flexible interface to the DB, better than web-based, much less costly than a full-fledged .NET app or so.... is it?), I tried measuring the bandwith consumed by the Access/MyODBC/MySQL link, which came out to be, er, quite high. I fancied it would be interesting to look at the queries Access throws at MySQL through the ODBC link, so I...
21
4693
by: lesperancer | last post by:
I've got an access97 reporting mdb that pulls data (77,000 rows) from a sql server table into a local table to run reports if the local table is part of the reporting MDB, the insert statement (16 fields) takes less than 30secs, but because of db-bloat, I moved the local table to a 2nd MDB and per postings, this 2nd MDB is copied into a folder and linked as a 'temp' MDB every time I run my reporting mdb
1
3724
by: vbace2 | last post by:
I have searched this forum, and the web, and I have not been able to find a solution to my issue. I may not have used the right search information to find the answer, but I found a lot of issues close to mine, but nothing has helped. We are running Apache/2.2.4 (Win32) PHP/5.2.3. I am trying to use the odbc_connect to connect to an MS Access database that is on another server. I have tried to use both a system DSN, as well as putting the...
3
5128
by: Bret Kuhns | last post by:
I recently started a co-op/internship at a company and they are looking to migrate a large legacy supported application from OLEDB to SQL Server. I'm doing prelim work in experimenting with the options available. The application is huge (1+ million lines of C++ code), so it'd be quite a bit of man hours to adapt all the database code for SQL Server. I stumbled upon linked tables in an OLEDB file to an ODBC source (such as SQL Server) and...
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9927
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9812
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3914
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.