Solved

Sql server timeout error when updating user profile

Posted on 2010-09-10
6
671 Views
Last Modified: 2012-05-10
Hello,

I have a LINQ recordset (of users and their username) that I want to loop through and update a user's profile value.  The profile information is based on the default asp.net membership tables.

The following is my code and the timeout error is happening on the userProfile.save() line
Dim dbRGT As New RegentSignsDataContext

        Dim myResults = From myTable In dbRGT.vw_USERS_GroupEmails

        For Each myRow In myResults
            ''The following line writes out to the OUTPUT window during Debug
            ''System.Diagnostics.Debug.Write(myRow.chrFullName.ToString + " = " + myRow.UserId.ToString)
            Dim userProfile As ProfileCommon = ProfileCommon.Create(myRow.UserName, True)
            userProfile.groupEmail = 1
            userProfile.Save()            
        Next

Open in new window


The specific error I am getting is:
Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. I should add that if I take out the profile.save I can loop through the recordset and perform other functions with no problem.

Can anyone help me figure out why this error is happening.  All other connections to the SQL server are working and have never thrown a timeout error.  

I even tried adding this code into the function in desperation:
System.Data.SqlClient.SqlConnection.ClearAllPools()
but it did not help at all
0
Comment
Question by:jordanking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 9

Accepted Solution

by:
wellhole earned 500 total points
ID: 33650520
Wherever your profilecommon executes the sql, you should set the command timeout to a value higher than the default.
0
 
LVL 1

Author Comment

by:jordanking
ID: 33650825
Thanks for the quick reply,

I changed my connection string in the web.config file which references a development database on a sql server 2008 express edition on the local computer where visual studio is running

the connection string is now:
   

This did not solve the problem.  I believe this changed the timeout to 30 seconds.  
0
 
LVL 9

Expert Comment

by:wellhole
ID: 33651104
I expect that the default timeout is 30 seconds. You should increase it to 900 and see if that fixes it.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 1

Author Comment

by:jordanking
ID: 33651187
I made that change but it did not work.  It did not wait 900 seconds and it threw the error same as before
0
 
LVL 9

Assisted Solution

by:wellhole
wellhole earned 500 total points
ID: 33651201
Then, I hope your sql is formatted correctly such that it's not trying to wipe out the whole database in 1 shot.

Besides that, see if you can change this timeout for the COMMAND and not the connection.
0
 
LVL 1

Author Comment

by:jordanking
ID: 33651785
okay,

so i took out LINQ data altogether and tested my code with just one record and it worked.  So then I tried adding the following code right below the datacontext declaration:
dbRGT.CommandTimeout = 9000

however that did not extend the time at all, so i thought it must be something with how i am getting the users profile.  So i changed the way I get all the users and it works.  The commandtimeout was a valueable lesson for using LINQ and SQL datacontext commands, so thanks for pointing me in that direction.

My working code is now:
Dim chrUsername As String

        Dim muc As MembershipUserCollection
        muc = Membership.GetAllUsers()
        Dim mu As MembershipUser
        For Each mu In muc
            chrUsername = mu.UserName
            Dim userProfile As ProfileCommon = ProfileCommon.Create(chrUsername, True)
            userProfile.groupEmail = 1
            userProfile.Save()
            ''iRet = myEmail.GroupEmail(myRow.Email, myRow.chrFullName, myRow.UserId.ToString, guidEmail)
        Next

Open in new window

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question