Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 averything) works when it's in a console application and run on that server.

What coud be the problem here?

Thanks in advance

share|improve this question
    
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

3 Answers 3

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

share|improve this answer

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

You have to use SPSecurity.RunWithElevatedPrivileges

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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