SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have my custom webpart, which have access to database. I need to configure data source, catalog, username and password, which allows webpart a access database. I don't want that users can see, what is account name or password. What is best way manage user rights in SharePoint?

I have thinking couple ways, but I cannot tell are these ideas good and whether there are better ways manage this?

Idea1: I save all neasesery information to list and I somehow hide it from users? (HOW?) Webpart reads this list information and access a database.

Idea2: Hardcode connection string to webpart. However maintenance will suffer.

Idea3: Webpart settings and connection string, but then all users must set it and it will not work.

share|improve this question

migrated from Jan 27 '14 at 14:32

This question came from our site for professional and enthusiast programmers.

no need for any of those!

you just need to add it to web.config


somthing on the lines of:

<add key="SQLConnectionString" value="server=;database=myDatabaseservername;uid=MyUserName;password=MyPassword;" />

MyUserName and MyPassword would need to be changed to a user account that has access to the sql server...

server= (You sql server name) and database=myDatabaseservername (your sql database name) need to be changed to the correct values! all can be found when logging in into sql server!

share|improve this answer

Create a custom tool part for you password using a password text box as the control.

Its just a case of subclassing the ToolPart control then adding the password textbox in the CreateChildControls() method

This link goes into the full detail

share|improve this answer

Modifying the web.config should be your last choice, in case of SharePoint. Especially, if there are other possibilities, like the following:

Store the connection string, user name and password in the the property bag of the SPSite.RootWeb or SPWebApplication or SPFarm (depends on how granular you want to be with these settings). Data in the property bag is completely hidden from the end user. It can be set and retrieved only by code or by powershell - for both you need access on the SharePoint Server.

It's worth to check out this blog post too, if you have wondered about the difference between SPWeb.Properties and SPWeb.AllProperties.

share|improve this answer

Your Answer


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.