Connecto to database SQL2005 from ActionScript3

[SIZE=3]I need a code that enables me to connecto to database SQL2005 using ActionScript3 even directly or through middleware(Asp.net2 only not PHP).
i searched about this issue in google and i found that it should be a middleware like PHP or ASP page and i want to know in details why direct connection is not secure and how data is exposed to all user and can be accessed ? as in C# we connecto to database directly so why data is not exposed to all user and we can secure it?
i need please a help as i am new in this forum and a beginner in cs3
if any one have an optimized solution please give full code for that [/SIZE]