I have a problem with accessing the SQL Server database from an application page in SharePoint 2010. With using the SqlConnection and SqlCommand an Adapter I keep getting an error

Cannot find table [0]

But the strange thing is that the exact same code (same connection string and everything) works when it's in a console application and run on that server.

What could be the problem here?

Thanks in advance

  • Is this a custom database you're trying to access? Is the server remote or local to the code running? – James Love Oct 3 '11 at 10:06
  • You don't state what credentials you're using to connect – SHug Oct 4 '11 at 12:13

Could be authentication, ensure your SP service account has correct permissions, try connecting to the SQL instance as the service account.


This is all caused by the "Code Access Security" changes made by SharePoint that disable the SQLConnection.

You have to use SPSecurity.RunWithElevatedPrivileges


This is probably related to User Account Control (UAC). Try running IE as an administrator by right clicking and choosing "Run as Administrator." I know a bunch of people will give me hell for this, but it's the worst thing Microsoft has ever implemented... wait.... within the context of server applications. Write back and let us know if that's what was biting you in the rump.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.