int number = comm.GetTdsInt ();
byte state = comm.GetByte ();
byte theClass = comm.GetByte ();
- string message = comm.GetString (comm.GetTdsShort ());
-
-
- string server = comm.GetString (comm.GetByte ());
-
- if (subType != TdsPacketSubType.Info && subType != TdsPacketSubType.Error)
- return;
-
- string procedure = comm.GetString (comm.GetByte ());
- byte lineNumber = comm.GetByte ();
- string source = String.Empty; // FIXME
+ string message;
+ string server;
+ string procedure;
+ byte lineNumber;
+ string source;
+ bool isError = false;
+
+ if (subType == TdsPacketSubType.EED) {
+ isError = (theClass <= 10);
+ comm.Skip (comm.GetByte ()); // SQL State
+ comm.Skip (1); // Status
+ comm.Skip (2); // TranState
+ } else
+ isError = (subType == TdsPacketSubType.Error);
+
+ message = comm.GetString (comm.GetTdsShort ());
+ server = comm.GetString (comm.GetByte ());
+ procedure = comm.GetString (comm.GetByte ());
+ lineNumber = comm.GetByte ();
+ source = String.Empty; // FIXME
+
+ if (subType != TdsPacketSubType.EED)
+ comm.Skip (1);
- comm.GetByte ();
- if (subType == TdsPacketSubType.Error)
- OnTdsErrorMessage (CreateTdsErrorMessageEvent (theClass, lineNumber, message, number, procedure, server, source, state));
- else
+ if (isError)
messages.Add (new TdsInternalError (theClass, lineNumber, message, number, procedure, server, source, state));
+ else
+ OnTdsErrorMessage (CreateTdsErrorMessageEvent (theClass, lineNumber, message, number, procedure, server, source, state));
}
private TdsPacketOutputParam ProcessOutputParam ()
result = ProcessEnvChange ();
break;
case TdsPacketSubType.Info :
- case TdsPacketSubType.Msg50Token :
+ case TdsPacketSubType.EED:
case TdsPacketSubType.Error :
ProcessMessage (subType);
break;
#region Constructors
public Tds50 (string server, int port)
- : this (server, port, 512, 15)
+ : this (server, port, 8192, 15)
{
}
if (IsConnected)
throw new InvalidOperationException ("The connection is already open.");
+ // some voodoo magic here.
+ byte[] capabilities = {0x01,0x07,0x03,109,127,0xFF,0xFF,0xFF,0xFE,0x02,0x07,0x00,0x00,0x0A,104,0x00,0x00,0x00};
+
SetCharset (connectionParameters.Charset);
SetLanguage (connectionParameters.Language);
Comm.StartPacket (TdsPacketType.Logon);
// hostname (offset 0)
+ // 0-30
byte[] tmp = Comm.Append (connectionParameters.Hostname, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// username (offset 31 0x1f)
+ // 31-61
tmp = Comm.Append (connectionParameters.User, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// password (offset 62 0x3e)
+ // 62-92
tmp = Comm.Append (connectionParameters.Password, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// hostproc (offset 93 0x5d)
- Comm.Append ("00000116", 8, pad);
-
- // unused (offset 109 0x6d)
- Comm.Append (empty, (30-14), pad);
-
- // apptype
- Comm.Append ((byte) 0x0);
- Comm.Append ((byte) 0xa0);
- Comm.Append ((byte) 0x24);
- Comm.Append ((byte) 0xcc);
- Comm.Append ((byte) 0x50);
- Comm.Append ((byte) 0x12);
-
- // hostproc length
- Comm.Append ((byte) 8);
+ // 93-123
+ tmp = Comm.Append ("37876", 30, pad);
+ Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// Byte order of 2 byte ints
// 2 = <MSB, LSB>, 3 = <LSB, MSB>
+ // 124
Comm.Append ((byte) 3);
// Byte order of 4 byte ints
// 0 = <MSB, LSB>, 1 = <LSB, MSB>
+ // 125
Comm.Append ((byte) 1);
// Character representation
// (6 = ASCII, 7 = EBCDIC)
+ // 126
Comm.Append ((byte) 6);
// Eight byte floating point representation
// 5 = VAX 'D'
// 10 = IEEE <LSB, ..., MSB>
// 11 = ND5000
+ // 127
Comm.Append ((byte) 10);
// Eight byte date format
// 8 = <MSB, ..., LSB>
+ // 128
Comm.Append ((byte) 9);
// notify of use db
+ // 129
Comm.Append ((byte) 1);
// disallow dump/load and bulk insert
+ // 130
Comm.Append ((byte) 1);
// sql interface type
+ // 131
Comm.Append ((byte) 0);
// type of network connection
+ // 132
Comm.Append ((byte) 0);
-
// spare [7]
+ // 133-139
Comm.Append (empty, 7, pad);
+
// appname
+ // 140-170
tmp = Comm.Append (connectionParameters.ApplicationName, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// server name
+ // 171-201
tmp = Comm.Append (DataSource, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// remote passwords
+ // 202-457
Comm.Append (empty, 2, pad);
tmp = Comm.Append (connectionParameters.Password, 253, pad);
Comm.Append ((byte) (tmp.Length < 253 ? tmp.Length + 2 : 253 + 2));
// tds version
- Comm.Append ((byte) (((byte) Version) / 10));
- Comm.Append ((byte) (((byte) Version) % 10));
+ // 458-461
+ Comm.Append ((byte) 5);
+ Comm.Append ((byte) 0);
Comm.Append ((byte) 0);
Comm.Append ((byte) 0);
// prog name
+ // 462-472
tmp = Comm.Append (connectionParameters.ProgName, 10, pad);
Comm.Append ((byte) (tmp.Length < 10 ? tmp.Length : 10));
// prog version
+ // 473-476
Comm.Append ((byte) 6);
-
- // Tell the server we can handle SQLServer version 6
Comm.Append ((byte) 0);
-
- // Send zero to tell the server we can't handle any other version
Comm.Append ((byte) 0);
Comm.Append ((byte) 0);
// auto convert short
+ // 477
Comm.Append ((byte) 0);
// type of flt4
+ // 478
Comm.Append ((byte) 0x0d);
// type of date4
+ // 479
Comm.Append ((byte) 0x11);
// language
+ // 480-510
tmp = Comm.Append (Language, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// notify on lang change
+ // 511
Comm.Append ((byte) 1);
// security label hierarchy
+ // 512-513
Comm.Append ((short) 0);
// security components
+ // 514-521
Comm.Append (empty, 8, pad);
// security spare
+ // 522-523
Comm.Append ((short) 0);
// security login role
+ // 524
Comm.Append ((byte) 0);
// charset
+ // 525-555
tmp = Comm.Append (Charset, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// notify on charset change
+ // 556
Comm.Append ((byte) 1);
// length of tds packets
+ // 557-563
tmp = Comm.Append (PacketSize.ToString (), 6, pad);
- Comm.Append ((byte) 3);
+ Comm.Append ((byte) (tmp.Length < 6 ? tmp.Length : 6));
- // pad out to a longword
Comm.Append (empty, 8, pad);
+ // Padding...
+ // 564-567
+ //Comm.Append (empty, 4, pad);
+
+ // Capabilities
+ //Comm.Append ((byte) TdsPacketType.Capability);
+ //Comm.Append ((short) 18);
+ //Comm.Append (capabilities, 18, pad);
Comm.SendPacket ();
- TdsPacketResult result;
bool done = false;
while (!done) {
- result = ProcessSubPacket ();
+ TdsPacketResult result = ProcessSubPacket ();
done = (result is TdsPacketEndTokenResult);
}
return IsConnected;
Append ((byte) (((byte) (l >> 8)) & 0xff));
Append ((byte) (((byte) (l >> 0)) & 0xff));
}
- else {
+ else
Append (BitConverter.GetBytes (l));
- }
}
private void ConnectCallback (IAsyncResult ar)
EnvChange = 0xe3,
Error = 0xaa,
Info = 0xab,
- Msg50Token = 0xe5,
+ EED = 0xe5,
Param = 0xac,
LoginAck = 0xad,
ReturnStatus = 0x79,
Reply = 0x4,
Cancel = 0x6,
Logon70 = 0x10,
- Logoff = 0x71
+ Logoff = 0x71,
+ Capability = 0xe2
}
}
+2002-11-18 Tim Coleman <tim@timcoleman.com>
+ * Mono.Data.TdsClient.Internal/Tds.cs:
+ * Mono.Data.TdsClient.Internal/Tds50.cs:
+ * Mono.Data.TdsClient.Internal/TdsComm.cs:
+ * Mono.Data.TdsClient.Internal/TdsPacketSubType.cs:
+ * Mono.Data.TdsClient.Internal/TdsPacketType.cs:
+ Sybase compatibility fixes.
+
2002-11-15 Tim Coleman <tim@timcoleman.com>
* Mono.Data.TdsClient.Internal/Tds.cs:
Add support for UniqueIdentifier (GUID),
int number = comm.GetTdsInt ();
byte state = comm.GetByte ();
byte theClass = comm.GetByte ();
- string message = comm.GetString (comm.GetTdsShort ());
-
-
- string server = comm.GetString (comm.GetByte ());
-
- if (subType != TdsPacketSubType.Info && subType != TdsPacketSubType.Error)
- return;
-
- string procedure = comm.GetString (comm.GetByte ());
- byte lineNumber = comm.GetByte ();
- string source = String.Empty; // FIXME
+ string message;
+ string server;
+ string procedure;
+ byte lineNumber;
+ string source;
+ bool isError = false;
+
+ if (subType == TdsPacketSubType.EED) {
+ isError = (theClass <= 10);
+ comm.Skip (comm.GetByte ()); // SQL State
+ comm.Skip (1); // Status
+ comm.Skip (2); // TranState
+ } else
+ isError = (subType == TdsPacketSubType.Error);
+
+ message = comm.GetString (comm.GetTdsShort ());
+ server = comm.GetString (comm.GetByte ());
+ procedure = comm.GetString (comm.GetByte ());
+ lineNumber = comm.GetByte ();
+ source = String.Empty; // FIXME
+
+ if (subType != TdsPacketSubType.EED)
+ comm.Skip (1);
- comm.GetByte ();
- if (subType == TdsPacketSubType.Error)
- OnTdsErrorMessage (CreateTdsErrorMessageEvent (theClass, lineNumber, message, number, procedure, server, source, state));
- else
+ if (isError)
messages.Add (new TdsInternalError (theClass, lineNumber, message, number, procedure, server, source, state));
+ else
+ OnTdsErrorMessage (CreateTdsErrorMessageEvent (theClass, lineNumber, message, number, procedure, server, source, state));
}
private TdsPacketOutputParam ProcessOutputParam ()
result = ProcessEnvChange ();
break;
case TdsPacketSubType.Info :
- case TdsPacketSubType.Msg50Token :
+ case TdsPacketSubType.EED:
case TdsPacketSubType.Error :
ProcessMessage (subType);
break;
#region Constructors
public Tds50 (string server, int port)
- : this (server, port, 512, 15)
+ : this (server, port, 8192, 15)
{
}
if (IsConnected)
throw new InvalidOperationException ("The connection is already open.");
+ // some voodoo magic here.
+ byte[] capabilities = {0x01,0x07,0x03,109,127,0xFF,0xFF,0xFF,0xFE,0x02,0x07,0x00,0x00,0x0A,104,0x00,0x00,0x00};
+
SetCharset (connectionParameters.Charset);
SetLanguage (connectionParameters.Language);
Comm.StartPacket (TdsPacketType.Logon);
// hostname (offset 0)
+ // 0-30
byte[] tmp = Comm.Append (connectionParameters.Hostname, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// username (offset 31 0x1f)
+ // 31-61
tmp = Comm.Append (connectionParameters.User, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// password (offset 62 0x3e)
+ // 62-92
tmp = Comm.Append (connectionParameters.Password, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// hostproc (offset 93 0x5d)
- Comm.Append ("00000116", 8, pad);
-
- // unused (offset 109 0x6d)
- Comm.Append (empty, (30-14), pad);
-
- // apptype
- Comm.Append ((byte) 0x0);
- Comm.Append ((byte) 0xa0);
- Comm.Append ((byte) 0x24);
- Comm.Append ((byte) 0xcc);
- Comm.Append ((byte) 0x50);
- Comm.Append ((byte) 0x12);
-
- // hostproc length
- Comm.Append ((byte) 8);
+ // 93-123
+ tmp = Comm.Append ("37876", 30, pad);
+ Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// Byte order of 2 byte ints
// 2 = <MSB, LSB>, 3 = <LSB, MSB>
+ // 124
Comm.Append ((byte) 3);
// Byte order of 4 byte ints
// 0 = <MSB, LSB>, 1 = <LSB, MSB>
+ // 125
Comm.Append ((byte) 1);
// Character representation
// (6 = ASCII, 7 = EBCDIC)
+ // 126
Comm.Append ((byte) 6);
// Eight byte floating point representation
// 5 = VAX 'D'
// 10 = IEEE <LSB, ..., MSB>
// 11 = ND5000
+ // 127
Comm.Append ((byte) 10);
// Eight byte date format
// 8 = <MSB, ..., LSB>
+ // 128
Comm.Append ((byte) 9);
// notify of use db
+ // 129
Comm.Append ((byte) 1);
// disallow dump/load and bulk insert
+ // 130
Comm.Append ((byte) 1);
// sql interface type
+ // 131
Comm.Append ((byte) 0);
// type of network connection
+ // 132
Comm.Append ((byte) 0);
-
// spare [7]
+ // 133-139
Comm.Append (empty, 7, pad);
+
// appname
+ // 140-170
tmp = Comm.Append (connectionParameters.ApplicationName, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// server name
+ // 171-201
tmp = Comm.Append (DataSource, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// remote passwords
+ // 202-457
Comm.Append (empty, 2, pad);
tmp = Comm.Append (connectionParameters.Password, 253, pad);
Comm.Append ((byte) (tmp.Length < 253 ? tmp.Length + 2 : 253 + 2));
// tds version
- Comm.Append ((byte) (((byte) Version) / 10));
- Comm.Append ((byte) (((byte) Version) % 10));
+ // 458-461
+ Comm.Append ((byte) 5);
+ Comm.Append ((byte) 0);
Comm.Append ((byte) 0);
Comm.Append ((byte) 0);
// prog name
+ // 462-472
tmp = Comm.Append (connectionParameters.ProgName, 10, pad);
Comm.Append ((byte) (tmp.Length < 10 ? tmp.Length : 10));
// prog version
+ // 473-476
Comm.Append ((byte) 6);
-
- // Tell the server we can handle SQLServer version 6
Comm.Append ((byte) 0);
-
- // Send zero to tell the server we can't handle any other version
Comm.Append ((byte) 0);
Comm.Append ((byte) 0);
// auto convert short
+ // 477
Comm.Append ((byte) 0);
// type of flt4
+ // 478
Comm.Append ((byte) 0x0d);
// type of date4
+ // 479
Comm.Append ((byte) 0x11);
// language
+ // 480-510
tmp = Comm.Append (Language, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// notify on lang change
+ // 511
Comm.Append ((byte) 1);
// security label hierarchy
+ // 512-513
Comm.Append ((short) 0);
// security components
+ // 514-521
Comm.Append (empty, 8, pad);
// security spare
+ // 522-523
Comm.Append ((short) 0);
// security login role
+ // 524
Comm.Append ((byte) 0);
// charset
+ // 525-555
tmp = Comm.Append (Charset, 30, pad);
Comm.Append ((byte) (tmp.Length < 30 ? tmp.Length : 30));
// notify on charset change
+ // 556
Comm.Append ((byte) 1);
// length of tds packets
+ // 557-563
tmp = Comm.Append (PacketSize.ToString (), 6, pad);
- Comm.Append ((byte) 3);
+ Comm.Append ((byte) (tmp.Length < 6 ? tmp.Length : 6));
- // pad out to a longword
Comm.Append (empty, 8, pad);
+ // Padding...
+ // 564-567
+ //Comm.Append (empty, 4, pad);
+
+ // Capabilities
+ //Comm.Append ((byte) TdsPacketType.Capability);
+ //Comm.Append ((short) 18);
+ //Comm.Append (capabilities, 18, pad);
Comm.SendPacket ();
- TdsPacketResult result;
bool done = false;
while (!done) {
- result = ProcessSubPacket ();
+ TdsPacketResult result = ProcessSubPacket ();
done = (result is TdsPacketEndTokenResult);
}
return IsConnected;
Append ((byte) (((byte) (l >> 8)) & 0xff));
Append ((byte) (((byte) (l >> 0)) & 0xff));
}
- else {
+ else
Append (BitConverter.GetBytes (l));
- }
}
private void ConnectCallback (IAsyncResult ar)
EnvChange = 0xe3,
Error = 0xaa,
Info = 0xab,
- Msg50Token = 0xe5,
+ EED = 0xe5,
Param = 0xac,
LoginAck = 0xad,
ReturnStatus = 0x79,
Reply = 0x4,
Cancel = 0x6,
Logon70 = 0x10,
- Logoff = 0x71
+ Logoff = 0x71,
+ Capability = 0xe2
}
}