Skip to content

Commit 4e04631

Browse files
authored
Complete removal of SQL 2000 support (#3217)
1 parent 325ca56 commit 4e04631

File tree

14 files changed

+115
-435
lines changed

14 files changed

+115
-435
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2352,8 +2352,7 @@ private static void ChangePassword(string connectionString, SqlConnectionString
23522352
}
23532353
finally
23542354
{
2355-
if (con != null)
2356-
con.Dispose();
2355+
con?.Dispose();
23572356
}
23582357
SqlConnectionPoolKey key = new SqlConnectionPoolKey(connectionString, credential, accessToken: null, accessTokenCallback: null);
23592358

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

-2
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ internal EncryptionOptions EncryptionOptions
251251
}
252252
}
253253

254-
internal bool Is2005OrNewer => true;
255-
256254
internal bool Is2008OrNewer
257255
{
258256
get

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs

+82-113
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,6 @@ internal object[] CreateRowBuffer()
112112
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/SqlBulkCopy/*'/>
113113
public sealed class SqlBulkCopy : IDisposable
114114
{
115-
private enum TableNameComponents
116-
{
117-
Server = 0,
118-
Catalog,
119-
Owner,
120-
TableName,
121-
}
122-
123115
private enum ValueSourceType
124116
{
125117
Unspecified = 0,
@@ -161,10 +153,6 @@ public SourceColumnMetadata(ValueMethod method, bool isSqlType, bool isDataFeed)
161153
// MetaData has n columns but no rows
162154
// Collation has 4 columns and n rows
163155

164-
private const int TranCountResultId = 0;
165-
private const int TranCountRowId = 0;
166-
private const int TranCountValueId = 0;
167-
168156
private const int MetaDataResultId = 1;
169157

170158
private const int CollationResultId = 2;
@@ -439,66 +427,60 @@ private string CreateInitialQuery()
439427
string TDSCommand;
440428

441429
TDSCommand = "select @@trancount; SET FMTONLY ON select * from " + ADP.BuildMultiPartName(parts) + " SET FMTONLY OFF ";
442-
if (_connection.Is2000)
443-
{
444-
// If its a temp DB then try to connect
445430

446-
string TableCollationsStoredProc;
447-
if (_connection.Is2008OrNewer)
448-
{
449-
TableCollationsStoredProc = "sp_tablecollations_100";
450-
}
451-
else if (_connection.Is2005OrNewer)
452-
{
453-
TableCollationsStoredProc = "sp_tablecollations_90";
454-
}
455-
else
456-
{
457-
TableCollationsStoredProc = "sp_tablecollations";
458-
}
431+
// If its a temp DB then try to connect
459432

460-
string TableName = parts[MultipartIdentifier.TableIndex];
461-
bool isTempTable = TableName.Length > 0 && '#' == TableName[0];
462-
if (!ADP.IsEmpty(TableName))
463-
{
464-
// Escape table name to be put inside TSQL literal block (within N'').
465-
TableName = SqlServerEscapeHelper.EscapeStringAsLiteral(TableName);
466-
// VSDD 581951 - escape the table name
467-
TableName = SqlServerEscapeHelper.EscapeIdentifier(TableName);
468-
}
433+
string TableCollationsStoredProc;
434+
if (_connection.Is2008OrNewer)
435+
{
436+
TableCollationsStoredProc = "sp_tablecollations_100";
437+
}
438+
else
439+
{
440+
TableCollationsStoredProc = "sp_tablecollations_90";
441+
}
469442

470-
string SchemaName = parts[MultipartIdentifier.SchemaIndex];
471-
if (!ADP.IsEmpty(SchemaName))
472-
{
473-
// Escape schema name to be put inside TSQL literal block (within N'').
474-
SchemaName = SqlServerEscapeHelper.EscapeStringAsLiteral(SchemaName);
475-
// VSDD 581951 - escape the schema name
476-
SchemaName = SqlServerEscapeHelper.EscapeIdentifier(SchemaName);
477-
}
443+
string TableName = parts[MultipartIdentifier.TableIndex];
444+
bool isTempTable = TableName.Length > 0 && '#' == TableName[0];
445+
if (!ADP.IsEmpty(TableName))
446+
{
447+
// Escape table name to be put inside TSQL literal block (within N'').
448+
TableName = SqlServerEscapeHelper.EscapeStringAsLiteral(TableName);
449+
// VSDD 581951 - escape the table name
450+
TableName = SqlServerEscapeHelper.EscapeIdentifier(TableName);
451+
}
478452

479-
string CatalogName = parts[MultipartIdentifier.CatalogIndex];
480-
if (isTempTable && ADP.IsEmpty(CatalogName))
481-
{
482-
TDSCommand += string.Format("exec tempdb..{0} N'{1}.{2}'",
483-
TableCollationsStoredProc,
484-
SchemaName,
485-
TableName
486-
);
487-
}
488-
else
453+
string SchemaName = parts[MultipartIdentifier.SchemaIndex];
454+
if (!ADP.IsEmpty(SchemaName))
455+
{
456+
// Escape schema name to be put inside TSQL literal block (within N'').
457+
SchemaName = SqlServerEscapeHelper.EscapeStringAsLiteral(SchemaName);
458+
// VSDD 581951 - escape the schema name
459+
SchemaName = SqlServerEscapeHelper.EscapeIdentifier(SchemaName);
460+
}
461+
462+
string CatalogName = parts[MultipartIdentifier.CatalogIndex];
463+
if (isTempTable && ADP.IsEmpty(CatalogName))
464+
{
465+
TDSCommand += string.Format("exec tempdb..{0} N'{1}.{2}'",
466+
TableCollationsStoredProc,
467+
SchemaName,
468+
TableName
469+
);
470+
}
471+
else
472+
{
473+
// VSDD 581951 - escape the catalog name
474+
if (!ADP.IsEmpty(CatalogName))
489475
{
490-
// VSDD 581951 - escape the catalog name
491-
if (!ADP.IsEmpty(CatalogName))
492-
{
493-
CatalogName = SqlServerEscapeHelper.EscapeIdentifier(CatalogName);
494-
}
495-
TDSCommand += string.Format("exec {0}..{1} N'{2}.{3}'",
496-
CatalogName,
497-
TableCollationsStoredProc,
498-
SchemaName,
499-
TableName
500-
);
476+
CatalogName = SqlServerEscapeHelper.EscapeIdentifier(CatalogName);
501477
}
478+
TDSCommand += string.Format("exec {0}..{1} N'{2}.{3}'",
479+
CatalogName,
480+
TableCollationsStoredProc,
481+
SchemaName,
482+
TableName
483+
);
502484
}
503485
return TDSCommand;
504486
}
@@ -549,7 +531,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
549531

550532
StringBuilder updateBulkCommandText = new StringBuilder();
551533

552-
if (_connection.Is2000 && 0 == internalResults[CollationResultId].Count)
534+
if (0 == internalResults[CollationResultId].Count)
553535
{
554536
throw SQL.BulkLoadNoCollation();
555537
}
@@ -562,15 +544,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
562544

563545
bool isInTransaction;
564546

565-
if (_parser.Is2005OrNewer)
566-
{
567-
isInTransaction = _connection.HasLocalTransaction;
568-
}
569-
else
570-
{
571-
isInTransaction = (bool)(0 < (SqlInt32)(internalResults[TranCountResultId][TranCountRowId][TranCountValueId]));
572-
}
573-
547+
isInTransaction = _connection.HasLocalTransaction;
574548
// Throw if there is a transaction but no flag is set
575549
if (isInTransaction &&
576550
_externalTransaction == null &&
@@ -701,50 +675,45 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
701675
}
702676
}
703677

704-
if (_connection.Is2000)
705-
{
706-
// 2000 or above!
707-
// get collation for column i
678+
// Get collation for column i
679+
Result rowset = internalResults[CollationResultId];
680+
object rowvalue = rowset[i][CollationId];
708681

709-
Result rowset = internalResults[CollationResultId];
710-
object rowvalue = rowset[i][CollationId];
682+
bool shouldSendCollation;
683+
switch (metadata.type)
684+
{
685+
case SqlDbType.Char:
686+
case SqlDbType.NChar:
687+
case SqlDbType.VarChar:
688+
case SqlDbType.NVarChar:
689+
case SqlDbType.Text:
690+
case SqlDbType.NText:
691+
shouldSendCollation = true;
692+
break;
711693

712-
bool shouldSendCollation;
713-
switch (metadata.type)
714-
{
715-
case SqlDbType.Char:
716-
case SqlDbType.NChar:
717-
case SqlDbType.VarChar:
718-
case SqlDbType.NVarChar:
719-
case SqlDbType.Text:
720-
case SqlDbType.NText:
721-
shouldSendCollation = true;
722-
break;
694+
default:
695+
shouldSendCollation = false;
696+
break;
697+
}
723698

724-
default:
725-
shouldSendCollation = false;
726-
break;
727-
}
699+
if (rowvalue != null && shouldSendCollation)
700+
{
701+
Debug.Assert(rowvalue is SqlString);
702+
SqlString collation_name = (SqlString)rowvalue;
728703

729-
if (rowvalue != null && shouldSendCollation)
704+
if (!collation_name.IsNull)
730705
{
731-
Debug.Assert(rowvalue is SqlString);
732-
SqlString collation_name = (SqlString)rowvalue;
733-
734-
if (!collation_name.IsNull)
706+
updateBulkCommandText.Append(" COLLATE " + collation_name.Value);
707+
// VSTFDEVDIV 461426: compare collations only if the collation value was set on the metadata
708+
if (_sqlDataReaderRowSource != null && metadata.collation != null)
735709
{
736-
updateBulkCommandText.Append(" COLLATE " + collation_name.Value);
737-
// VSTFDEVDIV 461426: compare collations only if the collation value was set on the metadata
738-
if (_sqlDataReaderRowSource != null && metadata.collation != null)
710+
// On SqlDataReader we can verify the sourcecolumn collation!
711+
int sourceColumnId = _localColumnMappings[assocId]._internalSourceColumnOrdinal;
712+
int destinationLcid = metadata.collation.LCID;
713+
int sourceLcid = _sqlDataReaderRowSource.GetLocaleId(sourceColumnId);
714+
if (sourceLcid != destinationLcid)
739715
{
740-
// On SqlDataReader we can verify the sourcecolumn collation!
741-
int sourceColumnId = _localColumnMappings[assocId]._internalSourceColumnOrdinal;
742-
int destinationLcid = metadata.collation.LCID;
743-
int sourceLcid = _sqlDataReaderRowSource.GetLocaleId(sourceColumnId);
744-
if (sourceLcid != destinationLcid)
745-
{
746-
throw SQL.BulkLoadLcidMismatch(sourceLcid, _sqlDataReaderRowSource.GetName(sourceColumnId), destinationLcid, metadata.column);
747-
}
716+
throw SQL.BulkLoadLcidMismatch(sourceLcid, _sqlDataReaderRowSource.GetName(sourceColumnId), destinationLcid, metadata.column);
748717
}
749718
}
750719
}

0 commit comments

Comments
 (0)