I am getting this exception when I run my code in a C# Web Server Application, but if I copy the same code to a C# console application, it works fine.

System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

And help would be great, thanks in advance.

It sounds like you have a web service configuration issue. If you think that might be it, try google'ing your error with added keywords "config" and "Unrestricted".