Home » SQL Server

ADO.NET Default CommandTimeOut

Dear Techies

SqlCommand.CommandTimeout has a default value of 30 seconds. I know that we can set it in our code. Is there any way to alter this default value by chaning some configuration files which is part of the .NET framework so that I dont have to touch the code.


Appreciate your inputs.


Thank You



Jayaraj Sivadasan



3 Answers Found


Answer 1

The connection string will help you in that. set  the time out in your connection string.

Answer 2

The timeout in the connectionstring is for how long we wait for the connection to sucessfully open. Not for the actual command to complete.

AFAIK there is no config files  provided by .Net itself to control the commandtimeout. But there is nothing to keep you from creating your own config

file and read a value from there. This file can then be edited from outside of the code.



Answer 3

Yes its my mistake Michael. Thanks for the correction Michael.


The SqlConnection and SqlCommand objects each have a property to set  a timeout value (ConnectionTimeout and CommandTimeout, respectively). You should note that the SqlConnection.ConnectionTimeout is the time allowed to establish a connection, and the SqlCommand.CommandTimeout is the time allowed to return data from a query or complete a data operation. The connection object's timeout is sometimes mistaken as a way to control how long an application waits for a query result, which is not the case and can be a "gotcha" for developers.



Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. My Blog: http://ashishkhandelwal.arkutil.com


I have a database table in SQL 2005 with a column of images (image datatype).  The images are GIFs.  I can write a VBScript and write out the images using ADO and I can open them just fine.  When I use ADO.Net, the file doubles in size and will not open.  If I insert into the table using ADO.net, I can pull it out just fine.  The data is/was put in using ADO.

How can I pull the images out of the table using ADO.Net and construct them back as GIFs?  Is there some translation somewhere that I am missing?



Years ago I started using ADO to query databases with sql-statements from Excel VBA as this was the preferred method at that time. I would like to know if ADO is still the best method when using Excel 2007 or 2010? Is ADO.NET or somethin else better?

I postet this question already in the excel forum, however, ADO.NET is not well known there.

If ADO.NET provides new feature, better performance etc. I'd greatly appreciate any demo code of how to query databases from excel.





I am migrating a code from ADO to ADO.NET. Here i am stuck with the SHAPE statement in sql query that is used in ADO. Please help me out with the equivalent code for ADO.NET


sql= " ((SHAPE { " + sql1+ " }  AS SECONDARY APPEND ";
sql= sql+ " ({ " + sql3+ "  } AS TASKAREA RELATE 'STASKID' TO 'TASKID') AS TASKAREA, ";
sql= sql+ " ({ " + sql4+ "  } AS REPEATS RELATE 'STASKID' TO 'STASKID') AS REPEATS, ";

where sql1, sql2, sql3, sql4, sql5 are complex select statements. It gives an invalid sql statement error in oracle db when i execute this.

It would be great if some one helps me out with equivalent code in ado.net using datasets or some other thing. Thanks.


I have a sql server table with a date column that has a default value of GetDate()

this default does not seem to get passed to the EF and so i was wondering what the most elegant way was to code this default value within my asp.net application? I dont want to manually alter the EF Model as i may want to re-import it and dont want to lose these changes.

any suggestions gratefully appreciated





   I am having more than 50 controls in a page which contains textboxes, drop downlists,radiobuttons, combo boxes etc. I want to load a data during page _load and also update the data if there is any control changes. Need best practices to load more data in a page without affecting the performance.

Hello Gurus!

We try to execute our SSIS packages from a .NET application. It works fine until we use “Expressions ” inside Data Flow’s components like “ADO NET Source” (e.g., for building SQL statements)

I use the ADO NET Source Control and want to set the SqlCommand property with an expression holding a SQL statement.

When executing the SSIS package in Visual Studio (in debug mode) I get no problem, everything works fine. When executing the package from within my .NET application it crashes the app completely, only creating a generic Win32 Exception with no relevant information.

My steps:

1.       I created new SSIS package.

2.       Then added the Data Flow component.

3.       Inside Data Flow I added “ADO NET Source”. I use this control in order to get data from Webtrends (a third party data provider). It uses an ODBC driver provided by Webtrends to access the data. SSIS allows me to access ODBC only via ADO NET provider, so that’s why I use ADO NET Source. The problem is not related to the Webtrends driver, we managed to reproduce the error with a connection to a SQL Server.

4.       I would like to have only one SSIS package which can get all the data I need from Webtrends. I just want to set some variables of the SSIS package from within C# (which works fine). When I set variables from C#, I use expressions to generate new SQL statements for the ADO.NET source using the values from the given variables. Unfortunately that does not work. I get an error and the application crashes.

5.       If I do not use Expressions, (by setting the SqlCommand directly in the package) then everything works fine and I can execute package from .Net, but even if I only want to set a hardcoded SQL statement within Expression I get an error….

If I understand correctly there is only one “DTS” framework which is used from SQL Server, Visual Studio and even from .Net/C#.  So I guess that it should work also from .Net without any problem, but probably it messes some parameters which I should set in C# for the application object before package executing.

If someone has already experienced this problem and has a solution please provide me with information on how to fix it.

Our environment:

VS 2008

SQL Server 2008 R2


Microsoft.SqlServer.DTSRuntimeWrap (version

Microsoft.SQLServer.ManagedDTS (version

Microsoft.SqlServer.DTSPipelineWrap (version


Here is my c# code:

  dtsApplication = new dts.Application ();

using (dts.Package dtsPackage = dtsApplication.LoadPackage(packagePath, null ))


packageResult = dtsPackage.Execute();


Here are some screenshots showing my packages:

You can see it’s just so simple…

Control Flow:



Data Flow:



ADO NET Source:





ASP.NET comes with ASP.NET Develepment Server, which can be embedded into ASP.NET application for running the test instead of deployment to IIS alike. 

Does ASP.NET/ADO.NET provide an embedded RDBMS for development purpose instead of access to MS-SQL server alike? Where can i find some popular embedded RDBMS which are open source, implemented by .NET C# and well-integrated with ASP.NET/ADO.NET? thx!



Apologies if this is not the right forum for my topic. I was wondering if someone could help clarify something for me. I have a page that pulls up data from a SQL Server database using a SqlDataAdapter. Recently, running the Fill method for the SqlDataAdapter is throwing an error from ".Net SqlClient Data Provider" (stack trace points to error happening at TDSParser.Run) with a blank error message. I found out that increasing the CommandTimeOut for the adapter's SqlCommand kept the error from happening. Does the CommandTimeOut work on more than just the command execution when used in a SqlDataAdapter? (the sql statement used in the command takes 5-10 seconds to execute on Sql Server Management Studio) Does anyone happen to know why an error with a blank error message is thrown?

Any help would be greatly appreciated.


Hi I am using SQLDataAdapter and I am trying to set the CommandTimeout to 0 but still my application is throwing a time out error. Below is my code and the exception. Any help is greatly appreciated.


 public DataSet getVCRDetailsByPNR(string conn, string pnr)
            sqlCon = new SqlConnection(conn);
            DataSet objDataSet = new DataSet();
                SqlParameter[] sqlParms = new SqlParameter[1];
                sqlParms[0] = new SqlParameter("@pnr", SqlDbType.NVarChar, 20);
                sqlParms[0].Value = pnr;
                sqlDa = new SqlDataAdapter("sp_structuredVcr_pnr", conn);
                sqlDa.SelectCommand.CommandTimeout = 0;
                objDataSet = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "sp_structuredVcr_pnr", sqlParms);
            catch (Exception ex)

            if (objDataSet != null && objDataSet.Tables.Count > 0 && objDataSet.Tables[0].Rows.Count > 0)
                return objDataSet;

                return null;


Exception thrown:

An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.
The statement has been terminated.
  at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
  at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
  at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
  at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
  at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
  at System.Data.SqlClient.SqlDataReader.get_MetaData()
  at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
  at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
  at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
  at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
  at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
  at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
  at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
  at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
  at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
  at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
  at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters)
  at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters)


hello, it's me again :-)

a (maybe) stupid question:

in asp.net 3.5 i've this .browser file:


<browser refID="safari1plus">


<adapter controlType="System.Web.UI.WebControls.Menu" adapterType="" />





now i suppose that in asp.net 4.0 this is not useful.

So what i've to do? I've simply to delete "App_Browsers" folder in my converted project or i've to put in this folder:














What's the best way?

Thank  you very much!



having installed SP1 Beta onto my VS Team Suite, I can't find any references whatoever to the Entity Data Model features; not when creating a new project, not when trying to add items.

Many thanks for any assistance,

Best regards,


I have built ADO.NET Data Services using the following 2 ways:
1. ADO.NET Data Service over Entity Framework
    temp service url: http: http://www.azurize.com/lta/ltadata.svc/
2. ADO.NET Data Service over LINQ2SQL
    temp service url: http: http://www.azurize.com/lta/linq/ltadata.svc/

Both of them is working when testing using web browser
But when i add them as service reference in Visual studio 2008 sp1
Only 1 works and 2 gives me a client stream handling exception:

System.Data.Services.Client.DataServiceClientException was unhandled
  Message="Error processing response stream. Server failed with following message:\r\nAn error occurred while processing this request."
I checked using fiddler and sure that the results have returned from the data service properly
And the client stream proccesing using the class generated by visual studio has resulted the exception;

May I know whether this is because visual studio does not support ADO.NET data service over LINQ to SQL? 



Hi All

I am working on a small system for a summer camp in WPF. I have a database that is linked via ADO.Net Entity Framework. It contains two tables; Campers & Bunks. The structure is as follows:


CustomerID, INT (KEY) Name, NVARCHAR BunkID, INT



There is a foreign key relationship for the link between Campers.BunkID & Bunks.BunkID

I made a WPF Window that consists of a ListBox of all the customers and a UserControl that displays the details of the customer selected in the ListBox . The UserControl consists of a TextBlock for the CamperID , TextBox for the Name of the camper and ComboBox for the Bunk of the camper.

Now the hard part... I have two questions:

What is the best method to bind the list of all the Campers to the ListBox ? What is the best way to bind the list of all the Bunks to the ComboBox in the UserControl ? I cannot figure out how to bind the ComboBox correctly such that it displays the Bunk for each Camper and can be updated by changing the value.

Currently I am doing both in the code behind in C# but with the strength of WPF, I can't imagine that a simpler and better solution does not exist...

Thanks in advance!

- Mike

Mike Kamioner

I was trying to Insert and get image from db[SQL SERVER 2005] using ADO.net Entiy Framework, I'm facing exception : Media link entry.
How to implement IServiceProvider.

I've check with http://msdn.microsoft.com/en-us/library/ee960144.aspx 

The main problem What i'm facing is how to implement IServiceProvider and how to set Media  link entry

Please give me a relative smaple with source code in [.net 3.5] awaiting for response..  

I'm trying to install ADO.Net Data Services v1.5 CTP2 onto a SharePoint 2010 Beta 2 machine. It keeps telling me 'access to path denied'.

Any idea what might be causing this?


can we use transaction option and ADO.Net transaction in the same serviced component? like for example can this work

<transaction(transactionop.requiresnew)> _ ---SERVICED COMPONENT's OWN TRANSACTION

Public Class ABC

public function XYZ() as boolean

trans=connection.begintransaction  --- ADO.NET TRANSACTION







end try

End Class

i think if i dont use Centextutil.SetAbort or ContextUtil.SetComplete or define my transactionscope as <AutoComplete()> function XYZ will not behave properly..  the two transactions of ADO.net and TransactionScope will overlap and the net result will be an error or some data loss..????

am i rite???


Any detailed guidance will be very much helpful here...



My case:

I am loading al lot of data from a server to a local PC. Then i crate a disconnected table localy and move data from the server to the local PC.

Then to update the userinterface (Wondows forms datagridview) i think i will use Linq ti move from this local tabel to the datagridview.

 On server there is 1000 000 rows in first tabel(source), to the user i have 30 000 rows each time the user loads forms and greate a smaler local  table.

That is once a day. But each time the user move to next row in datatabel there is 12 rows from my local table who is printed into the a new datagriview.

My Question.

How do i connect Linc to my ado table ?

Thank you.

Best regards

BLIS :-)






As the title says, my local database does not reflect the changes made by my  application. The syntax for inserting the values being:

  connectione.ConnectionString = GETCON();
            nameL = textBox1.Text;
            passL = textBox2.Text;
            authL = Authlist.SelectedItem.ToString();
            if (nameL.Length > 4 && nameL.Length < 10 && passL.Length > 4 && passL.Length < 10 && authL != null)
                    //insertin= connectione.BeginTransaction();
                    CheckAuth = "Select * from LoginEnterprise";
                    SqlCommand CheckCommand2 = new SqlCommand();
                    CheckCommand2.Connection = connectione;
                    CheckCommand2.CommandType = CommandType.Text;
                    CheckCommand2.CommandText = CheckAuth;
                    da.SelectCommand = CheckCommand2;
                    da.TableMappings.Add("Table", "LoginEnterprise");
                    CheckAuth = "INSERT INTO LoginEnterprise (Username, Password, Authority) Values(@nami, @passi, @authi)";
                    CheckCommand2.CommandType = CommandType.Text;
                    CheckCommand2.CommandText = CheckAuth;

                    CheckCommand2.Parameters.AddWithValue("@nami", nameL);
                    CheckCommand2.Parameters.AddWithValue("@passi", passL);
                    CheckCommand2.Parameters.AddWithValue("@authi", passL);
                    label1.Text = "activated";
                    da.InsertCommand = CheckCommand2;
                    da.UpdateBatchSize = 4;
                    da.Update(DS, "Table");

                    this.button1.Text = "Login";

                    buttonfunc = 1;
                catch (Exception ex)



i am able to filter results just fine however, adding with the above code, doesnt modify the original database....
i have tried several things, including mapping "Table" to "LoginEnterprise", to no avail.

does this issue, have some relation with my database being a local one?


I need to keep a record of who accesses a database and I wondered if there was a way of auditing who accesses a database from within the Entity model.


I realise I can put something like


Into the top of each Stored Procedure, but then that would not catch those who go in via tables and views and would be a royal PITA to put at the top of every single stored procedure with a good sized system.

Thanks in advance


I have the following Stored Procedure: 

CREATE PROCEDURE [dbo].[GetEmployeesByCity] 

    @City NVARCHAR(15)


    SELECT *
    FROM Employees
    WHERE City = @City


I have imported this into an Entity Model, done by Function import and have the following Data Service

namespace NorthWindDB
    public class NorthwindDS : DataService<NorthwindEntities>
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(IDataServiceConfiguration config)
            config.SetEntitySetAccessRule("*", EntitySetRights.All);
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);

        public ObjectResult<Employees> GetEmployeesByCity(string cityName)
            NorthwindEntities entities = new NorthwindEntities();
            return entities.GetEmployeesByCity(cityName);


Now if I make the following URL 

I get data back.

The question is

1. How do I call this from a Silverlight Application

For example my code for retrieving from a table is as follows;

            DataGrid myGrid = (DataGrid)this.ListWindow.Children[0];
            svc = new NorthwindEntities(new Uri("http://localhost:4143/NorthwindDS.svc", UriKind.RelativeOrAbsolute));


                myGrid.SelectionChanged += new SelectionChangedEventHandler(myGrid_SelectionChanged);
                var q = (from c in svc.Customers
                         select c) as DataServiceQuery<Customer>;

                    (ar) => myGrid.ItemsSource = q.EndExecute(ar).ToList(),

            catch (Exception ex)
                throw ex;

2. How do I can this from a windows client

Thanks in advance 


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure