Not quite sure what you are asking.
WebParts are in a Webpart zone on a WebPart page so they automatically have
access to SharePoint. Code Access Security will need to be set properly for
them to access the SharePoint object model, but no other special steps need
to be taken.
If you are talking about a webpart that will be accessing a separate data
source like a SQL server database, then do it the same way you would access
such a database from a webpage. Create a Connection Object, a Command
Object, a data Adapter and use those to fill a Data set. The only thing
that is different here is that Session state is turned off by default in
SharePoint so you can't cache the dataset in Session State. SharePoint has
its own caching mechanism for things like this. If I remember correctly it
is called a PartCache. You must use a webpart that inherits from the
SharePoint webpart object model to use it.