Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SharePoint

4 views
Skip to first unread message

Gerhard

unread,
May 27, 2009, 6:13:01 PM5/27/09
to
I have an application that is almost working the way I want. Only issue
right now is that about 20% of the time I get "Unable to connect to the
remote server". I can run the exact same code over an over, and most of the
time it works perfectly, but occasionally I get this error. Any ideas how I
can make this more consistent? The code it happens in is below. The account
name being passed is valid, the same account sometimes works, sometimes
doesn't

Thanks.

Private Sub GetSharePointProfile()

Dim accountName As String = strAccountPrefix & strSAMAccountName
Dim i As Integer = 0

bUserAccountExists = False

Dim UserProfileService As New
oem.UserProfileService.UserProfileService
Dim service As UserProfileService.UserProfileService = _
New UserProfileService.UserProfileService()

Try
service.Url = strSPURL

service.Credentials = _
System.Net.CredentialCache.DefaultNetworkCredentials

propertyData = _
service.GetUserProfileByName(accountName)

If propertyData.Length > 0 Then bUserAccountExists = True

Catch ex As Exception
mmReturnMessage = mmReturnMessage & "GetSharePointProfile() " &
ex.Message.ToString & "<br />"
Finally
service.Dispose()
service = Nothing
UserProfileService.Dispose()
UserProfileService = Nothing
End Try

End Sub

Steven Cheng

unread,
May 28, 2009, 4:15:11 AM5/28/09
to
Hi Gerhard,

Based on the description and code snippet you provided, you're encountering
some "server cannot access /connect error" when calling some sharepoint
webservice, correct?

As for the webservice consuming code, -I think it is ok and doesn't have
anything incorrect. IMO, the problem you encounter is likely a problem due
to the server-side processing of the service(which may abort or unable to
accept some of the webservice requests you made). How often is your client
program trying to call the webservice? If it is very frequent, you can try
slow down the frequency to see whether that will somewhat reduce the
failure requests number.

Also, if possible, you can try capture some network trace(via netmon or
other network utitlity) to see whether those requests are failed due to
some network error.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.


--------------------

Gerhard

unread,
May 28, 2009, 10:12:04 AM5/28/09
to
Thanks.

This is on a development server, with only me currently using it. So, there
is no network access involved. It doesn't make sense to me that SharePoint
cannot handle the traffic from one user, but if that is the case, how can I
justify using it in a production environment with over 100 users? It puts me
back in the position of wanting to go directly to the tables through a stored
procedure, or through a direct call to the SharePoint .dll and skip the web
service step. Is there any documentation of how to go through the sharepoint
.dll to accomplish what the user profile service does?

Thanks.

WenJun Zhang[msft]

unread,
Jun 3, 2009, 6:25:28 AM6/3/09
to
Hi Gerhard,

Steven is taking sick leave now. We are currently researching this issue
and will update you as soon as we get more findings or suggestions on it.
Meanwhile, could you please let us know if the problem can consistently be
reproduced on your dev server? i.e: if you call GetUserProfileByName 10
times in 1 or 2 mins, will it always return "Unable to connect to the
remote server" error about 2 times?

Thanks.

Sincerely,

WenJun Zhang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Gerhard

unread,
Jun 3, 2009, 1:43:01 PM6/3/09
to
Sorry to hear Steven is sick. He has always been a big help to me.

The issue with the web service was its inconsistency. It is not that it
always errored 2 out of 10 times. Sometimes it would run 15 or so and then
error 4 or 5 times in a row. It was wierd.

I've gotten around it by using direct calls to the stored procedures for the
Get and also specific Update. Still using the web service for any Create
ones as I couldn't find a stored procedure that did that. That doesn't
happen often though, so hopefully it will be stable in the production
environment.

What would be really good is to have a stored procedure that could be used
for the create also. As it currently stands, to meet my requirement of
updating the fields (such as address) in SharePoint when they are changed in
the accounting software used, I have to create a CLR stored procedure so that
I can call the Web Service if it is a new user. Seems real round about to
me. Be a lot more straightforward if there was a stored procedure for
creating a user directly without having to go through the web service.

Thanks for your help.

Steven Cheng

unread,
Jun 4, 2009, 12:22:05 AM6/4/09
to
Hi Gerhard,

Sorry for the late response as I got a bad cold previous days.

As for the webservice issue, if you have other sharepoint server
environment, you can perform some tests on other server boxes to verify
whether the unstable behavior is consistent on all sharepoint environment
or just specific to this dev environment.

Currently, you can keep your current workaround, and I would also recommend
try troubleshooting the original object model approach as that will be much
more effecient than using webservice.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.


--------------------
From: =?Utf-8?B?R2VyaGFyZA==?= <Ger...@community.nospam>
Subject: RE: SharePoint
Date: Wed, 3 Jun 2009 10:43:01 -0700

Gerhard

unread,
Jun 4, 2009, 2:37:01 PM6/4/09
to
Glad you are feeling better, and I hope you stay healthy.

I have it pretty stably running now, with the only remaining call to the web
service being on creating a new user. Looks like the stored procedure that
is used for that is profile_UpdateUserProfileBlobData passing the SID (from a
trace I ran). However, it is being passed a SID that is different than the
windows SID. Is there a way to get/create the Sharepoint SID? Any other way
to create a new user using a stored procedure so a call to a web service
would not be needed?

Take care.

Steven Cheng

unread,
Jun 4, 2009, 11:14:15 PM6/4/09
to
Thanks for your reply Gerhard,

Yes, the sid used internally may have been somewhat mangled. I haven't
found any reference which explain the format. One thing I think you can
have a look is the UserProfileManager class of the MOSS object model(in the
Microsoft.Office.Server.dll).

The "CreateUserProfile" method in it has refered to some methods related to
sid generation, which might be helpful.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

Gerhard

unread,
Jun 5, 2009, 10:55:03 AM6/5/09
to
Thanks.

The procedure sounds good, but isn't documented. There is a site, that
gives and example,
http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.userprofilemanager.aspx,
but that code as written doesn't work. First, it says TopologyManager is
undefined. So I add an Imports Microsoft.Sharepoint.Portal.Topology, but
that then says TopologyManager is obsolete, and also gives an error on
creating the UserProfileManager. This is the type of stuff that waste all
sorts of developer time.

If you come across documentation that actually shows a workable solution, it
would be helpful.....

Thanks, and I hope you are feeling better.

Gerhard

unread,
Jun 5, 2009, 6:10:01 PM6/5/09
to
I got what I need working in a console app:

Using site As New SPSite(strSPSite)

Dim context As ServerContext = ServerContext.GetContext(site)
Dim profileManager As New UserProfileManager(context)

If Not profileManager.UserExists(accountName) Then
Dim profile As UserProfile =
profileManager.CreateUserProfile(accountName)
If profile Is Nothing Then
mmReturnMessage = mmReturnMessage & "Failed to
Create User with account :" & accountName & "<br />"
End If
End If
End Using

However, all sorts of wierd errors in a web app, even running under an
account pool with server admin priviledges. Tried using
SPSecurity.RunWithElevatedPrivileges but still errors (like can't process
request, please try again.. Property evaluation failed.... Operation is
not valid due to the current state of the object....)

Any idea what it takes to get this to run in a web app? Since the code runs
in a console app, it must be something to do with web priviledges. I even
tried setting the anonomous user to one with admin priviledges, but still got
errors.

I hope other SharePoint actions aren't as convoluted... will never get
anything done.

Thanks.

Steven Cheng

unread,
Jun 8, 2009, 11:02:54 PM6/8/09
to
Thanks for your reply Gerhard,

So you have got the following code working in a normal console app, correc?

===============

Using site As New SPSite(strSPSite)

Dim context As ServerContext =
ServerContext.GetContext(site)
Dim profileManager As New UserProfileManager(context)

If Not profileManager.UserExists(accountName) Then
Dim profile As UserProfile =
profileManager.CreateUserProfile(accountName)
If profile Is Nothing Then
mmReturnMessage = mmReturnMessage & "Failed to
Create User with account :" & accountName & "<br />"
End If
End If
End Using

==================

That's just what I've used at the begininig via the object model. My
original object model test program is also a simple console program which
use the UserProfileManager to access the profile data.

From your description in last message, the problem you encounter is fail to
call the same code in a web application. Is this web application a
standalone ASP.NET web application or is it hosted in sharepoint site(in
_layout folder)?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.


--------------------
Subject: RE: SharePoint
Date: Fri, 5 Jun 2009 15:10:01 -0700

Gerhard

unread,
Jun 9, 2009, 10:08:01 AM6/9/09
to
Hi,

You have it right.

I have a class/dll that has that function in it. When called from the
console app, it works fine. When call from a simple .aspx page it gets wierd
errors. Same when a web service calls the .dll. The .aspx app is in IIS, on
a Windows 2003 server with an admin account running it, the application pool
it is assigned to is an admin account, and they are both admin accounts on
SharePoint. Seems to me that if the application pool account has server and
sharepoint admin permissions that I shouldn't be running into this,
especially since the same login can run a web service and do the same thing I
am trying to do through the api (I am trying to get away from the web service
as it is inconsistent, not stable enough for a production environment as far
as I am concerned).

I have also tried running it under extended priviledges, but that just give
a different batch of errors.

Can you help on what security settings need to be in place to be able to run
this without error (like it runs in the console app)? The .dll does run
stably in the console app and does exactly what I want it to do. There must
be a trick to get it to do the same in a web app/web service that I haven't
been able to locate after days of running searches and trying to find an
answer.

Thanks for your help.

Steven Cheng

unread,
Jun 11, 2009, 12:35:13 AM6/11/09
to
Thanks for your reply Gerhard,

Since my original test is also console specific, I may need to test the web
application case also. I'll let you know if I get any results.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.


--------------------
Thread-Topic: SharePoint
thread-index: AcnpC7NPZoxqa2Q+TymJ6g9B3JEugQ==
X-WBNR-Posting-Host: 12.108.45.6
From: =?Utf-8?B?R2VyaGFyZA==?= <Ger...@community.nospam>

Subject: RE: SharePoint
Date: Tue, 9 Jun 2009 07:08:01 -0700

Gerhard

unread,
Jun 11, 2009, 3:04:01 PM6/11/09
to
Thanks.

I built a default Visual Studio 2008 web page, put the routine in it and
called it from the page load event, and got errors.

I even tried setting the application pool to the same one used by sharepoint
for the web service. Didn't help.

Do you have access to the web service code to see how it is done there?

Thanks again.

Steven Cheng

unread,
Jun 12, 2009, 8:03:12 AM6/12/09
to
Thanks for the reply Gerhard,

Generally we do not have the permission to access product source code
directly and we'll also use the public product symbols is some production
debugging is required. I'll build a web application to see the behavior.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================


Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

--------------------
Subject: RE: SharePoint
Date: Thu, 11 Jun 2009 12:04:01 -0700

Gerhard

unread,
Jun 15, 2009, 11:51:01 AM6/15/09
to
Thanks.

Here is the code that I am getting errors on (I x'd out the account name and
site). This was just added to a default new web site. Added Label1 and set
windows authentication to deny any unauthorized users.

Imports Microsoft.SharePoint.Administration
Imports Microsoft.Office.Server.UserProfiles
Imports Microsoft.SharePoint
Imports Microsoft.Office.Server

Partial Class _Default
Inherits System.Web.UI.Page

Dim strSPSite As String = "http://xxxxxxxxx"
Dim accountName As String = "xxxxxx"
Dim mmReturnMessage As String = String.Empty
Dim strSPKey As String = String.Empty

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Try


Using site As New SPSite(strSPSite)

Dim context As ServerContext = ServerContext.GetContext(site)
Dim profileManager As New UserProfileManager(context)

If Not profileManager.UserExists(accountName) Then
Dim profile As UserProfile =
profileManager.CreateUserProfile(accountName)
If profile Is Nothing Then
mmReturnMessage = mmReturnMessage & "Failed to
Create User with account :" & accountName & "<br />"

Else

End If
End If
End Using

Catch ex As Exception
mmReturnMessage = mmReturnMessage & ex.Message
End Try

Me.Label1.Text = mmReturnMessage

End Sub
End Class

Steven Cheng

unread,
Jun 15, 2009, 11:20:48 PM6/15/09
to
Hi Gerhard,

I've performed some tests and did find the problem you encounter. I've used
a visual studio hosted(file system) based web site project to run the
object-model code and encounter "Null Reference for ServerContext".

I've also checked some former issue records and found that there are some
other members encountered this problem when tried accessing the
UserprofileManager in a non-sharepoint ASP.NET web
application(ServerContext not available). And the workaround suggested is
move the code into a sharepoint page(under _layouts folder) or develop a
custom webservice(which use objectmodel to access the sharepoint
userprofile) and then deploy the webservice into sharepoint application so
that your client code can access the custom webservice you created.

If the custom webservice approach is possible for your case, here are some
references about creating custom webservices:

http://www.mylifeinaminute.com/2008/03/20/sharepoint-2007-wss-30-and-custom-
web-services/

http://msdn.microsoft.com/en-us/library/ms464040.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.


--------------------


From: =?Utf-8?B?R2VyaGFyZA==?= <Ger...@community.nospam>
Subject: RE: SharePoint

Date: Mon, 15 Jun 2009 08:51:01 -0700

Gerhard

unread,
Jun 17, 2009, 6:01:01 PM6/17/09
to
Thanks for the feedback. I ran this in IIS (not file system) so was slightly
different, but I am glad you see the type of issue I am running into.

The thing is, I already have it working (except for random failures) using
the SharePoint web service, so I don't see any point in making a new web
service. Is there no way to create a new user using the API? I almost had
that working, but ran into the SID issue where SharePoint uses a different
SID than windows, and that is a required parameter to the create user
function in the API, but then there is no data on how to get/create the SID.
Do you have any information on that?

Thanks.

Bob

Steven Cheng

unread,
Jun 22, 2009, 12:21:15 AM6/22/09
to
Thanks for the followup Gerhard,

Sure, if you've already got the built-in webservice interface working, it
will be unnecessary to setup your own webservice(which use object model).
For the SID, so far I haven't got any documentation on it since the
internal implemenation is not public and may vary from version to version.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

--------------------


Gerhard

unread,
Jun 25, 2009, 2:24:02 PM6/25/09
to

Thanks.

The only remaining issue is that the Web Service errors out randomly, even
just using the same code.

Is there anyway to add a new user through the API or existing Stored
Procedure in a web app?

We have the one way the works in a console app, but not a web app.

We have the Web Service, but in testing that has not proven to be very
reliable.

Seems like there should be some way (preferably through a Stored Procedure
as those tend to be very reliable) to do this simply and reliably.

Thanks for all your work on this.

Steven Cheng

unread,
Jul 1, 2009, 6:13:57 AM7/1/09
to
Thanks for reply Gerhard,

Yes, the object model problem is at the web application in which the SPFarm
and SPSite context cannot be got. So far the working solution is the
webserice one though it is a bit unstable on your production environment.
I'll try working further on the object model approach to see whether it is
possible in a web application.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

--------------------
Thread-Topic: SharePoint
thread-index: Acn1wh1PNQ8IYJ2zQrCe6Krr0l2+xg==
X-WBNR-Posting-Host: 12.108.45.6


From: =?Utf-8?B?R2VyaGFyZA==?= <Ger...@community.nospam>
Subject: RE: SharePoint

Date: Thu, 25 Jun 2009 11:24:02 -0700

Gerhard

unread,
Jul 6, 2009, 11:06:00 AM7/6/09
to

Thank you. I hope you find a workaround. In the meantime, I will use the
webservice.

Have a happy day!

0 new messages