1 //------------------------------------------------------------------------------
2 // <copyright file="TdsEnums.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">Microsoft</owner>
6 // <owner current="true" primary="false">Microsoft</owner>
7 //------------------------------------------------------------------------------
9 namespace System.Data.SqlClient {
11 using System.Diagnostics;
13 /// <devdoc> Class of variables for the Tds connection.
15 internal static class TdsEnums {
17 // internal tdsparser constants
19 public const short SQL_SERVER_VERSION_SEVEN = 7;
21 public const string SQL_PROVIDER_NAME = Common.DbConnectionStringDefaults.ApplicationName;
23 public static readonly Decimal SQL_SMALL_MONEY_MIN = new Decimal(-214748.3648);
24 public static readonly Decimal SQL_SMALL_MONEY_MAX = new Decimal(214748.3647);
26 // sql debugging constants, sdci is the structure passed in
27 public const string SDCI_MAPFILENAME = "SqlClientSSDebug";
28 public const byte SDCI_MAX_MACHINENAME = 32;
29 public const byte SDCI_MAX_DLLNAME = 16;
30 public const byte SDCI_MAX_DATA = 255;
31 public const int SQLDEBUG_OFF = 0;
32 public const int SQLDEBUG_ON = 1;
33 public const int SQLDEBUG_CONTEXT = 2;
34 public const string SP_SDIDEBUG = "sp_sdidebug";
35 public static readonly string[] SQLDEBUG_MODE_NAMES = new string[3] {
42 // Constant for SqlDbType.SmallVarBinary... store internal variable here instead of on
43 // SqlDbType so that it is not surfaced to the user!!! Related to dtc and the fact that
44 // the TransactionManager TDS stream is the only token left that uses VarBinarys instead of
46 public const SqlDbType SmallVarBinary = (SqlDbType) (SqlDbType.Variant)+1;
48 // network protocol string constants
49 public const string TCP = "tcp";
50 public const string NP = "np";
51 public const string RPC = "rpc";
52 public const string BV = "bv";
53 public const string ADSP = "adsp";
54 public const string SPX = "spx";
55 public const string VIA = "via";
56 public const string LPC = "lpc";
58 // network function string contants
59 public const string INIT_SSPI_PACKAGE = "InitSSPIPackage";
60 public const string INIT_ADAL_PACKAGE = "InitADALPackage";
61 public const string INIT_SESSION = "InitSession";
62 public const string CONNECTION_GET_SVR_USER = "ConnectionGetSvrUser";
63 public const string GEN_CLIENT_CONTEXT = "GenClientContext";
65 // tdsparser packet handling constants
66 public const byte SOFTFLUSH = 0;
67 public const byte HARDFLUSH = 1;
68 public const byte IGNORE = 2;
71 public const int HEADER_LEN = 8;
72 public const int HEADER_LEN_FIELD_OFFSET = 2;
73 public const int YUKON_HEADER_LEN = 12; //Yukon headers also include a MARS session id
74 public const int MARS_ID_OFFSET = 8;
75 public const int HEADERTYPE_QNOTIFICATION = 1;
76 public const int HEADERTYPE_MARS = 2;
77 public const int HEADERTYPE_TRACE = 3;
79 // other various constants
80 public const int SUCCEED = 1;
81 public const int FAIL = 0;
82 public const short TYPE_SIZE_LIMIT = 8000;
83 public const int MIN_PACKET_SIZE = 512;
84 // Login packet can be no greater than 4k until server sends us env-change
85 // increasing packet size.
86 public const int DEFAULT_LOGIN_PACKET_SIZE = 4096;
87 public const int MAX_PRELOGIN_PAYLOAD_LENGTH = 1024;
88 public const int MAX_PACKET_SIZE = 32768;
89 public const int MAX_SERVER_USER_NAME = 256; // obtained from luxor
91 // Severity 0 - 10 indicates informational (non-error) messages
92 // Severity 11 - 16 indicates errors that can be corrected by user (syntax errors, etc...)
93 // Severity 17 - 19 indicates failure due to insufficient resources in the server
94 // (max locks exceeded, not enough memory, other internal server limits reached, etc..)
95 // Severity 20 - 25 Severe problems with the server, connection terminated.
96 public const byte MIN_ERROR_CLASS = 11; // webdata 100667: This should actually be 11
97 public const byte MAX_USER_CORRECTABLE_ERROR_CLASS = 16;
98 public const byte FATAL_ERROR_CLASS = 20;
101 public const byte MT_SQL = 1; // SQL command batch
102 public const byte MT_LOGIN = 2; // Login message for pre-Sphinx (before version 7.0)
103 public const byte MT_RPC = 3; // Remote procedure call
104 public const byte MT_TOKENS = 4; // Table response data stream
105 public const byte MT_BINARY = 5; // Unformatted binary response data (UNUSED)
106 public const byte MT_ATTN = 6; // Attention (break) signal
107 public const byte MT_BULK = 7; // Bulk load data
108 public const byte MT_FEDAUTH = 8; // Authentication token for federated authentication
109 public const byte MT_CLOSE = 9; // Close subchannel (UNUSED)
110 public const byte MT_ERROR = 10; // Protocol error detected
111 public const byte MT_ACK = 11; // Protocol acknowledgement (UNUSED)
112 public const byte MT_ECHO = 12; // Echo data (UNUSED)
113 public const byte MT_LOGOUT = 13; // Logout message (UNUSED)
114 public const byte MT_TRANS = 14; // Transaction Manager Interface
115 public const byte MT_OLEDB = 15; // ? (UNUSED)
116 public const byte MT_LOGIN7 = 16; // Login message for Sphinx (version 7) or later
117 public const byte MT_SSPI = 17; // SSPI message
118 public const byte MT_PRELOGIN = 18; // Pre-login handshake
120 // Message status bits
121 public const byte ST_EOM = 0x1; // Packet is end-of-message
122 public const byte ST_AACK = 0x2; // Packet acknowledges attention (server to client)
123 public const byte ST_IGNORE = 0x2; // Ignore this event (client to server)
124 public const byte ST_BATCH = 0x4; // Message is part of a batch.
125 public const byte ST_RESET_CONNECTION = 0x8; // Exec sp_reset_connection prior to processing message
126 public const byte ST_RESET_CONNECTION_PRESERVE_TRANSACTION = 0x10; // reset prior to processing, with preserving local tx
128 // TDS control tokens
129 public const byte SQLCOLFMT = 0xa1;
130 public const byte SQLPROCID = 0x7c;
131 public const byte SQLCOLNAME = 0xa0;
132 public const byte SQLTABNAME = 0xa4;
133 public const byte SQLCOLINFO = 0xa5;
134 public const byte SQLALTNAME = 0xa7;
135 public const byte SQLALTFMT = 0xa8;
136 public const byte SQLERROR = 0xaa;
137 public const byte SQLINFO = 0xab;
138 public const byte SQLRETURNVALUE = 0xac;
139 public const byte SQLRETURNSTATUS = 0x79;
140 public const byte SQLRETURNTOK = 0xdb;
141 public const byte SQLALTCONTROL = 0xaf;
142 public const byte SQLROW = 0xd1;
143 public const byte SQLNBCROW = 0xd2; // same as ROW with null-bit-compression support
144 public const byte SQLALTROW = 0xd3;
145 public const byte SQLDONE = 0xfd;
146 public const byte SQLDONEPROC = 0xfe;
147 public const byte SQLDONEINPROC = 0xff;
148 public const byte SQLOFFSET = 0x78;
149 public const byte SQLORDER = 0xa9;
150 public const byte SQLDEBUG_CMD = 0x60;
151 public const byte SQLLOGINACK = 0xad;
152 public const byte SQLFEATUREEXTACK= 0xae; // TDS 7.4 - feature ack
153 public const byte SQLSESSIONSTATE = 0xe4; // TDS 7.4 - connection resiliency session state
154 public const byte SQLENVCHANGE = 0xe3; // Environment change notification
155 public const byte SQLSECLEVEL = 0xed; // Security level token ???
156 public const byte SQLROWCRC = 0x39; // ROWCRC datastream???
157 public const byte SQLCOLMETADATA = 0x81; // Column metadata including name
158 public const byte SQLALTMETADATA = 0x88; // Alt column metadata including name
159 public const byte SQLSSPI = 0xed; // SSPI data
160 public const byte SQLFEDAUTHINFO = 0xee; // Info for client to generate fed auth token
162 // Environment change notification streams
163 // TYPE on TDS ENVCHANGE token stream (from sql\ntdbms\include\odsapi.h)
165 public const byte ENV_DATABASE = 1; // Database changed
166 public const byte ENV_LANG = 2; // Language changed
167 public const byte ENV_CHARSET = 3; // Character set changed
168 public const byte ENV_PACKETSIZE = 4; // Packet size changed
169 public const byte ENV_LOCALEID = 5; // Unicode data sorting locale id
170 public const byte ENV_COMPFLAGS = 6; // Unicode data sorting comparison flags
171 public const byte ENV_COLLATION = 7; // SQL Collation
172 // The following are environment change tokens valid for Yukon or later.
173 public const byte ENV_BEGINTRAN = 8; // Transaction began
174 public const byte ENV_COMMITTRAN = 9; // Transaction committed
175 public const byte ENV_ROLLBACKTRAN = 10; // Transaction rolled back
176 public const byte ENV_ENLISTDTC = 11; // Enlisted in Distributed Transaction
177 public const byte ENV_DEFECTDTC = 12; // Defected from Distributed Transaction
178 public const byte ENV_LOGSHIPNODE = 13; // Realtime Log shipping primary node
179 public const byte ENV_PROMOTETRANSACTION = 15; // Promote Transaction
180 public const byte ENV_TRANSACTIONMANAGERADDRESS = 16; // Transaction Manager Address
181 public const byte ENV_TRANSACTIONENDED = 17; // Transaction Ended
182 public const byte ENV_SPRESETCONNECTIONACK = 18; // SP_Reset_Connection ack
183 public const byte ENV_USERINSTANCE = 19; // User Instance
184 public const byte ENV_ROUTING = 20; // Routing (ROR) information
186 // done status stream bit masks
187 public const int DONE_MORE = 0x0001; // more command results coming
188 public const int DONE_ERROR = 0x0002; // error in command batch
189 public const int DONE_INXACT = 0x0004; // transaction in progress
190 public const int DONE_PROC = 0x0008; // done from stored proc
191 public const int DONE_COUNT = 0x0010; // count in done info
192 public const int DONE_ATTN = 0x0020; // oob ack
193 public const int DONE_INPROC = 0x0040; // like DONE_PROC except proc had error
194 public const int DONE_RPCINBATCH = 0x0080; // Done from RPC in batch
195 public const int DONE_SRVERROR = 0x0100; // Severe error in which resultset should be discarded
196 public const int DONE_FMTSENT = 0x8000; // fmt message sent, done_inproc req'd
199 public const byte FEATUREEXT_TERMINATOR = 0xFF;
200 public const byte FEATUREEXT_SRECOVERY = 0x01;
201 public const byte FEATUREEXT_FEDAUTH = 0x02;
202 public const byte FEATUREEXT_TCE = 0x04;
205 public enum FeatureExtension:uint {
212 public const byte FEDAUTHLIB_LIVEID = 0X00;
213 public const byte FEDAUTHLIB_SECURITYTOKEN = 0x01;
214 public const byte FEDAUTHLIB_ADAL = 0x02;
215 public const byte FEDAUTHLIB_RESERVED = 0X7F;
217 public enum FedAuthLibrary:byte {
218 LiveId=FEDAUTHLIB_LIVEID,
219 SecurityToken=FEDAUTHLIB_SECURITYTOKEN,
220 ADAL=FEDAUTHLIB_ADAL,
221 Default=FEDAUTHLIB_RESERVED
224 public const byte ADALWORKFLOW_ACTIVEDIRECTORYPASSWORD = 0x01;
225 public const byte ADALWORKFLOW_ACTIVEDIRECTORYINTEGRATED = 0x02;
227 public enum ActiveDirectoryWorkflow : byte {
228 Password=ADALWORKFLOW_ACTIVEDIRECTORYPASSWORD,
229 Integrated=ADALWORKFLOW_ACTIVEDIRECTORYINTEGRATED,
232 // The string used for username in the error message when Authentication = Active Directory Integrated with FedAuth is used, if authentication fails.
233 public const string NTAUTHORITYANONYMOUSLOGON = @"NT Authority\Anonymous Logon";
236 public const byte MAX_LOG_NAME = 30; // TDS 4.2 login rec max name length
237 public const byte MAX_PROG_NAME = 10; // max length of loginrec progran name
238 public const byte SEC_COMP_LEN = 8; // length of security compartments
239 public const byte MAX_PK_LEN = 6; // max length of TDS packet size
240 public const byte MAX_NIC_SIZE = 6; // The size of a MAC or client address
241 public const byte SQLVARIANT_SIZE = 2; // size of the fixed portion of a sql variant (type, cbPropBytes)
242 public const byte VERSION_SIZE = 4; // size of the tds version (4 unsigned bytes)
243 public const int CLIENT_PROG_VER = 0x06000000; // Client interface version
244 public const int YUKON_LOG_REC_FIXED_LEN = 0x5e;
246 public const int TEXT_TIME_STAMP_LEN = 8;
247 public const int COLLATION_INFO_LEN = 4;
250 public const byte INT4_LSB_HI = 0; // lsb is low byte (eg 68000)
251 // public const byte INT4_LSB_LO = 1; // lsb is low byte (eg VAX)
252 public const byte INT2_LSB_HI = 2; // lsb is low byte (eg 68000)
253 // public const byte INT2_LSB_LO = 3; // lsb is low byte (eg VAX)
254 public const byte FLT_IEEE_HI = 4; // lsb is low byte (eg 68000)
255 public const byte CHAR_ASCII = 6; // ASCII character set
256 public const byte TWO_I4_LSB_HI = 8; // lsb is low byte (eg 68000
257 // public const byte TWO_I4_LSB_LO = 9; // lsb is low byte (eg VAX)
258 // public const byte FLT_IEEE_LO = 10; // lsb is low byte (eg MSDOS)
259 public const byte FLT4_IEEE_HI = 12; // IEEE 4-byte floating point -lsb is high byte
260 // public const byte FLT4_IEEE_LO = 13; // IEEE 4-byte floating point -lsb is low byte
261 public const byte TWO_I2_LSB_HI = 16; // lsb is high byte
262 // public const byte TWO_I2_LSB_LO = 17; // lsb is low byte
264 public const byte LDEFSQL = 0; // server sends its default
265 public const byte LDEFUSER = 0; // regular old user
266 public const byte LINTEGRATED = 8; // integrated security login
269 /* Versioning scheme table:
273 0x71000000 -> Shiloh RTM
274 0x71000001 -> Shiloh SP1
275 0x72xx0002 -> Yukon RTM
278 0x07000000 -> Sphinx // Notice server response format is different for bwd compat
279 0x07010000 -> Shiloh RTM // Notice server response format is different for bwd compat
280 0x71000001 -> Shiloh SP1
281 0x72xx0002 -> Yukon RTM
284 // Pre Shiloh SP1 versioning scheme:
285 public const int SPHINXORSHILOH_MAJOR = 0x07; // The high byte (b3) is not sufficient to distinguish
286 public const int SPHINX_INCREMENT = 0x00; // Sphinx and Shiloh
287 public const int SHILOH_INCREMENT = 0x01; // So we need to look at the high-mid byte (b2) as well
288 public const int DEFAULT_MINOR = 0x0000;
290 // Shiloh SP1 and beyond versioning scheme:
293 public const int SHILOHSP1_MAJOR = 0x71; // For Shiloh SP1 and later the versioning schema changed and
294 public const int YUKON_MAJOR = 0x72; // the high-byte is sufficient to distinguish later versions
295 public const int KATMAI_MAJOR = 0x73;
296 public const int DENALI_MAJOR = 0x74;
299 public const int SHILOHSP1_INCREMENT = 0x00;
300 public const int YUKON_INCREMENT = 0x09;
301 public const int KATMAI_INCREMENT = 0x0b;
302 public const int DENALI_INCREMENT = 0x00;
305 public const int SHILOHSP1_MINOR = 0x0001;
306 public const int YUKON_RTM_MINOR = 0x0002;
307 public const int KATMAI_MINOR = 0x0003;
308 public const int DENALI_MINOR = 0x0004;
310 public const int ORDER_68000 = 1;
311 public const int USE_DB_ON = 1;
312 public const int INIT_DB_FATAL = 1;
313 public const int SET_LANG_ON = 1;
314 public const int INIT_LANG_FATAL = 1;
315 public const int ODBC_ON = 1;
316 public const int SSPI_ON = 1;
317 public const int REPL_ON = 3;
320 // send the read-only intent to the server
321 public const int READONLY_INTENT_ON = 1;
324 public const byte SQLLenMask = 0x30; // mask to check for length tokens
325 public const byte SQLFixedLen = 0x30; // Mask to check for fixed token
326 public const byte SQLVarLen = 0x20; // Value to check for variable length token
327 public const byte SQLZeroLen = 0x10; // Value to check for zero length token
328 public const byte SQLVarCnt = 0x00; // Value to check for variable count token
330 // Token masks for COLINFO status
331 public const byte SQLDifferentName = 0x20; // column name different than select list name
332 public const byte SQLExpression = 0x4; // column was result of an expression
333 public const byte SQLKey = 0x8; // column is part of the key for the table
334 public const byte SQLHidden = 0x10; // column not part of select list but added because part of key
336 // Token masks for COLMETADATA flags
338 public const byte Nullable = 0x1;
339 public const byte Identity = 0x10;
340 public const byte Updatability = 0xb; // mask off bits 3 and 4
342 public const byte ClrFixedLen = 0x1; // Fixed length CLR type
343 public const byte IsColumnSet = 0x4; // Column is an XML representation of an aggregation of other columns
344 public const byte IsEncrypted = 0x8; // Column is encrypted using TCE
347 public const uint VARLONGNULL = 0xffffffff; // null value for text and image types
348 public const int VARNULL = 0xffff; // null value for character and binary types
349 public const int MAXSIZE = 8000; // max size for any column
350 public const byte FIXEDNULL = 0;
351 public const UInt64 UDTNULL = 0xffffffffffffffff;
353 // SQL Server Data Type Tokens.
354 public const int SQLVOID = 0x1f;
355 public const int SQLTEXT = 0x23;
356 public const int SQLVARBINARY = 0x25;
357 public const int SQLINTN = 0x26;
358 public const int SQLVARCHAR = 0x27;
359 public const int SQLBINARY = 0x2d;
360 public const int SQLIMAGE = 0x22;
361 public const int SQLCHAR = 0x2f;
362 public const int SQLINT1 = 0x30;
363 public const int SQLBIT = 0x32;
364 public const int SQLINT2 = 0x34;
365 public const int SQLINT4 = 0x38;
366 public const int SQLMONEY = 0x3c;
367 public const int SQLDATETIME = 0x3d;
368 public const int SQLFLT8 = 0x3e;
369 public const int SQLFLTN = 0x6d;
370 public const int SQLMONEYN = 0x6e;
371 public const int SQLDATETIMN = 0x6f;
372 public const int SQLFLT4 = 0x3b;
373 public const int SQLMONEY4 = 0x7a;
374 public const int SQLDATETIM4 = 0x3a;
375 public const int SQLDECIMALN = 0x6a;
376 public const int SQLNUMERICN = 0x6c;
377 public const int SQLUNIQUEID = 0x24;
378 public const int SQLBIGCHAR = 0xaf;
379 public const int SQLBIGVARCHAR = 0xa7;
380 public const int SQLBIGBINARY = 0xad;
381 public const int SQLBIGVARBINARY = 0xa5;
382 public const int SQLBITN = 0x68;
383 public const int SQLNCHAR = 0xef;
384 public const int SQLNVARCHAR = 0xe7;
385 public const int SQLNTEXT = 0x63;
386 public const int SQLUDT = 0xF0;
388 // aggregate operator type TDS tokens, used by compute statements:
389 public const int AOPCNTB = 0x09;
390 public const int AOPSTDEV = 0x30;
391 public const int AOPSTDEVP = 0x31;
392 public const int AOPVAR = 0x32;
393 public const int AOPVARP = 0x33;
395 public const int AOPCNT = 0x4b;
396 public const int AOPSUM = 0x4d;
397 public const int AOPAVG = 0x4f;
398 public const int AOPMIN = 0x51;
399 public const int AOPMAX = 0x52;
400 public const int AOPANY = 0x53;
401 public const int AOPNOOP = 0x56;
403 // SQL Server user-defined type tokens we care about
404 public const int SQLTIMESTAMP = 0x50;
406 public const int MAX_NUMERIC_LEN = 0x11; // 17 bytes of data for max numeric/decimal length
407 public const int DEFAULT_NUMERIC_PRECISION = 0x1D; // 29 is the default max numeric precision(Decimal.MaxValue) if not user set
408 public const int SPHINX_DEFAULT_NUMERIC_PRECISION = 0x1C; // 28 is the default max numeric precision for Sphinx(Decimal.MaxValue doesn't work for sphinx)
409 public const int MAX_NUMERIC_PRECISION = 0x26; // 38 is max numeric precision;
410 public const byte UNKNOWN_PRECISION_SCALE = 0xff; // -1 is value for unknown precision or scale
412 // The following datatypes are specific to SHILOH (version 8) and later.
413 public const int SQLINT8 = 0x7f;
414 public const int SQLVARIANT = 0x62;
416 // The following datatypes are specific to Yukon (version 9) or later
417 public const int SQLXMLTYPE = 0xf1;
418 public const int XMLUNICODEBOM = 0xfeff;
419 public static readonly byte[] XMLUNICODEBOMBYTES = { 0xff, 0xfe };
421 // The following datatypes are specific to Katmai (version 10) or later
422 public const int SQLTABLE = 0xf3;
423 public const int SQLDATE = 0x28;
424 public const int SQLTIME = 0x29;
425 public const int SQLDATETIME2 = 0x2a;
426 public const int SQLDATETIMEOFFSET = 0x2b;
428 public const int DEFAULT_VARTIME_SCALE = 7;
430 //Partially length prefixed datatypes constants. These apply to XMLTYPE, BIGVARCHRTYPE,
431 // NVARCHARTYPE, and BIGVARBINTYPE. Valid for Yukon or later
433 public const ulong SQL_PLP_NULL = 0xffffffffffffffff; // Represents null value
434 public const ulong SQL_PLP_UNKNOWNLEN = 0xfffffffffffffffe; // Data coming in chunks, total length unknown
435 public const int SQL_PLP_CHUNK_TERMINATOR = 0x00000000; // Represents end of chunked data.
436 public const ushort SQL_USHORTVARMAXLEN = 0xffff; // Second ushort in TDS stream is this value if one of max types
438 // TVPs require some new in-value control tokens:
439 public const byte TVP_ROWCOUNT_ESTIMATE = 0x12;
440 public const byte TVP_ROW_TOKEN = 0x01;
441 public const byte TVP_END_TOKEN = 0x00;
442 public const ushort TVP_NOMETADATA_TOKEN = 0xFFFF;
443 public const byte TVP_ORDER_UNIQUE_TOKEN = 0x10;
445 // TvpColumnMetaData flags
446 public const int TVP_DEFAULT_COLUMN = 0x200;
448 // TVP_ORDER_UNIQUE_TOKEN flags
449 public const byte TVP_ORDERASC_FLAG = 0x1;
450 public const byte TVP_ORDERDESC_FLAG = 0x2;
451 public const byte TVP_UNIQUE_FLAG = 0x4;
453 public const bool Is68K = false;
454 public const bool TraceTDS = false;
456 // RPC function names
457 public const string SP_EXECUTESQL = "sp_executesql"; // used against 7.0 servers
458 public const string SP_PREPEXEC = "sp_prepexec"; // used against 7.5 servers
460 public const string SP_PREPARE = "sp_prepare"; // used against 7.0 servers
461 public const string SP_EXECUTE = "sp_execute";
462 public const string SP_UNPREPARE = "sp_unprepare";
463 public const string SP_PARAMS = "sp_procedure_params_rowset";
464 public const string SP_PARAMS_MANAGED = "sp_procedure_params_managed";
465 public const string SP_PARAMS_MGD10 = "sp_procedure_params_100_managed";
468 // NOTE: It is more efficient to call these procs using ProcID's instead of names
469 public const ushort RPC_PROCID_CURSOR = 1;
470 public const ushort RPC_PROCID_CURSOROPEN = 2;
471 public const ushort RPC_PROCID_CURSORPREPARE = 3;
472 public const ushort RPC_PROCID_CURSOREXECUTE = 4;
473 public const ushort RPC_PROCID_CURSORPREPEXEC = 5;
474 public const ushort RPC_PROCID_CURSORUNPREPARE = 6;
475 public const ushort RPC_PROCID_CURSORFETCH = 7;
476 public const ushort RPC_PROCID_CURSOROPTION = 8;
477 public const ushort RPC_PROCID_CURSORCLOSE = 9;
478 public const ushort RPC_PROCID_EXECUTESQL = 10;
479 public const ushort RPC_PROCID_PREPARE = 11;
480 public const ushort RPC_PROCID_EXECUTE = 12;
481 public const ushort RPC_PROCID_PREPEXEC = 13;
482 public const ushort RPC_PROCID_PREPEXECRPC = 14;
483 public const ushort RPC_PROCID_UNPREPARE = 15;
486 public const string TRANS_BEGIN = "BEGIN TRANSACTION";
487 public const string TRANS_COMMIT = "COMMIT TRANSACTION";
488 public const string TRANS_ROLLBACK = "ROLLBACK TRANSACTION";
489 public const string TRANS_IF_ROLLBACK = "IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION";
490 public const string TRANS_SAVE = "SAVE TRANSACTION";
492 // For Transactions - isolation levels
493 public const string TRANS_READ_COMMITTED = "SET TRANSACTION ISOLATION LEVEL READ COMMITTED";
494 public const string TRANS_READ_UNCOMMITTED = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED";
495 public const string TRANS_REPEATABLE_READ = "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ";
496 public const string TRANS_SERIALIZABLE = "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE";
497 public const string TRANS_SNAPSHOT = "SET TRANSACTION ISOLATION LEVEL SNAPSHOT";
500 public const byte SHILOH_RPCBATCHFLAG = 0x80;
501 public const byte YUKON_RPCBATCHFLAG = 0xFF;
504 public const byte RPC_RECOMPILE = 0x1;
505 public const byte RPC_NOMETADATA = 0x2;
507 // RPC parameter class
508 public const byte RPC_PARAM_BYREF = 0x1;
509 public const byte RPC_PARAM_DEFAULT = 0x2;
510 public const byte RPC_PARAM_ENCRYPTED = 0x8;
512 // SQL parameter list text
513 public const string PARAM_OUTPUT = "output";
515 // SQL Parameter constants
516 public const int MAX_PARAMETER_NAME_LENGTH = 128;
518 // metadata options (added around an existing sql statement)
521 public const string FMTONLY_ON = " SET FMTONLY ON;";
522 public const string FMTONLY_OFF = " SET FMTONLY OFF;";
524 public const string BROWSE_ON = " SET NO_BROWSETABLE ON;";
525 public const string BROWSE_OFF = " SET NO_BROWSETABLE OFF;";
527 // generic table name
528 public const string TABLE = "Table";
530 public const int EXEC_THRESHOLD = 0x3; // if the number of commands we execute is > than this threshold, than do prep/exec/unprep instead
533 // dbnetlib error values
534 public const short TIMEOUT_EXPIRED = -2;
535 public const short ENCRYPTION_NOT_SUPPORTED = 20;
536 // CAUTION: These are not error codes returned by SNI. This is used for backward compatibility
537 // since netlib (now removed from sqlclient) returned these codes.
539 // SQL error values (from sqlerrorcodes.h)
540 public const int LOGON_FAILED = 18456;
541 public const int PASSWORD_EXPIRED = 18488;
542 public const int IMPERSONATION_FAILED = 1346;
543 public const int P_TOKENTOOLONG = 103;
545 // SNI\Win32 error values
546 // NOTE: these are simply windows system error codes, not SNI specific
547 public const uint SNI_UNINITIALIZED = unchecked((uint)-1);
548 public const uint SNI_SUCCESS = 0; // The operation completed successfully.
549 public const uint SNI_WAIT_TIMEOUT = 258; // The wait operation timed out.
550 public const uint SNI_SUCCESS_IO_PENDING = 997; // Overlapped I/O operation is in progress.
552 // Windows Sockets Error Codes
553 public const short SNI_WSAECONNRESET = 10054; // An existing connection was forcibly closed by the remote host.
556 public const UInt32 SNI_SSL_VALIDATE_CERTIFICATE = 1; // This enables validation of server certificate
557 public const UInt32 SNI_SSL_USE_SCHANNEL_CACHE = 2; // This enables schannel session cache
558 public const UInt32 SNI_SSL_IGNORE_CHANNEL_BINDINGS = 0x10; // Used with SSL Provider, sent to SNIAddProvider in case of SQL Authentication & Encrypt.
560 public const string DEFAULT_ENGLISH_CODE_PAGE_STRING = "iso_1";
561 public const short DEFAULT_ENGLISH_CODE_PAGE_VALUE = 1252;
562 public const short CHARSET_CODE_PAGE_OFFSET = 2;
563 internal const int MAX_SERVERNAME = 255;
565 // Sql Statement Tokens in the DONE packet
566 // (see ntdbms\ntinc\tokens.h)
568 internal const ushort SELECT = 0xc1;
569 internal const ushort INSERT = 0xc3;
570 internal const ushort DELETE = 0xc4;
571 internal const ushort UPDATE = 0xc5;
572 internal const ushort ABORT = 0xd2;
573 internal const ushort BEGINXACT = 0xd4;
574 internal const ushort ENDXACT = 0xd5;
575 internal const ushort BULKINSERT = 0xf0;
576 internal const ushort OPENCURSOR = 0x20;
577 internal const ushort MERGE = 0x117;
580 // Login data validation Rules
582 internal const ushort MAXLEN_HOSTNAME = 128; // the client machine name
583 internal const ushort MAXLEN_USERNAME = 128; // the client user id
584 internal const ushort MAXLEN_PASSWORD = 128; // the password supplied by the client
585 internal const ushort MAXLEN_APPNAME = 128; // the client application name
586 internal const ushort MAXLEN_SERVERNAME = 128; // the server name
587 internal const ushort MAXLEN_CLIENTINTERFACE = 128; // the interface library name
588 internal const ushort MAXLEN_LANGUAGE = 128; // the initial language
589 internal const ushort MAXLEN_DATABASE = 128; // the initial database
590 internal const ushort MAXLEN_ATTACHDBFILE = 260; // the filename for a database that is to be attached during the connection process
591 internal const ushort MAXLEN_NEWPASSWORD = 128; // new password for the specified login.
594 // array copied directly from tdssort.h from luxor
595 public static readonly UInt16[] CODE_PAGE_FROM_SORT_ID = {
854 internal enum UDTFormatType {
859 internal enum TransactionManagerRequestType {
869 internal enum TransactionManagerIsolationLevel {
871 ReadUncommitted = 0x01,
872 ReadCommitted = 0x02,
873 RepeatableRead = 0x03,
878 internal enum GenericType {
882 // Date, Time, DateTime2, DateTimeOffset specific constants
883 internal static readonly Int64[] TICKS_FROM_SCALE = {
894 internal const int MAX_TIME_SCALE = 7; // Maximum scale for time-related types
895 internal const int MAX_TIME_LENGTH = 5; // Maximum length for time
896 internal const int MAX_DATETIME2_LENGTH = 8; // Maximum length for datetime2
897 internal const int WHIDBEY_DATE_LENGTH = 10;
898 internal static readonly int[] WHIDBEY_TIME_LENGTH = { 8, 10, 11, 12, 13, 14, 15, 16 };
899 internal static readonly int[] WHIDBEY_DATETIME2_LENGTH = { 19, 21, 22, 23, 24, 25, 26, 27 };
900 internal static readonly int[] WHIDBEY_DATETIMEOFFSET_LENGTH = {26, 28, 29, 30, 31, 32, 33, 34 };
902 internal enum FedAuthInfoId:byte {
903 Stsurl = 0x01, // FedAuthInfoData is token endpoint URL from which to acquire fed auth token
904 Spn = 0x02, // FedAuthInfoData is the SPN to use for acquiring fed auth token
907 // TCE Related constants
908 internal const byte MAX_SUPPORTED_TCE_VERSION = 0x01; // max version
909 internal const ushort MAX_TCE_CIPHERINFO_SIZE = 2048; // max size of cipherinfo blob
910 internal const long MAX_TCE_CIPHERTEXT_SIZE = 2147483648; // max size of encrypted blob- currently 2GB.
911 internal const byte CustomCipherAlgorithmId = 0; // Id used for custom encryption algorithm.
913 internal const int AES_256_CBC = 1;
914 internal const int AEAD_AES_256_CBC_HMAC_SHA256 = 2;
916 // TCE Param names for exec handling
917 internal const string TCE_PARAM_CIPHERTEXT = "cipherText";
918 internal const string TCE_PARAM_CIPHER_ALGORITHM_ID="cipherAlgorithmId";
919 internal const string TCE_PARAM_COLUMNENCRYPTION_KEY="columnEncryptionKey";
920 internal const string TCE_PARAM_ENCRYPTION_ALGORITHM="encryptionAlgorithm";
921 internal const string TCE_PARAM_ENCRYPTIONTYPE = "encryptionType";
922 internal const string TCE_PARAM_ENCRYPTIONKEY = "encryptionKey";
923 internal const string TCE_PARAM_MASTERKEY_PATH = "masterKeyPath";
924 internal const string TCE_PARAM_ENCRYPTED_CEK = "encryptedColumnEncryptionKey";
925 internal const string TCE_PARAM_CLIENT_KEYSTORE_PROVIDERS="clientKeyStoreProviders";
926 internal const string TCE_PARAM_FORCE_COLUMN_ENCRYPTION="ForceColumnEncryption(true)";
929 internal enum ParsingErrorState {
931 FedAuthInfoLengthTooShortForCountOfInfoIds = 1,
932 FedAuthInfoLengthTooShortForData = 2,
933 FedAuthInfoFailedToReadCountOfInfoIds = 3,
934 FedAuthInfoFailedToReadTokenStream = 4,
935 FedAuthInfoInvalidOffset = 5,
936 FedAuthInfoFailedToReadData = 6,
937 FedAuthInfoDataNotUnicode = 7,
938 FedAuthInfoDoesNotContainStsurlAndSpn = 8,
939 FedAuthInfoNotReceived = 9,
940 FedAuthNotAcknowledged = 10,
941 FedAuthFeatureAckContainsExtraData = 11,
942 FedAuthFeatureAckUnknownLibraryType = 12,
943 UnrequestedFeatureAckReceived = 13,
944 UnknownFeatureAck = 14,
945 InvalidTdsTokenReceived = 15,
946 SessionStateLengthTooShort = 16,
947 SessionStateInvalidStatus = 17,
948 CorruptedTdsStream = 18,
949 ProcessSniPacketFailed = 19,
950 FedAuthRequiredPreLoginResponseInvalidValue = 20,
951 TceUnknownVersion = 21,
952 TceInvalidVersion = 22,
953 TceInvalidOrdinalIntoCipherInfoTable = 23,
956 internal enum SniContext {
959 Snix_PreLoginBeforeSuccessfullWrite,
974 /// Column Encryption Setting to be used for the SqlConnection.
976 public enum SqlConnectionColumnEncryptionSetting {
978 /// Disables column encryption by default on all commands on this connection.
983 /// Enables column encryption by default on all commands on this connection.
989 /// Column Encryption Setting to be used for the SqlCommand.
991 public enum SqlCommandColumnEncryptionSetting {
993 /// if
\93Column Encryption Setting=Enabled
\94 in the connection string, use Enabled. Otherwise, maps to Disabled.
995 UseConnectionSetting = 0,
998 /// Enables TCE for the command. Overrides the connection level setting for this command.
1003 /// Parameters will not be encrypted, only the ResultSet will be decrypted. This is an optimization for queries that do not pass any encrypted input parameters.
1004 /// Overrides the connection level setting for this command.
1009 /// Disables TCE for the command.Overrides the connection level setting for this command.
1014 public enum SqlAuthenticationMethod {
1017 ActiveDirectoryPassword,
1018 ActiveDirectoryIntegrated,
1021 internal class ActiveDirectoryAuthentication
1023 internal const string AdoClientId = "4d079b4c-cab7-4b7c-a115-8fd51b6f8239";
1024 internal const string AdalGetAccessTokenFunctionName = "ADALGetAccessToken";
1025 internal const int GetAccessTokenSuccess = 0;
1026 internal const int GetAccessTokenInvalidGrant = 1;
1027 internal const int GetAccessTokenTansisentError = 2;
1028 internal const int GetAccessTokenOtherError = 3;
1031 // Fields in the first resultset of "sp_describe_parameter_encryption".
1032 // We expect the server to return the fields in the resultset in the same order as mentioned below.
1033 // If the server changes the below order, then transparent parameter encryption will break.
1034 internal enum DescribeParameterEncryptionResultSet1 {
1043 KeyEncryptionAlgorithm,
1046 // Fields in the second resultset of "sp_describe_parameter_encryption"
1047 // We expect the server to return the fields in the resultset in the same order as mentioned below.
1048 // If the server changes the below order, then transparent parameter encryption will break.
1049 internal enum DescribeParameterEncryptionResultSet2 {
1050 ParameterOrdinal = 0,
1052 ColumnEncryptionAlgorithm,
1053 ColumnEncrytionType,
1054 ColumnEncryptionKeyOrdinal,
1055 NormalizationRuleVersion,