SqlCommand有一个属性是
MyCommand.CommandTimeout=180;

解决方案 »

  1.   

    Session[""]不是可以设置时间吗?我就是用的Session
      

  2.   

    session?怎么用?我没用过,请详诉。
      

  3.   

    tcpclient没有相应的连接超时的说法吗?
      

  4.   

    我看的tcpclient资料,有发送超时、接收超时,
    不过我用的方法是new tcpclient(host,port)方式,再捕捉错误,如果有错则说明端口未开放
    所以不知道如何指定超时时间。
      

  5.   

    服务端是否开始Accept?可以读到netStream?
    在服务端设断点调试。
      

  6.   

    可不可以使用socket的timeout?或者有一个笨办法,自己设置一个timer,然后当开始连接的时候,启动这个timer,如果到了你所设置的timeout,那个时候还没有获取host的反映,就认为是超时,这样就可以通过设置timer的上限为超时时间了(不推荐)static void Connect(String server, String message) 
    {
          // Create a TcpClient.
        // Note, for this client to work you need to have a TcpServer 
        // connected to the same address as specified by the server, port
        // combination.
        Int32 port = 13000;
        TcpClient client = new TcpClient(server, port);
        
        // Translate the passed message into ASCII and store it as a Byte array.
        Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);             // Get a client stream for reading and writing.
       //  Stream stream = client.GetStream();
        
        NetworkStream stream = client.GetStream();    // Send the message to the connected TcpServer. 
        stream.Write(data, 0, data.Length);    Console.WriteLine("Sent: {0}", message);             // Receive the TcpServer.response.
        
        // Buffer to store the response bytes.
        data = new Byte[256];    // String to store the response ASCII representation.
        String responseData = String.Empty;    // Read the first batch of the TcpServer response bytes.
        Int32 bytes = stream.Read(data, 0, data.Length);
        responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
        Console.WriteLine("Received: {0}", responseData);             // Close everything.
        client.Close();         
      } 
        
      

  7.   

    看看这个帖子,对你应该有帮助,采用其它的构造方法应该也是可以的
    http://www.codeproject.com/cs/webservices/wsaltroute2.asp?print=true
      

  8.   

    不行啊,TcpClient有两个超时属性,SendTimeout和ReceiveTimeout,但对于连接超时没有找到相关属性,怎么办呢?
      

  9.   

    TcpClient:
    对继承者的说明:  您可以使用通过 Client 访问的 Socket 来方便地利用在使用 TcpClient 属性的简化接口时不可用的任何功能。特别是,可以调用 SetSocketOption 来设置所需的选项。//Send operations will timeout of confirmation is not received within 1000 milliseconds.
    s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.SendTimeout, 1000);      //Socket will linger for 10 seconds after close is called.
          LingerOption lingerOption = new LingerOption(true, 10);
          s.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Linger, lingerOption);
       .NET 框架类库   LingerOption 类  [C#]请参见
    LingerOption 成员 | System.Net.Sockets 命名空间 
    要求
    命名空间: System.Net.Sockets平台: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family程序集: System (在 System.dll 中)
    语言包含有关套接字逗留时间的信息。套接字逗留时间是指如果在套接字关闭后仍有数据要发送,套接字保持的时间量。有关此类型所有成员的列表,请参阅 LingerOption 成员。System.Object
       System.Net.Sockets.LingerOption[C#]
    public class LingerOption
    线程安全
    此类型的所有公共静态(Visual Basic 中为 Shared)成员对多线程操作而言都是安全的。但不保证任何实例成员是线程安全的。备注
    套接字逗留时间的时间长度受与 Socket 实例相关联的 LingerOption 实例的设置控制。如果 Enabled 为 false,调用 Close 方法将立即关闭与网络的连接。如果 Enabled 为 true,则数据将继续发送到网络上,但有 LingerTime 超时限制(以秒为单位)。发送完数据或超时过期时,网络连接会平稳关闭。如果发送队列中没有任何数据,套接字将立即关闭。当 Enabled 为 true 并且 LingerTime 为 0 时,调用 Close 会立即关闭套接字,所有未发送的数据都将丢失。示例
    [C#] 
    LingerOption myOpts = new LingerOption(true,1);mySocket.SetSocketOption(SocketOptionLevel.IP,SocketOptionName.Linger,myOpts);
    [C++, JScript] 没有可用于 C++ 或 JScript 的示例。若要查看 Visual Basic 或 C# 示例,请单击页左上角的语言筛选器按钮 。要求
    命名空间: System.Net.Sockets平台: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows .NET Server family程序集: System (在 System.dll 中)请参见
    LingerOption 成员 | System.Net.Sockets 命名空间 
      

  10.   

    to netdust (ND) 你所说的是网页操作超时、数据库连接超时还是想自定义的TCP超时??
      

  11.   

    比如我想做个端口扫描器,片断代码如下:
    try
    {
      ScaningPort++;
      new TcpClient("127.0.0.1","79");
    }
    catch(Exception)
    {;}
    如果捕获到错误则说明端口未开放,否则为开放。
    我想能够指定超时的时间,不知道能否做到。
    ------
    984437(NewStar) 说的方法还没仔细看,稍候我试一下,谢谢。
      

  12.   

    解决了没有,我也想知道!socket好像也没有连接超时控制吧!