You should deploy the assembly of the web part to the Global Assembly Cache (GAC), configure full trust for the application in the web config, or create a custom trust, that allows this kind of database interaction.
I suggest you to read the following articles to get a deeper insight into the Codes Access Security:
Microsoft Windows SharePoint Services and Code Access Security