1查看sqlserver服务是否开启,重启sqlserver服务尝试;
2查看防火墙设置,--》防火墙关闭;
3看到文章最后介绍可能是tcp/ip的问题,在tcp/ip属性中设置ip为已启用。
重启sqlserver服务,ok!数据库连接上了。
你了解TCP/IP socket编程相关知识吗?
网页链接
首先你要在云服务器上运行一个服务器程序,然后在本机运行客户端程序,两者通过TCP协议通讯交换数据(即你所说的连上云服务器)。
最简单的服务器程序:
using System;using SystemIO;
using SystemNet;
using SystemNetSockets;
using SystemText;
class MyTcpListener
{
public static void Main()
{
TcpListener server=null;
try
{
// Set the TcpListener on port 13000
Int32 port = 13000;
IPAddress localAddr = IPAddressParse("127001");
// TcpListener server = new TcpListener(port);
server = new TcpListener(localAddr, port);
// Start listening for client requests
serverStart();
// Buffer for reading data
Byte[] bytes = new Byte[256];
String data = null;
// Enter the listening loop
while(true)
{
ConsoleWrite("Waiting for a connection ");
// Perform a blocking call to accept requests
// You could also user serverAcceptSocket() here
TcpClient client = serverAcceptTcpClient();
ConsoleWriteLine("Connected!");
data = null;
// Get a stream object for reading and writing
NetworkStream stream = clientGetStream();
int i;
// Loop to receive all the data sent by the client
while((i = streamRead(bytes, 0, bytesLength))!=0)
{
// Translate data bytes to a ASCII string
data = SystemTextEncodingASCIIGetString(bytes, 0, i);
ConsoleWriteLine("Received: {0}", data);
// Process the data sent by the client
data = dataToUpper();
byte[] msg = SystemTextEncodingASCIIGetBytes(data);
// Send back a response
streamWrite(msg, 0, msgLength);
ConsoleWriteLine("Sent: {0}", data);
}
// Shutdown and end connection
clientClose();
}
}
catch(SocketException e)
{
ConsoleWriteLine("SocketException: {0}", e);
}
finally
{
// Stop listening for new clients
serverStop();
}
ConsoleWriteLine("\nHit enter to continue");
ConsoleRead();
}
}
最简单的客户端:
{
try
{
// 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 = SystemTextEncodingASCIIGetBytes(message);
// Get a client stream for reading and writing
// Stream stream = clientGetStream();
NetworkStream stream = clientGetStream();
// Send the message to the connected TcpServer
streamWrite(data, 0, dataLength);
ConsoleWriteLine("Sent: {0}", message);
// Receive the TcpServerresponse
// Buffer to store the response bytes
data = new Byte[256];
// String to store the response ASCII representation
String responseData = StringEmpty;
// Read the first batch of the TcpServer response bytes
Int32 bytes = streamRead(data, 0, dataLength);
responseData = SystemTextEncodingASCIIGetString(data, 0, bytes);
ConsoleWriteLine("Received: {0}", responseData);
// Close everything
streamClose();
clientClose();
}
catch (ArgumentNullException e)
{
ConsoleWriteLine("ArgumentNullException: {0}", e);
}
catch (SocketException e)
{
ConsoleWriteLine("SocketException: {0}", e);
}
ConsoleWriteLine("\n Press Enter to continue");
ConsoleRead();
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)