本文整理汇总了C#中System.Data.SqlClient.TdsParserStateObject.TryPeekByte方法的典型用法代码示例。如果您正苦于以下问题:C# TdsParserStateObject.TryPeekByte方法的具体用法?C# TdsParserStateObject.TryPeekByte怎么用?C# TdsParserStateObject.TryPeekByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.TdsParserStateObject
的用法示例。
在下文中一共展示了TdsParserStateObject.TryPeekByte方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryProcessError
internal bool TryProcessError(byte token, TdsParserStateObject stateObj, out SqlError error)
{
ushort shortLen;
byte byteLen;
int number;
byte state;
byte errorClass;
error = null;
if (!stateObj.TryReadInt32(out number))
{
return false;
}
if (!stateObj.TryReadByte(out state))
{
return false;
}
if (!stateObj.TryReadByte(out errorClass))
{
return false;
}
Debug.Assert(((errorClass >= TdsEnums.MIN_ERROR_CLASS) && token == TdsEnums.SQLERROR) ||
((errorClass < TdsEnums.MIN_ERROR_CLASS) && token == TdsEnums.SQLINFO), "class and token don't match!");
if (!stateObj.TryReadUInt16(out shortLen))
{
return false;
}
string message;
if (!stateObj.TryReadString(shortLen, out message))
{
return false;
}
if (!stateObj.TryReadByte(out byteLen))
{
return false;
}
string server;
// If the server field is not received use the locally cached value.
if (byteLen == 0)
{
server = _server;
}
else
{
if (!stateObj.TryReadString(byteLen, out server))
{
return false;
}
}
if (!stateObj.TryReadByte(out byteLen))
{
return false;
}
string procedure;
if (!stateObj.TryReadString(byteLen, out procedure))
{
return false;
}
int line;
if (_isYukon)
{
if (!stateObj.TryReadInt32(out line))
{
return false;
}
}
else
{
ushort shortLine;
if (!stateObj.TryReadUInt16(out shortLine))
{
return false;
}
line = shortLine;
// If we haven't yet completed processing login token stream yet, we may be talking to a Yukon server
// In that case we still have to read another 2 bytes
if (_state == TdsParserState.OpenNotLoggedIn)
{
// Login incomplete
byte b;
if (!stateObj.TryPeekByte(out b))
{
return false;
}
if (b == 0)
{
// This is an invalid token value
ushort value;
if (!stateObj.TryReadUInt16(out value))
{
return false;
}
//.........这里部分代码省略.........
示例2: TryRun
//.........这里部分代码省略.........
break;
}
case TdsEnums.SQLORDER:
{
// don't do anything with the order token so read off the pipe
if (!stateObj.TrySkipBytes(tokenLength))
{
return false;
}
break;
}
case TdsEnums.SQLALTMETADATA:
{
stateObj.CloneCleanupAltMetaDataSetArray();
if (stateObj._cleanupAltMetaDataSetArray == null)
{
// create object on demand (lazy creation)
stateObj._cleanupAltMetaDataSetArray = new _SqlMetaDataSetCollection();
}
_SqlMetaDataSet cleanupAltMetaDataSet;
if (!TryProcessAltMetaData(tokenLength, stateObj, out cleanupAltMetaDataSet))
{
return false;
}
stateObj._cleanupAltMetaDataSetArray.SetAltMetaData(cleanupAltMetaDataSet);
if (null != dataStream)
{
byte metadataConsumedByte;
if (!stateObj.TryPeekByte(out metadataConsumedByte))
{
return false;
}
if (!dataStream.TrySetAltMetaDataSet(cleanupAltMetaDataSet, (TdsEnums.SQLALTMETADATA != metadataConsumedByte)))
{
return false;
}
}
break;
}
case TdsEnums.SQLALTROW:
{
if (!stateObj.TryStartNewRow(isNullCompressed: false))
{ // altrows are not currently null compressed
return false;
}
// read will call run until dataReady. Must not read any data if returnimmetiately set
if (RunBehavior.ReturnImmediately != (RunBehavior.ReturnImmediately & runBehavior))
{
ushort altRowId;
if (!stateObj.TryReadUInt16(out altRowId))
{ // get altRowId
return false;
}
if (!TrySkipRow(stateObj._cleanupAltMetaDataSetArray.GetAltMetaData(altRowId), stateObj))
{ // skip altRow
return false;
}
示例3: TryProcessDone
private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavior run, TdsParserStateObject stateObj) {
ushort curCmd;
ushort status;
int count;
// Can't retry TryProcessDone
stateObj._syncOverAsync = true;
// status
// command
// rowcount (valid only if DONE_COUNT bit is set)
if (!stateObj.TryReadUInt16(out status)) {
return false;
}
if (!stateObj.TryReadUInt16(out curCmd)) {
return false;
}
if (_isYukon) {
long longCount;
if (!stateObj.TryReadInt64(out longCount)) {
return false;
}
count = (int) longCount;
}
else {
if (!stateObj.TryReadInt32(out count)) {
return false;
}
// If we haven't yet completed processing login token stream yet, we may be talking to a Yukon server
// In that case we still have to read another 4 bytes
// But don't try to read beyond the TDS stream in this case, because it generates errors if login failed.
if ( _state == TdsParserState.OpenNotLoggedIn) {
// Login incomplete, if we are reading from Yukon we need to read another int
if (stateObj._inBytesRead > stateObj._inBytesUsed) {
byte b;
if (!stateObj.TryPeekByte(out b)) {
return false;
}
if (b == 0) {
// This is an invalid token value
if (!stateObj.TryReadInt32(out count)) {
return false;
}
}
}
}
}
// We get a done token with the attention bit set
if (TdsEnums.DONE_ATTN == (status & TdsEnums.DONE_ATTN)) {
Debug.Assert(TdsEnums.DONE_MORE != (status & TdsEnums.DONE_MORE),"Not expecting DONE_MORE when receiving DONE_ATTN");
Debug.Assert(stateObj._attentionSent, "Received attention done without sending one!");
stateObj._attentionReceived = true;
Debug.Assert(stateObj._inBytesUsed == stateObj._inBytesRead && stateObj._inBytesPacket == 0, "DONE_ATTN received with more data left on wire");
}
if ((null != cmd) && (TdsEnums.DONE_COUNT == (status & TdsEnums.DONE_COUNT))) {
if (curCmd != TdsEnums.SELECT) {
if (cmd.IsDescribeParameterEncryptionRPCCurrentlyInProgress) {
// The below line is used only for debug asserts and not exposed publicly or impacts functionality otherwise.
cmd.RowsAffectedByDescribeParameterEncryption = count;
}
else {
cmd.InternalRecordsAffected = count;
}
}
// Skip the bogus DONE counts sent by the server
if (stateObj._receivedColMetaData || (curCmd != TdsEnums.SELECT)) {
cmd.OnStatementCompleted(count);
}
}
stateObj._receivedColMetaData = false;
// Surface exception for DONE_ERROR in the case we did not receive an error token
// in the stream, but an error occurred. In these cases, we throw a general server error. The
// situations where this can occur are: an invalid buffer received from client, login error
// and the server refused our connection, and the case where we are trying to log in but
// the server has reached its max connection limit. Bottom line, we need to throw general
// error in the cases where we did not receive a error token along with the DONE_ERROR.
if ((TdsEnums.DONE_ERROR == (TdsEnums.DONE_ERROR & status)) && stateObj.ErrorCount == 0 &&
stateObj._errorTokenReceived == false && (RunBehavior.Clean != (RunBehavior.Clean & run))) {
stateObj.AddError(new SqlError(0, 0, TdsEnums.MIN_ERROR_CLASS, _server, SQLMessage.SevereError(), "", 0));
if (null != reader) { // SQL BU DT 269516
if (!reader.IsInitialized) {
run = RunBehavior.UntilDone;
}
}
}
// Similar to above, only with a more severe error. In this case, if we received
// the done_srverror, this exception will be added to the collection regardless.
// MDAC #93896. Also, per Ashwin, the server will always break the connection in this case.
if ((TdsEnums.DONE_SRVERROR == (TdsEnums.DONE_SRVERROR & status)) && (RunBehavior.Clean != (RunBehavior.Clean & run))) {
stateObj.AddError(new SqlError(0, 0, TdsEnums.FATAL_ERROR_CLASS, _server, SQLMessage.SevereError(), "", 0));
if (null != reader) { // SQL BU DT 269516
if (!reader.IsInitialized) {
//.........这里部分代码省略.........