Solved

Sql server timeout error when updating user profile

Posted on 2010-09-10
6
660 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
  • 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now