using System.Data.SqlClient; using System.IO; // establish a connection to the SQL Server database string connectionString = "Server=myServerAddress;Database=myDatabase;User Id=myUsername;Password=myPassword;"; SqlConnection connection = new SqlConnection(connectionString); connection.Open(); // create a TDS packet using MemoryStream MemoryStream stream = new MemoryStream(); stream.WriteByte(0x01); // write a single byte to the stream // send the TDS packet to the SQL Server using TdsParserStateObject byte[] buffer = stream.ToArray(); TdsParserStateObject stateObj = connection.GetOpenTdsStream().Parser._physicalStateObj; stateObj.Write(buffer, 0, buffer.Length); // close the connection connection.Close();
using System.Data.SqlClient; // establish a connection to the SQL Server database string connectionString = "Server=myServerAddress;Database=myDatabase;User Id=myUsername;Password=myPassword;"; SqlConnection connection = new SqlConnection(connectionString); connection.Open(); // create a TDS packet using byte array byte[] buffer = new byte[10] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A}; // send the TDS packet to the SQL Server using TdsParserStateObject TdsParserStateObject stateObj = connection.GetOpenTdsStream().Parser._physicalStateObj; stateObj.Write(buffer, 0, buffer.Length); // close the connection connection.Close();This example establishes a connection to the SQL Server database, creates a byte array containing 10 values, sends the array to the server using TdsParserStateObject’s Write method, and then closes the connection. In conclusion, the System.Data.SqlClient package library provides the TdsParserStateObject class, which is used to manage the data reading and writing operations of the TDS protocol. The WriteByte method is used to send a single byte to the server over the network connection.