SqlCommand有一个属性是
MyCommand.CommandTimeout=180;
MyCommand.CommandTimeout=180;
解决方案 »
- [求助啊求助]懂sql语句操作EXCEL的来帮帮忙
- C# DataGridView 动态添加行时的问题
- C#盲提问using System.EnterpriseServices;不存在?
- 本人有一个想法,不知是否可行,求教!!
- [求助]\"转义后怎么还是\"?
- SQL server 多线程问题:多线程同时使用SqlCommand访问数据库,应该怎样做?
- 帮帮我吧!
- 大神帮忙看下 画面logo问题
- 不明白为什么出错,关于用OLEDB连接ACCESS数据库,帮忙看看谢谢
- 在基于c/s结构的应用程序开发中,怎样保证数据的一致性
- e.Graphics.DrawString() 怎么实现让字符串显示在矩形中间?谢谢!
- 初学,如何从SQL SERVER当中把数据搞进来?
不过我用的方法是new tcpclient(host,port)方式,再捕捉错误,如果有错则说明端口未开放
所以不知道如何指定超时时间。
在服务端设断点调试。
{
// 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();
}
http://www.codeproject.com/cs/webservices/wsaltroute2.asp?print=true
对继承者的说明: 您可以使用通过 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 命名空间
try
{
ScaningPort++;
new TcpClient("127.0.0.1","79");
}
catch(Exception)
{;}
如果捕获到错误则说明端口未开放,否则为开放。
我想能够指定超时的时间,不知道能否做到。
------
984437(NewStar) 说的方法还没仔细看,稍候我试一下,谢谢。