Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
izaltsman
A custom title
1139 Posts |
Posted - 2002-01-03 : 12:45:52
|
| Hi all! Is there a way to force a client application to connect to SQL Server via TCP/IP (instead of Named Pipes) without having to install a Client Network Utility on the client machine (application connects via ADO)? |
|
|
KnooKie
Aged Yak Warrior
623 Posts |
Posted - 2002-01-03 : 12:58:55
|
| How about the Winsock control. Sounds like it may be apossibility.Here's the following from MSDN...Using the Winsock ControlA WinSock control allows you to connect to a remote machine and exchange data using either the User Datagram Protocol (UDP) or the Transmission Control Protocol (TCP). Both protocols can be used to create client and server applications. Like the Timer control, the WinSock control doesn't have a visible interface at run time.Possible UsesCreate a client application that collects user information before sending it to a central server.Create a server application that functions as a central collection point for data from several users.Create a "chat" application. Selecting a ProtocolWhen using the WinSock control, the first consideration is whether to use the TCP or the UDP protocol. The major difference between the two lies in their connection state: The TCP protocol control is a connection-based protocol, and is analogous to a telephone — the user must establish a connection before proceeding.The UDP protocol is a connectionless protocol, and the transaction between two computers is like passing a note: a message is sent from one computer to another, but there is no explicit connection between the two. Additionally, the maximum data size of individual sends is determined by the network. The nature of the application you are creating will generally determine which protocol you select. Here are a few questions that may help you select the appropriate protocol: Will the application require acknowledgment from the server or client when data is sent or received? If so, the TCP protocol requires an explicit connection before sending or receiving data.Will the data be extremely large (such as image or sound files)? Once a connection has been made, the TCP protocol maintains the connection and ensures the integrity of the data. This connection, however, uses more computing resources, making it more "expensive."Will the data be sent intermittently, or in one session? For example, if you are creating an application that notifies specific computers when certain tasks have completed, the UDP protocol may be more appropriate. The UDP protocol is also more suited for sending small amounts of data. Setting the ProtocolTo set the protocol that your application will use: at design-time, on the Properties window, click Protocol and select either sckTCPProtocol, or sckUDPProtocol. You can also set the Protocol property in code, as shown below:Winsock1.Protocol = sckTCPProtocolDetermining the Name of Your ComputerTo connect to a remote computer, you must know either its IP address or its "friendly name." The IP address is a series of three digit numbers separated by periods (xxx.xxx.xxx.xxx). In general, it's much easier to remember the friendly name of a computer. To find your computer's name On the Taskbar of your computer, click Start.On the Settings item, click the Control Panel.Double-click the Network icon.Click the Identification tab.The name of your computer will be found in the Computer name box. Once you have found your computer's name, it can be used as a value for the RemoteHost property.TCP Connection BasicsWhen creating an application that uses the TCP protocol, you must first decide if your application will be a server or a client. Creating a server means that your application will "listen," on a designated port. When the client makes a connection request, the server can then accept the request and thereby complete the connection. Once the connection is complete, the client and server can freely communicate with each other.The following steps create a rudimentary server:To create a TCP server Create a new Standard EXE project.Change the name of the default form to frmServer.Change the caption of the form to "TCP Server."Draw a Winsock control on the form and change its name to tcpServer.Add two TextBox controls to the form. Name the first txtSendData, and the second txtOutput.Add the code below to the form.Private Sub Form_Load()' Set the LocalPort property to an integer.' Then invoke the Listen method.tcpServer.LocalPort = 1001tcpServer.Listen frmClient.Show ' Show the client form.End SubPrivate Sub tcpServer_ConnectionRequest _(ByVal requestID As Long)' Check if the control's State is closed. If not, ' close the connection before accepting the new' connection.If tcpServer.State <> sckClosed Then _tcpServer.Close' Accept the request with the requestID ' parameter.tcpServer.Accept requestIDEnd SubPrivate Sub txtSendData_Change()' The TextBox control named txtSendData ' contains the data to be sent. Whenever the user ' types into the textbox, the string is sent ' using the SendData method.tcpServer.SendData txtSendData.TextEnd SubPrivate Sub tcpServer_DataArrival _(ByVal bytesTotal As Long)' Declare a variable for the incoming data. ' Invoke the GetData method and set the Text' property of a TextBox named txtOutput to ' the data.Dim strData As StringtcpServer.GetData strDatatxtOutput.Text = strDataEnd SubThe procedures above create a simple server application. However, to complete the scenario, you must also create a client application.To create a TCP client Add a new form to the project, and name it frmClient.Change the caption of the form to TCP Client.Add a Winsock control to the form and name it tcpClient.Add two TextBox controls to frmClient. Name the first txtSend, and the second txtOutput.Draw a CommandButton control on the form and name it cmdConnect.Change the caption of the CommandButton control to Connect.Add the code below to the form. Important Be sure to change the value of the RemoteHost property to the friendly name of your computer.Private Sub Form_Load()' The name of the Winsock control is tcpClient.' Note: to specify a remote host, you can use ' either the IP address (ex: "121.111.1.1") or' the computer's "friendly" name, as shown here.tcpClient.RemoteHost = "RemoteComputerName"tcpClient.RemotePort = 1001End SubPrivate Sub cmdConnect_Click()' Invoke the Connect method to initiate a ' connection.tcpClient.ConnectEnd SubPrivate Sub txtSendData_Change()tcpClient.SendData txtSend.TextEnd SubPrivate Sub tcpClient_DataArrival _(ByVal bytesTotal As Long)Dim strData As StringtcpClient.GetData strDatatxtOutput.Text = strDataEnd SubThe code above creates a simple client-server application. To try the two together, run the project, and click Connect. Then type text into the txtSendData TextBox on either form, and the same text will appear in the txtOutput TextBox on the other form. |
 |
|
|
izaltsman
A custom title
1139 Posts |
|
|
|
|
|
|
|