• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1908
  • Last Modified:

Change connectiontimeout in ADO.NET

Hi experts!

I have project with C#  , WindowsForms and Framework 2.0 with VS2008. I open connection to SQL Server 2005 and want to set different (smaller ) ConnectionTimeout . This property is read only, do I have other properties or way to chage it?  It is very borrow to wait 30 sec. In LAN connection&
1 Solution
Gyanendra SinghArchitectCommented:
use this

mycon.CommandTimeout = ... set your time here

mycon is connection object
The connection string http://www.connectionstrings.com/?carrier=sqlserver2005 has an optional property for "Connection Timeout" http://articles.techrepublic.com.com/5100-10878_11-6084879.html# which you would set as in the example below (the actual connection string will depend on your type of connection).

CommandTimeout http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx is different than ConnectionTimeout http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx
Provider=SQLNCLI;Server=myServerAddress;Database=myDataBase;Uid=myUsername; Pwd=myPassword;Connection Timeout=10;

Open in new window

dvplayltdAuthor Commented:
Thank you very much for you time!I get answer to other me question - how to change connection port for SQL Server ( I will work with SQL Server with realIP via Internet).

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now