Solved

SQL Connection Timeout

Posted on 2004-04-07
3
6,265 Views
Last Modified: 2008-03-03
I am setting the timeout in a connection string to be 420 seconds but for some reason it still times out at 30, I've run the query in analyzer and it's all good, in the example below i set the timeout to 0 which should be infinite
Here's the code

            public DataAccess(string psUser, string psPassword, string psServer, string psDB)
            {
                  mstrConnection = "Network Library=DBMSSOCN;Data Source=" + psServer + ";Initial Catalog=" + psDB + ";User ID=" + psUser + ";Password=" + psPassword + ";Connection Timeout = 0";
                  
            }

            public DataTable ExportShorts()
            {
                  System.Diagnostics.Debug.WriteLine(mstrConnection);
                  
                  SqlConnection conn = new SqlConnection(mstrConnection);
                  System.Diagnostics.Debug.WriteLine(conn.ConnectionTimeout);
                  DataSet ds = new DataSet();
                  DataTable dt = new DataTable();
                  ds=SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "ShortPositionAges");
                  dt=ds.Tables[0];
                  return dt;
            }

Thanks
0
Comment
Question by:painlessprod
[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
  • 2
3 Comments
 

Author Comment

by:painlessprod
ID: 10778893
Sorry I'm also using sql helper if that has anything to do with it, but I don't see why it should.
0
 
LVL 3

Accepted Solution

by:
gillit earned 125 total points
ID: 10779015
I have had trouble with this before, although I am not very familiar with SqlHelper. But the following is what I used.

SqlCommand myCommand = new SqlCommand();
myCommand.Connection = new SqlConnection(strConnection);
myCommand.Connection.Open();
myCommand.CommandText = strSql;         // *******************1
myCommand.CommandType = CommandType.Text;  //***************2
myCommand.CommandTimeout = 120;

SqlDataAdapter objDataAdapter = new SqlDataAdapter(myCommand);

objDataAdapter.Fill(dt);


*****************

You probably would need to change 1 and 2 with the following:
myCommand.CommandText = "ShortPositionAges";
myCommand.CommandType = CommandType.StoredProcedure;


**************

Hope that helps.
0
 

Author Comment

by:painlessprod
ID: 10779246
Well that worked.

Upon doing further research I found that SQLHelper doesn't allow a command timeout, it has a connection timeout but not a command timeout.  So SQLHelper is useless for large stored procedures.  Otherwise SQLHelper is a very useful tool.

Thanks gillit
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

732 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