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'm trying to connect to an external SQL server DB programmatically from a SharePoint WebPart. The problem is that I'm not able to authenticate to the DB although I gave access to application pool identity on it.

After investigation, I knew that the reason is that we are using Windows Authentication with NTLM, which doesn't have the ability to pass the credentials to the external DB. I also knew that kerberos can be a solution. But, other than kerberos, do we have any other options?

I've heard about something called SharePoint Secure Stores where I can declare a specific target data source and SharePoint can handle the authentication to it. But I'm not sure if this solution fits my problem

share|improve this question
    
Please add the information how you connect to SQL(connection string) and the exact error you get. Also, check if you are using SQLExpress- if so, it will not work normally –  Amit Kumawat Jun 25 '12 at 14:28
    
The error I was getting: "Login failed for user NT Authority\ANONYMOUS" –  Mohammed Shokry Jul 10 '12 at 8:20
    
What I have done temporarily is that I wrapped my code that connects to the SQL DB with SPSecurity.RunWithElevatedPrivileges which made SharePoint able to pass the app bool credentials to SQL DB. And hence the access succeeded. –  Mohammed Shokry Jul 10 '12 at 8:22

2 Answers 2

You can also use connection string with SQL server authentication instead of windows.

Data Source=ServerName; Initial Catalog=DatabaseName; User Id=UserName; Password=UserPassword;
share|improve this answer

I answered a similar question recently.

SharePoint 2010 you should use the Secure Store Service (SSS) for these kind of settings (credentials, connectionstrings etc). That provides a user interface for selected users, you can then in your Web Part Property point to the SSS application ID that you want it to use (you could also get fancy and make the property a dropdown of available application ID's).

Create a library class with a GetCredentials method that fetches SecureStoreProvider using SPServiceContext and use the GetCredentials(appId) method to fetch your SecureStoreServiceApplicationCollection.

Read full answer here

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.