This blog is subject the DISCLAIMER below.

Sunday, November 30, 2008

How to restrict some users to update some tables under some criteria?

Q. How to restrict some users to update some tables under some criteria?

A. If you administer SQL server database, you know that you can grant\deny user updating some tables, but what if you wish to grant\deny user updating some tables when just column equal some value, scenario like that

Table Course (ID, CourseName)

Table Student (ID, Name, CourseID, ….)

Sure, the most common example we give when we teach someone the introduction of databases especially relationships, so if you don’t know it; in brief Student has right to have some courses and the relationship is one-to-many; course-took by- many students.

1

Going on our scenario, data entry1 responsible for insert\update\delete all students take C# course, data entry2 responsible for insert\update\delete all students take Java course

2 3

Clear, isn’t it?

What you should do is to create 2 users dataentry1, and dataentry2 and to create 2 database roles CSharpController, and JavaController.

To create user using SQL Server Management Studio [URL]

To create Database Role using SQL Server Management Studio [URL]

Assign dataentry1 to CSharpController role, and dataentry2 to JavaController, you can assign more users to proper role as you see.

Next step; when user does insert\update\delete operation on Student table, users belong to CSharpController have right if and only if CourseID = 1, and the same for JavaController if and only if CourseID = 2

So, let’s write some code or script; yes, trigger to do those validations

create trigger ManageDML_Student
on student
for insert, delete, update
AS

--here to get column value and assign it variable to check its value later

IF IS_MEMBER ('CSharpController') = 1 && --value == 1--
  commit transaction
else
rollback transaction

Thanks :)


Acknowledge
I'd like to thank Mohamed Abd ALLAH Hewedy, he helped me through this problem

.. more.

Wednesday, November 26, 2008

Enabling Remote Debugging for tomcat

Sometimes your web application just works very fine on your local machine and when you move it to the deployment environment you see a BOOM. If the deployment environment is a Non-GUI machine (which is the common case), it is very hard to debug on that machine. Simply all what you need is to use a remote debugger to connect to the server machine and see what is wrong.

The concept is that you enable the web server to start the JVM in debug mode and start listening on a certain port for remote debuggers to connect, in tomcat, all what you need to do is to add this line to the catalina.sh
you will find at the begining of the file a set of lines started by "#" as they are commented, uncomment the JAVA_OPTS and insert the following line between double qoutes.
"JAVA_OPTS = -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

-Xdebug: tells the VM to start in debugging mode.
-Xrunjdwp: selects the protocol to use,address: the port,suspend=n: tells the server to start listening even if no debugger is connected, simply, start and dont wait for a debugger to connect.

That's it, tomcat is waiting for a debugger to connect.

.. more.

Tuesday, November 18, 2008

Limitations on using Cookies

Make note of the following limitations when using Cookies (I'm not sure if that applies to all Web-technologies or just Asp.Net, but I've just solved a bug related to this issue using Asp.Net):

  • A cookie size is limited to 4096 bytes. It is not much, so cookies should be used to store small amounts of data. For larger amounts of data
  • Also, number of cookies is limited to 20 per website. If you make new cookie when you already have 20 cookies, browser will delete oldest one.
Quoted from beansoftware.com

.. more.

Saturday, November 08, 2008

dotNetWork.org 9th gathering


Date:
Saturday, November 29th 2008,
12:00 - 16:00

Attendance is FREE =)

Note:
Again (like the last 2 gathering), we are having 2 parallel tracks, but this time we have 4 sessions presented by 4 different speakers.. Waiting for your feed-back about that..


Speakers:

Mohamed Ahmed Meligy
Senior Software Developer, Raya-Software.

Mostafa Mourad
Team Leader, ITWorx.

Hossam El-Deen M. Barakat
Senior Software Developer, Raya-Software.

Hossam Kamel
Senior Software Engineer, ITWorx.
Agenda:

12:00 - 14:00
Applying Domain Driven Design on ASP.NET MVC
by Mohamed Meligy.
Information Architecture
by Mostafa Mourad.
14:30 - 16:30
IIS 7.0
by Hosam Kamel.
BizTalk-SharePoint Integration
by Hossam El-Deen M. Barakat.
Location:


Canadian International College, @ "El-Tagamo3 El-5ames"

Buses will be available at: Nady El-Sekka (11:00 AM - 11:30 AM)
Please be there before 11:30 coz we will leave on time..


For those who wanna keep tuned with further news about this event & other upcoming events of the dotnetwork.org user group, please check the following links:

Yahoo!Group:
http://tech.groups.yahoo.com/group/dotnetworkorg/

Facebook Event:
http://www.facebook.com/event.php?eid=32256529483
You'd better join the above event if you have a facebook account so we can roughly estimate the attendees count..


Facebook Fan Page:
http://www.facebook.com/pages/netWorkorg/13135685545

Facebook Group:
http://www.facebook.com/group.php?gid=2409268236

Please don't hesitate to contact me if you have any further questions..
See u on the gathering ;)

.. more.

Sunday, November 02, 2008

Enabling remote access to Mysql

A very common problem when using Mysql is when you try to remotely connect to the server, the solution is very simple and direct.

Configuration:
1- find a file named "my.cnf", this file contains the server configurations.
2- if you find a line with this syntax "skip-networking", comment it by putting a "#" in the begining of the line.
3- if you find a line with this syntax: bind-address = 127.0.0.1, comment it as well, this line tells mysql to accept connections only from localhost.

Persmissions:
now, you have to tell mysql who is to access the server with what permissions
1- login to mysql(example using root user name) : mysql -uroot -p
2- suppose that the data base we need to make available is named koko, so to make koko available to root with password 'password' at the machine with address 192.168.1.5 we write:
GRANT ALL on koko.* TO 'root'@'192.168.1.5' IDENTIFIED BY 'password';
3- then write : FLUSH PRIVILEGES;

Note: do not forget to restart mysql to reload configurations in the my.cnf file.

.. more.