From 1e71ea07451e725cc807f7993ffe18b1cedb8ec1 Mon Sep 17 00:00:00 2001 From: Javad Date: Tue, 17 Sep 2019 17:22:20 -0700 Subject: [PATCH 1/9] documentation files updated --- doc/samples/IDbCommand_CommandTimeout.cs | 23 + doc/samples/SqlBulkCopy_ColumnMapping.cs | 92 + .../SqlBulkCopy_ColumnMappingColNameIndex.cs | 85 + .../SqlBulkCopy_ColumnMappingCollection.cs | 85 + ...BulkCopy_ColumnMappingCollectionOrdinal.cs | 85 + .../SqlBulkCopy_ColumnMappingIndexColName.cs | 85 + .../SqlBulkCopy_ColumnMappingOrdersDetails.cs | 168 ++ .../SqlBulkCopy_ColumnMappingRemove.cs | 168 ++ .../SqlBulkCopy_ColumnMappingRemoveAt.cs | 171 ++ doc/samples/SqlBulkCopy_KeepIdentity.cs | 82 + .../SqlClientFactory_DataSourceEnumerator.cs | 39 + ...qlCommand.BeginExecuteReaderAsyncSimple.cs | 102 + doc/samples/SqlCommand.Cancel.cs | 69 + .../SqlCommand_BeginExecuteNonQuery.cs | 85 + .../SqlCommand_BeginExecuteNonQueryForm.cs | 193 ++ ...Command_BeginExecuteReaderAsyncBehavior.cs | 189 ++ .../SqlCommand_BeginExecuteXmlReader.cs | 85 + .../SqlCommand_BeginExecuteXmlReaderAsync.cs | 192 ++ doc/samples/SqlCommand_CommandText.cs | 24 + doc/samples/SqlCommand_Connection.cs | 41 + doc/samples/SqlCommand_ExecuteReader.cs | 34 + doc/samples/SqlCommand_ExecuteReader2.cs | 32 + doc/samples/SqlCommand_SqlCommand1.cs | 24 + .../ApplicationIntent.xml | 25 +- .../OnChangeEventHandler.xml | 17 + .../PoolBlockingPeriod.xml | 20 + .../Microsoft.Data.SqlClient/SQLDebugging.xml | 11 + .../Microsoft.Data.SqlClient/SortOrder.xml | 25 + .../SqlAuthenticationInitializer.xml | 11 + .../SqlAuthenticationMethod.xml | 29 + .../SqlAuthenticationParameters.xml | 60 + .../SqlAuthenticationProvider.xml | 46 + .../SqlAuthenticationToken.xml | 25 + .../Microsoft.Data.SqlClient/SqlBulkCopy.xml | 849 ++++++++ .../SqlBulkCopyColumnMapping.xml | 264 +++ .../SqlBulkCopyColumnMappingCollection.xml | 327 +++ .../SqlBulkCopyOptions.xml | 66 + .../SqlClientFactory.xml | 176 ++ .../SqlClientLogger.xml | 43 + .../SqlClientMetaDataCollectionNames.xml | 38 + .../SqlClientPermission.xml | 88 + .../SqlClientPermissionAttribute.xml | 20 + ...lumnEncryptionCertificateStoreProvider.xml | 54 + .../SqlColumnEncryptionCngProvider.xml | 69 + .../SqlColumnEncryptionCspProvider.xml | 69 + .../SqlColumnEncryptionEnclaveProvider.xml | 56 + .../SqlColumnEncryptionKeyStoreProvider.xml | 65 + .../SqlCommand.SqlCommand2.cs | 40 + .../Microsoft.Data.SqlClient/SqlCommand.xml | 1900 +++++++++++++++++ .../SqlCommandBuilder.xml | 37 + .../Data/SqlClient/ApplicationIntent.cs | 7 +- .../Data/SqlClient/OnChangedEventHandler.cs | 1 + .../Data/SqlClient/PoolBlockingPeriod.cs | 8 +- .../src/Microsoft/Data/SqlClient/SortOrder.cs | 6 + .../SqlClient/SqlAuthenticationParameters.cs | 37 +- .../SqlClient/SqlAuthenticationProvider.cs | 40 +- .../SqlAuthenticationProviderManager.cs | 8 +- .../Data/SqlClient/SqlAuthenticationToken.cs | 17 +- .../Microsoft/Data/SqlClient/SqlBulkCopy.cs | 27 + .../SqlClient/SqlBulkCopyColumnMapping.cs | 11 +- .../SqlBulkCopyColumnMappingCollection.cs | 13 + .../Data/SqlClient/SqlBulkCopyOptions.cs | 16 + .../Data/SqlClient/SqlClientFactory.cs | 7 + .../src/Microsoft/Data/SqlClient/TdsEnums.cs | 10 + .../netfx/ref/Microsoft.Data.SqlClient.cs | 3 +- .../Microsoft/Data/RelationshipConverter.cs | 41 - .../Data/SqlClient/ApplicationIntent.cs | 8 +- .../Data/SqlClient/OnChangedEventHandler.cs | 1 + .../Data/SqlClient/PoolBlockingPeriod.cs | 10 +- .../src/Microsoft/Data/SqlClient/SortOrder.cs | 6 + .../SqlClient/SqlAuthenticationParameters.cs | 37 +- .../SqlClient/SqlAuthenticationProvider.cs | 40 +- .../SqlAuthenticationProviderManager.cs | 10 +- .../Data/SqlClient/SqlAuthenticationToken.cs | 16 +- .../Microsoft/Data/SqlClient/SqlBulkCopy.cs | 35 +- .../SqlClient/SqlBulkCopyColumnMapping.cs | 11 +- .../SqlBulkCopyColumnMappingCollection.cs | 15 +- .../Data/SqlClient/SqlBulkCopyOptions.cs | 17 +- .../Data/SqlClient/SqlClientFactory.cs | 11 +- .../src/Microsoft/Data/SqlClient/TdsEnums.cs | 10 + 80 files changed, 6835 insertions(+), 227 deletions(-) create mode 100644 doc/samples/IDbCommand_CommandTimeout.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMapping.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingColNameIndex.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingCollection.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingOrdersDetails.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingRemove.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingRemoveAt.cs create mode 100644 doc/samples/SqlBulkCopy_KeepIdentity.cs create mode 100644 doc/samples/SqlClientFactory_DataSourceEnumerator.cs create mode 100644 doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs create mode 100644 doc/samples/SqlCommand.Cancel.cs create mode 100644 doc/samples/SqlCommand_BeginExecuteNonQuery.cs create mode 100644 doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs create mode 100644 doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs create mode 100644 doc/samples/SqlCommand_BeginExecuteXmlReader.cs create mode 100644 doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs create mode 100644 doc/samples/SqlCommand_CommandText.cs create mode 100644 doc/samples/SqlCommand_Connection.cs create mode 100644 doc/samples/SqlCommand_ExecuteReader.cs create mode 100644 doc/samples/SqlCommand_ExecuteReader2.cs create mode 100644 doc/samples/SqlCommand_SqlCommand1.cs create mode 100644 doc/snippets/Microsoft.Data.SqlClient/OnChangeEventHandler.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SortOrder.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMappingCollection.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyOptions.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlClientPermissionAttribute.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml create mode 100644 doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml diff --git a/doc/samples/IDbCommand_CommandTimeout.cs b/doc/samples/IDbCommand_CommandTimeout.cs new file mode 100644 index 0000000000..4b2b5c675e --- /dev/null +++ b/doc/samples/IDbCommand_CommandTimeout.cs @@ -0,0 +1,23 @@ +using System; +using System.Xml; +using System.Data; +using Microsoft.Data.SqlClient; +using System.Data.Common; +using System.Windows.Forms; + +public class Form1: Form +{ + protected DataSet DataSet1; + protected DataGrid dataGrid1; + + +// + public void CreateSqlCommand() + { + SqlCommand command = new SqlCommand(); + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + } +// + +} \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_ColumnMapping.cs b/doc/samples/SqlBulkCopy_ColumnMapping.cs new file mode 100644 index 0000000000..5f1c1d12f2 --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMapping.cs @@ -0,0 +1,92 @@ +using System; +using System.Data; +// +using Microsoft..Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // Set up the column mappings by name. + SqlBulkCopyColumnMapping mapID = + new SqlBulkCopyColumnMapping("ProductID", "ProdID"); + bulkCopy.ColumnMappings.Add(mapID); + + SqlBulkCopyColumnMapping mapName = + new SqlBulkCopyColumnMapping("Name", "ProdName"); + bulkCopy.ColumnMappings.Add(mapName); + + SqlBulkCopyColumnMapping mapMumber = + new SqlBulkCopyColumnMapping("ProductNumber", "ProdNum"); + bulkCopy.ColumnMappings.Add(mapMumber); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_ColumnMappingColNameIndex.cs b/doc/samples/SqlBulkCopy_ColumnMappingColNameIndex.cs new file mode 100644 index 0000000000..ac4f3f3cad --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingColNameIndex.cs @@ -0,0 +1,85 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // The column order in the source doesn't match the order + // in the destination, so ColumnMappings must be defined. + bulkCopy.ColumnMappings.Add(0, 0); + bulkCopy.ColumnMappings.Add(1, 2); + bulkCopy.ColumnMappings.Add(2, 1); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs b/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs new file mode 100644 index 0000000000..7db2818f0c --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs @@ -0,0 +1,85 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // The column order in the source doesn't match the order + // in the destination, so ColumnMappings must be defined. + bulkCopy.ColumnMappings.Add("ProductID", "ProdID"); + bulkCopy.ColumnMappings.Add("Name", "ProdName"); + bulkCopy.ColumnMappings.Add("ProductNumber", "ProdNum"); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs b/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs new file mode 100644 index 0000000000..ac4f3f3cad --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs @@ -0,0 +1,85 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // The column order in the source doesn't match the order + // in the destination, so ColumnMappings must be defined. + bulkCopy.ColumnMappings.Add(0, 0); + bulkCopy.ColumnMappings.Add(1, 2); + bulkCopy.ColumnMappings.Add(2, 1); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs b/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs new file mode 100644 index 0000000000..ac4f3f3cad --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs @@ -0,0 +1,85 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // The column order in the source doesn't match the order + // in the destination, so ColumnMappings must be defined. + bulkCopy.ColumnMappings.Add(0, 0); + bulkCopy.ColumnMappings.Add(1, 2); + bulkCopy.ColumnMappings.Add(2, 1); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_ColumnMappingOrdersDetails.cs b/doc/samples/SqlBulkCopy_ColumnMappingOrdersDetails.cs new file mode 100644 index 0000000000..ce2742d250 --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingOrdersDetails.cs @@ -0,0 +1,168 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a connection to the AdventureWorks database. + using (SqlConnection connection = + new SqlConnection(connectionString)) + { + connection.Open(); + + // Empty the destination tables. + SqlCommand deleteHeader = new SqlCommand( + "DELETE FROM dbo.BulkCopyDemoOrderHeader;", + connection); + deleteHeader.ExecuteNonQuery(); + SqlCommand deleteDetail = new SqlCommand( + "DELETE FROM dbo.BulkCopyDemoOrderDetail;", + connection); + deleteDetail.ExecuteNonQuery(); + + // Perform an initial count on the destination + // table with matching columns. + SqlCommand countRowHeader = new SqlCommand( + "SELECT COUNT(*) FROM dbo.BulkCopyDemoOrderHeader;", + connection); + long countStartHeader = System.Convert.ToInt32( + countRowHeader.ExecuteScalar()); + Console.WriteLine( + "Starting row count for Header table = {0}", + countStartHeader); + + // Perform an initial count on the destination + // table with different column positions. + SqlCommand countRowDetail = new SqlCommand( + "SELECT COUNT(*) FROM dbo.BulkCopyDemoOrderDetail;", + connection); + long countStartDetail = System.Convert.ToInt32( + countRowDetail.ExecuteScalar()); + Console.WriteLine( + "Starting row count for Detail table = {0}", + countStartDetail); + + // Get data from the source table as a SqlDataReader. + // The Sales.SalesOrderHeader and Sales.SalesOrderDetail + // tables are quite large and could easily cause a timeout + // if all data from the tables is added to the destination. + // To keep the example simple and quick, a parameter is + // used to select only orders for a particular account + // as the source for the bulk insert. + SqlCommand headerData = new SqlCommand( + "SELECT [SalesOrderID], [OrderDate], " + + "[AccountNumber] FROM [Sales].[SalesOrderHeader] " + + "WHERE [AccountNumber] = @accountNumber;", + connection); + SqlParameter parameterAccount = new SqlParameter(); + parameterAccount.ParameterName = "@accountNumber"; + parameterAccount.SqlDbType = SqlDbType.NVarChar; + parameterAccount.Direction = ParameterDirection.Input; + parameterAccount.Value = "10-4020-000034"; + headerData.Parameters.Add(parameterAccount); + SqlDataReader readerHeader = headerData.ExecuteReader(); + + // Get the Detail data in a separate connection. + using (SqlConnection connection2 = new SqlConnection(connectionString)) + { + connection2.Open(); + SqlCommand sourceDetailData = new SqlCommand( + "SELECT [Sales].[SalesOrderDetail].[SalesOrderID], [SalesOrderDetailID], " + + "[OrderQty], [ProductID], [UnitPrice] FROM [Sales].[SalesOrderDetail] " + + "INNER JOIN [Sales].[SalesOrderHeader] ON [Sales].[SalesOrderDetail]." + + "[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID] " + + "WHERE [AccountNumber] = @accountNumber;", connection2); + + SqlParameter accountDetail = new SqlParameter(); + accountDetail.ParameterName = "@accountNumber"; + accountDetail.SqlDbType = SqlDbType.NVarChar; + accountDetail.Direction = ParameterDirection.Input; + accountDetail.Value = "10-4020-000034"; + sourceDetailData.Parameters.Add(accountDetail); + SqlDataReader readerDetail = sourceDetailData.ExecuteReader(); + + // Create the SqlBulkCopy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoOrderHeader"; + + // Guarantee that columns are mapped correctly by + // defining the column mappings for the order. + bulkCopy.ColumnMappings.Add("SalesOrderID", "SalesOrderID"); + bulkCopy.ColumnMappings.Add("OrderDate", "OrderDate"); + bulkCopy.ColumnMappings.Add("AccountNumber", "AccountNumber"); + + // Write readerHeader to the destination. + try + { + bulkCopy.WriteToServer(readerHeader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + readerHeader.Close(); + } + + // Set up the order details destination. + bulkCopy.DestinationTableName ="dbo.BulkCopyDemoOrderDetail"; + + // Clear the ColumnMappingCollection. + bulkCopy.ColumnMappings.Clear(); + + // Add order detail column mappings. + bulkCopy.ColumnMappings.Add("SalesOrderID", "SalesOrderID"); + bulkCopy.ColumnMappings.Add("SalesOrderDetailID", "SalesOrderDetailID"); + bulkCopy.ColumnMappings.Add("OrderQty", "OrderQty"); + bulkCopy.ColumnMappings.Add("ProductID", "ProductID"); + bulkCopy.ColumnMappings.Add("UnitPrice", "UnitPrice"); + + // Write readerDetail to the destination. + try + { + bulkCopy.WriteToServer(readerDetail); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + readerDetail.Close(); + } + } + + // Perform a final count on the destination + // tables to see how many rows were added. + long countEndHeader = System.Convert.ToInt32( + countRowHeader.ExecuteScalar()); + Console.WriteLine("{0} rows were added to the Header table.", + countEndHeader - countStartHeader); + long countEndDetail = System.Convert.ToInt32( + countRowDetail.ExecuteScalar()); + Console.WriteLine("{0} rows were added to the Detail table.", + countEndDetail - countStartDetail); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + } + + private static string GetConnectionString() + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs b/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs new file mode 100644 index 0000000000..ce2742d250 --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs @@ -0,0 +1,168 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a connection to the AdventureWorks database. + using (SqlConnection connection = + new SqlConnection(connectionString)) + { + connection.Open(); + + // Empty the destination tables. + SqlCommand deleteHeader = new SqlCommand( + "DELETE FROM dbo.BulkCopyDemoOrderHeader;", + connection); + deleteHeader.ExecuteNonQuery(); + SqlCommand deleteDetail = new SqlCommand( + "DELETE FROM dbo.BulkCopyDemoOrderDetail;", + connection); + deleteDetail.ExecuteNonQuery(); + + // Perform an initial count on the destination + // table with matching columns. + SqlCommand countRowHeader = new SqlCommand( + "SELECT COUNT(*) FROM dbo.BulkCopyDemoOrderHeader;", + connection); + long countStartHeader = System.Convert.ToInt32( + countRowHeader.ExecuteScalar()); + Console.WriteLine( + "Starting row count for Header table = {0}", + countStartHeader); + + // Perform an initial count on the destination + // table with different column positions. + SqlCommand countRowDetail = new SqlCommand( + "SELECT COUNT(*) FROM dbo.BulkCopyDemoOrderDetail;", + connection); + long countStartDetail = System.Convert.ToInt32( + countRowDetail.ExecuteScalar()); + Console.WriteLine( + "Starting row count for Detail table = {0}", + countStartDetail); + + // Get data from the source table as a SqlDataReader. + // The Sales.SalesOrderHeader and Sales.SalesOrderDetail + // tables are quite large and could easily cause a timeout + // if all data from the tables is added to the destination. + // To keep the example simple and quick, a parameter is + // used to select only orders for a particular account + // as the source for the bulk insert. + SqlCommand headerData = new SqlCommand( + "SELECT [SalesOrderID], [OrderDate], " + + "[AccountNumber] FROM [Sales].[SalesOrderHeader] " + + "WHERE [AccountNumber] = @accountNumber;", + connection); + SqlParameter parameterAccount = new SqlParameter(); + parameterAccount.ParameterName = "@accountNumber"; + parameterAccount.SqlDbType = SqlDbType.NVarChar; + parameterAccount.Direction = ParameterDirection.Input; + parameterAccount.Value = "10-4020-000034"; + headerData.Parameters.Add(parameterAccount); + SqlDataReader readerHeader = headerData.ExecuteReader(); + + // Get the Detail data in a separate connection. + using (SqlConnection connection2 = new SqlConnection(connectionString)) + { + connection2.Open(); + SqlCommand sourceDetailData = new SqlCommand( + "SELECT [Sales].[SalesOrderDetail].[SalesOrderID], [SalesOrderDetailID], " + + "[OrderQty], [ProductID], [UnitPrice] FROM [Sales].[SalesOrderDetail] " + + "INNER JOIN [Sales].[SalesOrderHeader] ON [Sales].[SalesOrderDetail]." + + "[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID] " + + "WHERE [AccountNumber] = @accountNumber;", connection2); + + SqlParameter accountDetail = new SqlParameter(); + accountDetail.ParameterName = "@accountNumber"; + accountDetail.SqlDbType = SqlDbType.NVarChar; + accountDetail.Direction = ParameterDirection.Input; + accountDetail.Value = "10-4020-000034"; + sourceDetailData.Parameters.Add(accountDetail); + SqlDataReader readerDetail = sourceDetailData.ExecuteReader(); + + // Create the SqlBulkCopy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoOrderHeader"; + + // Guarantee that columns are mapped correctly by + // defining the column mappings for the order. + bulkCopy.ColumnMappings.Add("SalesOrderID", "SalesOrderID"); + bulkCopy.ColumnMappings.Add("OrderDate", "OrderDate"); + bulkCopy.ColumnMappings.Add("AccountNumber", "AccountNumber"); + + // Write readerHeader to the destination. + try + { + bulkCopy.WriteToServer(readerHeader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + readerHeader.Close(); + } + + // Set up the order details destination. + bulkCopy.DestinationTableName ="dbo.BulkCopyDemoOrderDetail"; + + // Clear the ColumnMappingCollection. + bulkCopy.ColumnMappings.Clear(); + + // Add order detail column mappings. + bulkCopy.ColumnMappings.Add("SalesOrderID", "SalesOrderID"); + bulkCopy.ColumnMappings.Add("SalesOrderDetailID", "SalesOrderDetailID"); + bulkCopy.ColumnMappings.Add("OrderQty", "OrderQty"); + bulkCopy.ColumnMappings.Add("ProductID", "ProductID"); + bulkCopy.ColumnMappings.Add("UnitPrice", "UnitPrice"); + + // Write readerDetail to the destination. + try + { + bulkCopy.WriteToServer(readerDetail); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + readerDetail.Close(); + } + } + + // Perform a final count on the destination + // tables to see how many rows were added. + long countEndHeader = System.Convert.ToInt32( + countRowHeader.ExecuteScalar()); + Console.WriteLine("{0} rows were added to the Header table.", + countEndHeader - countStartHeader); + long countEndDetail = System.Convert.ToInt32( + countRowDetail.ExecuteScalar()); + Console.WriteLine("{0} rows were added to the Detail table.", + countEndDetail - countStartDetail); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + } + + private static string GetConnectionString() + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_ColumnMappingRemoveAt.cs b/doc/samples/SqlBulkCopy_ColumnMappingRemoveAt.cs new file mode 100644 index 0000000000..0d6c51fc1d --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingRemoveAt.cs @@ -0,0 +1,171 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a connection to the AdventureWorks database. + using (SqlConnection connection = + new SqlConnection(connectionString)) + { + connection.Open(); + + // Empty the destination tables. + SqlCommand deleteHeader = new SqlCommand( + "DELETE FROM dbo.BulkCopyDemoOrderHeader;", + connection); + deleteHeader.ExecuteNonQuery(); + SqlCommand deleteDetail = new SqlCommand( + "DELETE FROM dbo.BulkCopyDemoOrderDetail;", + connection); + deleteDetail.ExecuteNonQuery(); + + // Perform an initial count on the destination + // table with matching columns. + SqlCommand countRowHeader = new SqlCommand( + "SELECT COUNT(*) FROM dbo.BulkCopyDemoOrderHeader;", + connection); + long countStartHeader = System.Convert.ToInt32( + countRowHeader.ExecuteScalar()); + Console.WriteLine( + "Starting row count for Header table = {0}", + countStartHeader); + + // Perform an initial count on the destination + // table with different column positions. + SqlCommand countRowDetail = new SqlCommand( + "SELECT COUNT(*) FROM dbo.BulkCopyDemoOrderDetail;", + connection); + long countStartDetail = System.Convert.ToInt32( + countRowDetail.ExecuteScalar()); + Console.WriteLine( + "Starting row count for Detail table = {0}", + countStartDetail); + + // Get data from the source table as a SqlDataReader. + // The Sales.SalesOrderHeader and Sales.SalesOrderDetail + // tables are quite large and could easily cause a timeout + // if all data from the tables is added to the destination. + // To keep the example simple and quick, a parameter is + // used to select only orders for a particular account + // as the source for the bulk insert. + SqlCommand headerData = new SqlCommand( + "SELECT [SalesOrderID], [OrderDate], " + + "[AccountNumber] FROM [Sales].[SalesOrderHeader] " + + "WHERE [AccountNumber] = @accountNumber;", + connection); + SqlParameter parameterAccount = new SqlParameter(); + parameterAccount.ParameterName = "@accountNumber"; + parameterAccount.SqlDbType = SqlDbType.NVarChar; + parameterAccount.Direction = ParameterDirection.Input; + parameterAccount.Value = "10-4020-000034"; + headerData.Parameters.Add(parameterAccount); + SqlDataReader readerHeader = headerData.ExecuteReader(); + + // Get the Detail data in a separate connection. + using (SqlConnection connection2 = new SqlConnection(connectionString)) + { + connection2.Open(); + SqlCommand sourceDetailData = new SqlCommand( + "SELECT [Sales].[SalesOrderDetail].[SalesOrderID], [SalesOrderDetailID], " + + "[OrderQty], [ProductID], [UnitPrice] FROM [Sales].[SalesOrderDetail] " + + "INNER JOIN [Sales].[SalesOrderHeader] ON [Sales].[SalesOrderDetail]." + + "[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID] " + + "WHERE [AccountNumber] = @accountNumber;", connection2); + + SqlParameter accountDetail = new SqlParameter(); + accountDetail.ParameterName = "@accountNumber"; + accountDetail.SqlDbType = SqlDbType.NVarChar; + accountDetail.Direction = ParameterDirection.Input; + accountDetail.Value = "10-4020-000034"; + sourceDetailData.Parameters.Add(accountDetail); + SqlDataReader readerDetail = sourceDetailData.ExecuteReader(); + + // Create the SqlBulkCopy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoOrderHeader"; + + // Guarantee that columns are mapped correctly by + // defining the column mappings for the order. + bulkCopy.ColumnMappings.Add("SalesOrderID", "SalesOrderID"); + bulkCopy.ColumnMappings.Add("OrderDate", "OrderDate"); + bulkCopy.ColumnMappings.Add("AccountNumber", "AccountNumber"); + + // Write readerHeader to the destination. + try + { + bulkCopy.WriteToServer(readerHeader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + readerHeader.Close(); + } + + // Set up the order details destination. + bulkCopy.DestinationTableName ="dbo.BulkCopyDemoOrderDetail"; + + // Rather than clearing mappings that are not necessary + // for the next bulk copyo peration, the unneeded mappings + // are removed with the RemoveAt method. + bulkCopy.ColumnMappings.RemoveAt(2); + bulkCopy.ColumnMappings.RemoveAt(1); + + // Add order detail column mappings. + bulkCopy.ColumnMappings.Add("SalesOrderDetailID", "SalesOrderDetailID"); + bulkCopy.ColumnMappings.Add("OrderQty", "OrderQty"); + bulkCopy.ColumnMappings.Add("ProductID", "ProductID"); + bulkCopy.ColumnMappings.Add("UnitPrice", "UnitPrice"); + bulkCopy.WriteToServer(readerDetail); + + // Write readerDetail to the destination. + try + { + bulkCopy.WriteToServer(readerDetail); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + readerDetail.Close(); + } + } + + // Perform a final count on the destination + // tables to see how many rows were added. + long countEndHeader = System.Convert.ToInt32( + countRowHeader.ExecuteScalar()); + Console.WriteLine("{0} rows were added to the Header table.", + countEndHeader - countStartHeader); + long countEndDetail = System.Convert.ToInt32( + countRowDetail.ExecuteScalar()); + Console.WriteLine("{0} rows were added to the Detail table.", + countEndDetail - countStartDetail); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + } + + private static string GetConnectionString() + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlBulkCopy_KeepIdentity.cs b/doc/samples/SqlBulkCopy_KeepIdentity.cs new file mode 100644 index 0000000000..20b13bf5ab --- /dev/null +++ b/doc/samples/SqlBulkCopy_KeepIdentity.cs @@ -0,0 +1,82 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoMatchingColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Create the SqlBulkCopy object using a connection string + // and the KeepIdentity option. + // In the real world you would not use SqlBulkCopy to move + // data from one table to the other in the same database. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoMatchingColumns"; + + try + { + // Write from the source to the destination. + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlClientFactory_DataSourceEnumerator.cs b/doc/samples/SqlClientFactory_DataSourceEnumerator.cs new file mode 100644 index 0000000000..3429ea4e4c --- /dev/null +++ b/doc/samples/SqlClientFactory_DataSourceEnumerator.cs @@ -0,0 +1,39 @@ +// +using System; +using System.Data; +using System.Data.Common; +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + // List all SQL Server instances: + ListServers(SqlClientFactory.Instance); + + Console.WriteLine(); + Console.WriteLine("Press any key to continue..."); + Console.ReadKey(); + } + private static void ListServers(DbProviderFactory factory) + { + // This procedure is provider-agnostic, and can list + // instances of any provider's servers. Of course, + // not all providers can create a data source enumerator, + // so it's best to check the CanCreateDataSourceEnumerator + // property before attempting to list the data sources. + if (factory.CanCreateDataSourceEnumerator) + { + DbDataSourceEnumerator instance = + factory.CreateDataSourceEnumerator(); + DataTable table = instance.GetDataSources(); + + foreach (DataRow row in table.Rows) + { + Console.WriteLine("{0}\\{1}", + row["ServerName"], row["InstanceName"]); + } + } + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs b/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs new file mode 100644 index 0000000000..ca54cf210a --- /dev/null +++ b/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs @@ -0,0 +1,102 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; +class Class1 +{ + static void Main() + { + // This example is not terribly useful, but it proves a point. + // The WAITFOR statement simply adds enough time to prove the + // asynchronous nature of the command. + string commandText = "WAITFOR DELAY '00:00:03';" + + "SELECT ProductID, Name FROM Production.Product WHERE ListPrice < 100"; + + RunCommandAsynchronously(commandText, GetConnectionString()); + + Console.WriteLine("Press ENTER to continue."); + Console.ReadLine(); + } + + private static void RunCommandAsynchronously( + string commandText, string connectionString) + { + // Given command text and connection string, asynchronously execute + // the specified command against the connection. For this example, + // the code displays an indicator as it is working, verifying the + // asynchronous behavior. + + try + { + // The code does not need to handle closing the connection explicitly-- + // the use of the CommandBehavior.CloseConnection option takes care + // of that for you. + SqlConnection connection = new SqlConnection(connectionString); + SqlCommand command = new SqlCommand(commandText, connection); + + connection.Open(); + IAsyncResult result = command.BeginExecuteReader( + CommandBehavior.CloseConnection); + + // Although it is not necessary, the following code + // displays a counter in the console window, indicating that + // the main thread is not blocked while awaiting the command + // results. + int count = 0; + while (!result.IsCompleted) + { + Console.WriteLine("Waiting ({0})", count++); + // Wait for 1/10 second, so the counter + // does not consume all available resources + // on the main thread. + System.Threading.Thread.Sleep(100); + } + + using (SqlDataReader reader = command.EndExecuteReader(result)) + { + DisplayResults(reader); + } + } + catch (SqlException ex) + { + Console.WriteLine("Error ({0}): {1}", ex.Number, ex.Message); + } + catch (InvalidOperationException ex) + { + Console.WriteLine("Error: {0}", ex.Message); + } + catch (Exception ex) + { + // You might want to pass these errors + // back out to the caller. + Console.WriteLine("Error: {0}", ex.Message); + } + } + + private static void DisplayResults(SqlDataReader reader) + { + // Display the data within the reader. + while (reader.Read()) + { + // Display all the columns. + for (int i = 0; i < reader.FieldCount; i++) + { + Console.Write("{0}\t", reader.GetValue(i)); + } + Console.WriteLine(); + } + } + + private static string GetConnectionString() + { + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + + // If you have not included "Asynchronous Processing=true" in the + // connection string, the command is not able + // to execute asynchronously. + return "Data Source=(local);Integrated Security=true;" + + "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlCommand.Cancel.cs b/doc/samples/SqlCommand.Cancel.cs new file mode 100644 index 0000000000..7d631829a5 --- /dev/null +++ b/doc/samples/SqlCommand.Cancel.cs @@ -0,0 +1,69 @@ +// +using System; +using System.Data; +using Microsoft.Data.SqlClient; +using System.Threading; + +class Program +{ + private static SqlCommand m_rCommand; + + public static SqlCommand Command + { + get { return m_rCommand; } + set { m_rCommand = value; } + } + + public static void Thread_Cancel() + { + Command.Cancel(); + } + + static void Main() + { + string connectionString = GetConnectionString(); + try + { + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + + Command = connection.CreateCommand(); + Command.CommandText = "DROP TABLE TestCancel"; + try + { + Command.ExecuteNonQuery(); + } + catch { } + + Command.CommandText = "CREATE TABLE TestCancel(co1 int, co2 char(10))"; + Command.ExecuteNonQuery(); + Command.CommandText = "INSERT INTO TestCancel VALUES (1, '1')"; + Command.ExecuteNonQuery(); + + Command.CommandText = "SELECT * FROM TestCancel"; + SqlDataReader reader = Command.ExecuteReader(); + + Thread rThread2 = new Thread(new ThreadStart(Thread_Cancel)); + rThread2.Start(); + rThread2.Join(); + + reader.Read(); + System.Console.WriteLine(reader.FieldCount); + reader.Close(); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + static private string GetConnectionString() + { + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + return "Data Source=(local);Initial Catalog=AdventureWorks;" + + "Integrated Security=SSPI"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlCommand_BeginExecuteNonQuery.cs b/doc/samples/SqlCommand_BeginExecuteNonQuery.cs new file mode 100644 index 0000000000..2e1f72719e --- /dev/null +++ b/doc/samples/SqlCommand_BeginExecuteNonQuery.cs @@ -0,0 +1,85 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Class1 +{ + static void Main() + { + // This is a simple example that demonstrates the usage of the + // BeginExecuteNonQuery functionality. + // The WAITFOR statement simply adds enough time to prove the + // asynchronous nature of the command. + + string commandText = + "UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 " + + "WHERE ReorderPoint Is Not Null;" + + "WAITFOR DELAY '0:0:3';" + + "UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 " + + "WHERE ReorderPoint Is Not Null"; + + RunCommandAsynchronously(commandText, GetConnectionString()); + + Console.WriteLine("Press ENTER to continue."); + Console.ReadLine(); + } + + private static void RunCommandAsynchronously( + string commandText, string connectionString) + { + // Given command text and connection string, asynchronously execute + // the specified command against the connection. For this example, + // the code displays an indicator as it is working, verifying the + // asynchronous behavior. + using (SqlConnection connection = + new SqlConnection(connectionString)) + { + try + { + int count = 0; + SqlCommand command = new SqlCommand(commandText, connection); + connection.Open(); + + IAsyncResult result = command.BeginExecuteNonQuery(); + while (!result.IsCompleted) + { + Console.WriteLine("Waiting ({0})", count++); + // Wait for 1/10 second, so the counter + // does not consume all available resources + // on the main thread. + System.Threading.Thread.Sleep(100); + } + Console.WriteLine("Command complete. Affected {0} rows.", + command.EndExecuteNonQuery(result)); + } + catch (SqlException ex) + { + Console.WriteLine("Error ({0}): {1}", ex.Number, ex.Message); + } + catch (InvalidOperationException ex) + { + Console.WriteLine("Error: {0}", ex.Message); + } + catch (Exception ex) + { + // You might want to pass these errors + // back out to the caller. + Console.WriteLine("Error: {0}", ex.Message); + } + } + } + + private static string GetConnectionString() + { + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + + // If you have not included "Asynchronous Processing=true" in the + // connection string, the command is not able + // to execute asynchronously. + return "Data Source=(local);Integrated Security=SSPI;" + + "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs b/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs new file mode 100644 index 0000000000..1b342459a8 --- /dev/null +++ b/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs @@ -0,0 +1,193 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +// +using System.Data.SqlClient; + +namespace Microsoft.AdoDotNet.CodeSamples +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + + // Hook up the form's Load event handler (you can double-click on + // the form's design surface in Visual Studio), and then add + // this code to the form's class: + private void Form1_Load(object sender, EventArgs e) + { + this.button1.Click += new System.EventHandler(this.button1_Click); + this.FormClosing += new System.Windows.Forms. + FormClosingEventHandler(this.Form1_FormClosing); + + } + + // You need this delegate in order to display text from a thread + // other than the form's thread. See the HandleCallback + // procedure for more information. + // This same delegate matches both the DisplayStatus + // and DisplayResults methods. + private delegate void DisplayInfoDelegate(string Text); + + // This flag ensures that the user does not attempt + // to restart the command or close the form while the + // asynchronous command is executing. + private bool isExecuting; + + // This example maintains the connection object + // externally, so that it is available for closing. + private SqlConnection connection; + + private static string GetConnectionString() + { + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + + // If you have not included "Asynchronous Processing=true" in the + // connection string, the command is not able + // to execute asynchronously. + return "Data Source=(local);Integrated Security=true;" + + "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; + } + + private void DisplayStatus(string Text) + { + this.label1.Text = Text; + } + + private void DisplayResults(string Text) + { + this.label1.Text = Text; + DisplayStatus("Ready"); + } + + private void Form1_FormClosing(object sender, + System.Windows.Forms.FormClosingEventArgs e) + { + if (isExecuting) + { + MessageBox.Show(this, "Cannot close the form until " + + "the pending asynchronous command has completed. Please wait..."); + e.Cancel = true; + } + } + + private void button1_Click(object sender, System.EventArgs e) + { + if (isExecuting) + { + MessageBox.Show(this, + "Already executing. Please wait until the current query " + + "has completed."); + } + else + { + SqlCommand command = null; + try + { + DisplayResults(""); + DisplayStatus("Connecting..."); + connection = new SqlConnection(GetConnectionString()); + // To emulate a long-running query, wait for + // a few seconds before working with the data. + // This command does not do much, but that's the point-- + // it does not change your data, in the long run. + string commandText = + "WAITFOR DELAY '0:0:05';" + + "UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 " + + "WHERE ReorderPoint Is Not Null;" + + "UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 " + + "WHERE ReorderPoint Is Not Null"; + + command = new SqlCommand(commandText, connection); + connection.Open(); + + DisplayStatus("Executing..."); + isExecuting = true; + // Although it is not required that you pass the + // SqlCommand object as the second parameter in the + // BeginExecuteNonQuery call, doing so makes it easier + // to call EndExecuteNonQuery in the callback procedure. + AsyncCallback callback = new AsyncCallback(HandleCallback); + command.BeginExecuteNonQuery(callback, command); + + } + catch (Exception ex) + { + isExecuting = false; + DisplayStatus(string.Format("Ready (last error: {0})", ex.Message)); + if (connection != null) + { + connection.Close(); + } + } + } + } + + private void HandleCallback(IAsyncResult result) + { + try + { + // Retrieve the original command object, passed + // to this procedure in the AsyncState property + // of the IAsyncResult parameter. + SqlCommand command = (SqlCommand)result.AsyncState; + int rowCount = command.EndExecuteNonQuery(result); + string rowText = " rows affected."; + if (rowCount == 1) + { + rowText = " row affected."; + } + rowText = rowCount + rowText; + + // You may not interact with the form and its contents + // from a different thread, and this callback procedure + // is all but guaranteed to be running from a different thread + // than the form. Therefore you cannot simply call code that + // displays the results, like this: + // DisplayResults(rowText) + + // Instead, you must call the procedure from the form's thread. + // One simple way to accomplish this is to call the Invoke + // method of the form, which calls the delegate you supply + // from the form's thread. + DisplayInfoDelegate del = new DisplayInfoDelegate(DisplayResults); + this.Invoke(del, rowText); + + } + catch (Exception ex) + { + // Because you are now running code in a separate thread, + // if you do not handle the exception here, none of your other + // code catches the exception. Because none of + // your code is on the call stack in this thread, there is nothing + // higher up the stack to catch the exception if you do not + // handle it here. You can either log the exception or + // invoke a delegate (as in the non-error case in this + // example) to display the error on the form. In no case + // can you simply display the error without executing a delegate + // as in the try block here. + + // You can create the delegate instance as you + // invoke it, like this: + this.Invoke(new DisplayInfoDelegate(DisplayStatus), + String.Format("Ready(last error: {0}", ex.Message)); + } + finally + { + isExecuting = false; + if (connection != null) + { + connection.Close(); + } + } + } + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs b/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs new file mode 100644 index 0000000000..c815a80edb --- /dev/null +++ b/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs @@ -0,0 +1,189 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +// +using Microsoft.Data.SqlClient; + +namespace Microsoft.AdoDotNet.CodeSamples +{ + public partial class Form1 : Form + { + public Form1() + { + InitializeComponent(); + } + // Hook up the form's Load event handler (you can double-click on + // the form's design surface in Visual Studio), and then add + // this code to the form's class: + // You need this delegate in order to fill the grid from + // a thread other than the form's thread. See the HandleCallback + // procedure for more information. + private delegate void FillGridDelegate(SqlDataReader reader); + + // You need this delegate to update the status bar. + private delegate void DisplayStatusDelegate(string Text); + + // This flag ensures that the user does not attempt + // to restart the command or close the form while the + // asynchronous command is executing. + private bool isExecuting; + + private void DisplayStatus(string Text) + { + this.label1.Text = Text; + } + + private void FillGrid(SqlDataReader reader) + { + try + { + DataTable table = new DataTable(); + table.Load(reader); + this.dataGridView1.DataSource = table; + DisplayStatus("Ready"); + } + catch (Exception ex) + { + // Because you are guaranteed this procedure + // is running from within the form's thread, + // it can directly interact with members of the form. + DisplayStatus(string.Format("Ready (last attempt failed: {0})", + ex.Message)); + } + finally + { + // Closing the reader also closes the connection, + // because this reader was created using the + // CommandBehavior.CloseConnection value. + if (reader != null) + { + reader.Close(); + } + } + } + + private void HandleCallback(IAsyncResult result) + { + try + { + // Retrieve the original command object, passed + // to this procedure in the AsyncState property + // of the IAsyncResult parameter. + SqlCommand command = (SqlCommand)result.AsyncState; + SqlDataReader reader = command.EndExecuteReader(result); + // You may not interact with the form and its contents + // from a different thread, and this callback procedure + // is all but guaranteed to be running from a different thread + // than the form. Therefore you cannot simply call code that + // fills the grid, like this: + // FillGrid(reader); + // Instead, you must call the procedure from the form's thread. + // One simple way to accomplish this is to call the Invoke + // method of the form, which calls the delegate you supply + // from the form's thread. + FillGridDelegate del = new FillGridDelegate(FillGrid); + this.Invoke(del, reader); + // Do not close the reader here, because it is being used in + // a separate thread. Instead, have the procedure you have + // called close the reader once it is done with it. + } + catch (Exception ex) + { + // Because you are now running code in a separate thread, + // if you do not handle the exception here, none of your other + // code catches the exception. Because there is none of + // your code on the call stack in this thread, there is nothing + // higher up the stack to catch the exception if you do not + // handle it here. You can either log the exception or + // invoke a delegate (as in the non-error case in this + // example) to display the error on the form. In no case + // can you simply display the error without executing a delegate + // as in the try block here. + // You can create the delegate instance as you + // invoke it, like this: + this.Invoke(new DisplayStatusDelegate(DisplayStatus), "Error: " + + ex.Message); + } + finally + { + isExecuting = false; + } + } + + private string GetConnectionString() + { + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + + // If you do not include the Asynchronous Processing=true name/value pair, + // you wo not be able to execute the command asynchronously. + return "Data Source=(local);Integrated Security=true;" + + "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; + } + + private void button1_Click(object sender, System.EventArgs e) + { + if (isExecuting) + { + MessageBox.Show(this, + "Already executing. Please wait until the current query " + + "has completed."); + } + else + { + SqlCommand command = null; + SqlConnection connection = null; + try + { + DisplayStatus("Connecting..."); + connection = new SqlConnection(GetConnectionString()); + // To emulate a long-running query, wait for + // a few seconds before retrieving the real data. + command = new SqlCommand("WAITFOR DELAY '0:0:5';" + + "SELECT ProductID, Name, ListPrice, Weight FROM Production.Product", + connection); + connection.Open(); + + DisplayStatus("Executing..."); + isExecuting = true; + // Although it is not required that you pass the + // SqlCommand object as the second parameter in the + // BeginExecuteReader call, doing so makes it easier + // to call EndExecuteReader in the callback procedure. + AsyncCallback callback = new AsyncCallback(HandleCallback); + command.BeginExecuteReader(callback, command, + CommandBehavior.CloseConnection); + } + catch (Exception ex) + { + DisplayStatus("Error: " + ex.Message); + if (connection != null) + { + connection.Close(); + } + } + } + } + + private void Form1_Load(object sender, System.EventArgs e) + { + this.button1.Click += new System.EventHandler(this.button1_Click); + this.FormClosing += new FormClosingEventHandler(Form1_FormClosing); + } + + void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + if (isExecuting) + { + MessageBox.Show(this, "Cannot close the form until " + + "the pending asynchronous command has completed. Please wait..."); + e.Cancel = true; + } + } + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlCommand_BeginExecuteXmlReader.cs b/doc/samples/SqlCommand_BeginExecuteXmlReader.cs new file mode 100644 index 0000000000..5b179dfb0b --- /dev/null +++ b/doc/samples/SqlCommand_BeginExecuteXmlReader.cs @@ -0,0 +1,85 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; +using System.Xml; + +class Class1 +{ + static void Main() + { + // This example is not terribly effective, but it proves a point. + // The WAITFOR statement simply adds enough time to prove the + // asynchronous nature of the command. + string commandText = + "WAITFOR DELAY '00:00:03';" + + "SELECT Name, ListPrice FROM Production.Product " + + "WHERE ListPrice < 100 " + + "FOR XML AUTO, XMLDATA"; + + RunCommandAsynchronously(commandText, GetConnectionString()); + + Console.WriteLine("Press ENTER to continue."); + Console.ReadLine(); + } + + private static void RunCommandAsynchronously( + string commandText, string connectionString) + { + // Given command text and connection string, asynchronously execute + // the specified command against the connection. For this example, + // the code displays an indicator as it is working, verifying the + // asynchronous behavior. + using (SqlConnection connection = new SqlConnection(connectionString)) + { + SqlCommand command = new SqlCommand(commandText, connection); + + connection.Open(); + IAsyncResult result = command.BeginExecuteXmlReader(); + + // Although it is not necessary, the following procedure + // displays a counter in the console window, indicating that + // the main thread is not blocked while awaiting the command + // results. + int count = 0; + while (!result.IsCompleted) + { + Console.WriteLine("Waiting ({0})", count++); + // Wait for 1/10 second, so the counter + // does not consume all available resources + // on the main thread. + System.Threading.Thread.Sleep(100); + } + + XmlReader reader = command.EndExecuteXmlReader(result); + DisplayProductInfo(reader); + } + } + + private static void DisplayProductInfo(XmlReader reader) + { + // Display the data within the reader. + while (reader.Read()) + { + // Skip past items that are not from the correct table. + if (reader.LocalName.ToString() == "Production.Product") + { + Console.WriteLine("{0}: {1:C}", + reader["Name"], Convert.ToSingle(reader["ListPrice"])); + } + } + } + + private static string GetConnectionString() + { + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + + // If you have not included "Asynchronous Processing=true" in the + // connection string, the command is not able + // to execute asynchronously. + return "Data Source=(local);Integrated Security=true;" + + "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs b/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs new file mode 100644 index 0000000000..4e47a52f09 --- /dev/null +++ b/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; +// +using Microsoft.Data.SqlClient; +using System.Xml; + +namespace Microsoft.AdoDotNet.CodeSamples +{ + public partial class Form1 : Form + { + // Hook up the form's Load event handler and then add + // this code to the form's class: + // You need these delegates in order to display text from a thread + // other than the form's thread. See the HandleCallback + // procedure for more information. + private delegate void DisplayInfoDelegate(string Text); + private delegate void DisplayReaderDelegate(XmlReader reader); + + private bool isExecuting; + + // This example maintains the connection object + // externally, so that it is available for closing. + private SqlConnection connection; + + public Form1() + { + InitializeComponent(); + } + + private string GetConnectionString() + { + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + + // If you do not include the Asynchronous Processing=true name/value pair, + // you wo not be able to execute the command asynchronously. + return "Data Source=(local);Integrated Security=true;" + + "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; + } + + private void DisplayStatus(string Text) + { + this.label1.Text = Text; + } + + private void ClearProductInfo() + { + // Clear the list box. + this.listBox1.Items.Clear(); + } + + private void DisplayProductInfo(XmlReader reader) + { + // Display the data within the reader. + while (reader.Read()) + { + // Skip past items that are not from the correct table. + if (reader.LocalName.ToString() == "Production.Product") + { + this.listBox1.Items.Add(String.Format("{0}: {1:C}", + reader["Name"], Convert.ToDecimal(reader["ListPrice"]))); + } + } + DisplayStatus("Ready"); + } + + private void Form1_FormClosing(object sender, + System.Windows.Forms.FormClosingEventArgs e) + { + if (isExecuting) + { + MessageBox.Show(this, "Cannot close the form until " + + "the pending asynchronous command has completed. Please wait..."); + e.Cancel = true; + } + } + + private void button1_Click(object sender, System.EventArgs e) + { + if (isExecuting) + { + MessageBox.Show(this, + "Already executing. Please wait until the current query " + + "has completed."); + } + else + { + SqlCommand command = null; + try + { + ClearProductInfo(); + DisplayStatus("Connecting..."); + connection = new SqlConnection(GetConnectionString()); + + // To emulate a long-running query, wait for + // a few seconds before working with the data. + string commandText = + "WAITFOR DELAY '00:00:03';" + + "SELECT Name, ListPrice FROM Production.Product " + + "WHERE ListPrice < 100 " + + "FOR XML AUTO, XMLDATA"; + + command = new SqlCommand(commandText, connection); + connection.Open(); + + DisplayStatus("Executing..."); + isExecuting = true; + // Although it is not required that you pass the + // SqlCommand object as the second parameter in the + // BeginExecuteXmlReader call, doing so makes it easier + // to call EndExecuteXmlReader in the callback procedure. + AsyncCallback callback = new AsyncCallback(HandleCallback); + command.BeginExecuteXmlReader(callback, command); + + } + catch (Exception ex) + { + isExecuting = false; + DisplayStatus(string.Format("Ready (last error: {0})", ex.Message)); + if (connection != null) + { + connection.Close(); + } + } + } + } + + private void HandleCallback(IAsyncResult result) + { + try + { + // Retrieve the original command object, passed + // to this procedure in the AsyncState property + // of the IAsyncResult parameter. + SqlCommand command = (SqlCommand)result.AsyncState; + XmlReader reader = command.EndExecuteXmlReader(result); + + // You may not interact with the form and its contents + // from a different thread, and this callback procedure + // is all but guaranteed to be running from a different thread + // than the form. + + // Instead, you must call the procedure from the form's thread. + // One simple way to accomplish this is to call the Invoke + // method of the form, which calls the delegate you supply + // from the form's thread. + DisplayReaderDelegate del = new DisplayReaderDelegate(DisplayProductInfo); + this.Invoke(del, reader); + + } + catch (Exception ex) + { + // Because you are now running code in a separate thread, + // if you do not handle the exception here, none of your other + // code catches the exception. Because none of + // your code is on the call stack in this thread, there is nothing + // higher up the stack to catch the exception if you do not + // handle it here. You can either log the exception or + // invoke a delegate (as in the non-error case in this + // example) to display the error on the form. In no case + // can you simply display the error without executing a delegate + // as in the try block here. + + // You can create the delegate instance as you + // invoke it, like this: + this.Invoke(new DisplayInfoDelegate(DisplayStatus), + String.Format("Ready(last error: {0}", ex.Message)); + } + finally + { + isExecuting = false; + if (connection != null) + { + connection.Close(); + } + } + } + + private void Form1_Load(object sender, System.EventArgs e) + { + this.button1.Click += new System.EventHandler(this.button1_Click); + this.FormClosing += new System.Windows.Forms. + FormClosingEventHandler(this.Form1_FormClosing); + } + } +} +// \ No newline at end of file diff --git a/doc/samples/SqlCommand_CommandText.cs b/doc/samples/SqlCommand_CommandText.cs new file mode 100644 index 0000000000..936e3f9247 --- /dev/null +++ b/doc/samples/SqlCommand_CommandText.cs @@ -0,0 +1,24 @@ +using System; +using System.Xml; +using System.Data; +using Microsoft.Data.SqlClient; +using System.Data.Common; +using System.Windows.Forms; + +public class Form1: Form +{ + protected DataSet DataSet1; + protected DataGrid dataGrid1; + + +// +public void CreateCommand() + { + SqlCommand command = new SqlCommand(); + command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"; + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + } +// + +} \ No newline at end of file diff --git a/doc/samples/SqlCommand_Connection.cs b/doc/samples/SqlCommand_Connection.cs new file mode 100644 index 0000000000..58febc807f --- /dev/null +++ b/doc/samples/SqlCommand_Connection.cs @@ -0,0 +1,41 @@ +using System; +using System.Data; +using Microsoft.Data.SqlClient; + + +namespace SqlCommandCS +{ + class Program + { + static void Main() + { + string str = "Data Source=(local);Initial Catalog=Northwind;" + + "Integrated Security=SSPI"; + string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;"; + CreateCommand(qs, str); + } + // + private static void CreateCommand(string queryString, + string connectionString) + { + using (SqlConnection connection = new SqlConnection( + connectionString)) + { + SqlCommand command = new SqlCommand(); + command.Connection = connection; + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + command.CommandText = queryString; + + connection.Open(); + SqlDataReader reader = command.ExecuteReader(); + while (reader.Read()) + { + Console.WriteLine(String.Format("{0}, {1}", + reader[0], reader[1])); + } + } + } + // + } +} \ No newline at end of file diff --git a/doc/samples/SqlCommand_ExecuteReader.cs b/doc/samples/SqlCommand_ExecuteReader.cs new file mode 100644 index 0000000000..bfce377e10 --- /dev/null +++ b/doc/samples/SqlCommand_ExecuteReader.cs @@ -0,0 +1,34 @@ +using System; +using System.Data; +using Microsoft.Data.SqlClient; + + + +class Program +{ + static void Main() + { + string str = "Data Source=(local);Initial Catalog=Northwind;" + + "Integrated Security=SSPI"; + string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;"; + CreateCommand(qs, str); + } + // + private static void CreateCommand(string queryString, + string connectionString) + { + using (SqlConnection connection = new SqlConnection( + connectionString)) + { + connection.Open(); + + SqlCommand command = new SqlCommand(queryString, connection); + SqlDataReader reader = command.ExecuteReader(); + while (reader.Read()) + { + Console.WriteLine(String.Format("{0}", reader[0])); + } + } + } + // +} diff --git a/doc/samples/SqlCommand_ExecuteReader2.cs b/doc/samples/SqlCommand_ExecuteReader2.cs new file mode 100644 index 0000000000..6f201a158d --- /dev/null +++ b/doc/samples/SqlCommand_ExecuteReader2.cs @@ -0,0 +1,32 @@ +using System; +using System.Data; +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string str = "Data Source=(local);Initial Catalog=Northwind;" + + "Integrated Security=SSPI"; + string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;"; + CreateCommand(qs, str); + } + // + private static void CreateCommand(string queryString, + string connectionString) + { + using (SqlConnection connection = new SqlConnection( + connectionString)) + { + SqlCommand command = new SqlCommand(queryString, connection); + connection.Open(); + SqlDataReader reader = + command.ExecuteReader(CommandBehavior.CloseConnection); + while (reader.Read()) + { + Console.WriteLine(String.Format("{0}", reader[0])); + } + } + } + // +} diff --git a/doc/samples/SqlCommand_SqlCommand1.cs b/doc/samples/SqlCommand_SqlCommand1.cs new file mode 100644 index 0000000000..d84a5001bb --- /dev/null +++ b/doc/samples/SqlCommand_SqlCommand1.cs @@ -0,0 +1,24 @@ +using System; +using System.Xml; +using System.Data; +using Microsoft.Data.SqlClient; +using System.Data.Common; +using System.Windows.Forms; + +public class Form1: Form +{ + protected DataSet DataSet1; + protected DataGrid dataGrid1; + + +// +public void CreateCommand() + { + string queryString = "SELECT * FROM Categories ORDER BY CategoryID"; + SqlCommand command = new SqlCommand(queryString); + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + } +// + +} \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/ApplicationIntent.xml b/doc/snippets/Microsoft.Data.SqlClient/ApplicationIntent.xml index de0a4c2fa1..03de187fba 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/ApplicationIntent.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/ApplicationIntent.xml @@ -1,17 +1,20 @@ - - + - Represents the application workload type when connecting to a server + Specifies a value for . Possible values are and . - - - - - + To be added. + + The application workload type when connecting to a server is read write. + 0 + 0 + + + The application workload type when connecting to a server is read only. + 1 + 1 + - \ No newline at end of file + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/OnChangeEventHandler.xml b/doc/snippets/Microsoft.Data.SqlClient/OnChangeEventHandler.xml new file mode 100644 index 0000000000..66b64dee02 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/OnChangeEventHandler.xml @@ -0,0 +1,17 @@ + + + + The source of the event. + A object that contains the event data. + Handles the event that is fired when a notification is received for any of the commands associated with a object. + + event does not necessarily imply a change in the data. Other circumstances, such as time-out expired and failure to set the notification request, also generate . + + ]]> + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml b/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml new file mode 100644 index 0000000000..9da432467f --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml @@ -0,0 +1,20 @@ + + + + Specifies a value for the property. + To be added. + + + Blocking period OFF for Azure SQL servers, but ON for all other SQL servers. + 0 + + + Blocking period ON for all SQL servers including Azure SQL servers. + 1 + + + Blocking period OFF for Azure SQL servers, but ON for all other SQL servers. + 2 + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml b/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml new file mode 100644 index 0000000000..ec36d3d264 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml @@ -0,0 +1,11 @@ + + + + + + Included to support debugging applications. Not intended for direct use. + + To be added. + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SortOrder.xml b/doc/snippets/Microsoft.Data.SqlClient/SortOrder.xml new file mode 100644 index 0000000000..0a80576703 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SortOrder.xml @@ -0,0 +1,25 @@ + + + + + Specifies how rows of data are sorted. + + To be added. + + + The default. No sort order is specified. + -1 + -1 + + + Rows are sorted in ascending order. + 0 + 0 + + + Rows are sorted in descending order. + 1 + 1 + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml new file mode 100644 index 0000000000..36a71053f7 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml @@ -0,0 +1,11 @@ + + + + Called from constructors in derived classes to initialize the class. + To be added. + + + When overridden in a derived class, initializes the authentication initializer. This method is called by the constructor during startup. + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml new file mode 100644 index 0000000000..da1c60cdc9 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml @@ -0,0 +1,29 @@ + + + + Describes the different SQL authentication methods that can be used by a client connecting to Azure SQL Database. For details, see Connecting to SQL Database By Using Azure Active Directory Authentication. + + To be added. + + + The authentication method is not specified. + 0 + + + The authentication method is Sql Password. + 1 + + + The authentication method uses Active Directory Password. Use Active Directory Password to connect to a SQL Database using an Azure AD principal name and password. + 2 + + + The authentication method uses Active Directory Integrated. Use Active Directory Integrated to connect to a SQL Database using integrated Windows authentication. + 3 + + + The authentication method uses Active Directory Interactive. Available since the .NET Framework 4.7.2. + 4 + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml new file mode 100644 index 0000000000..2b2820ca96 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml @@ -0,0 +1,60 @@ + + + + Represents AD authentication parameters passed by a driver to authentication providers. + To be added. + + + Constructor + + + + + + + + + To be added. + + + Gets the authentication method. + The authentication method. + To be added. + + + Resource URI. + The resource URI. + To be added. + + + Gets the connection ID. + The connection ID. + To be added. + + + Gets the user login name/ID. + The user login name/ID. + To be added. + + + Gets the resource URI. + The resource URI. + To be added. + + + Gets the connection ID. + The connection ID. + To be added. + + + Gets the database name. + The database name. + To be added. + + + Gets the database name. + The database name. + To be added. + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml new file mode 100644 index 0000000000..f8c5094733 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml @@ -0,0 +1,46 @@ + + + + Defines the core behavior of authentication providers and provides a base class for derived classes. + Derived classes must provide a parameterless constructor if they can be instantiated from the app.config file. + + + The authentication method. + Gets an authentication provider by method. + The authentication provider or if not found. + To be added. + + + The authentication method. + The authentication provider. + Sets an authentication provider by method. + + if the operation succeeded; otherwise, (for example, the existing provider disallows overriding). + + To be added. + + + The authentication method. + This method is called immediately before the provider is added to SQL drivers registry. + Avoid performing long-waiting tasks in this method, since it can block other threads from accessing the provider registry. + + + The authentication method. + This method is called immediately before the provider is removed from the SQL drivers registry. + For example, this method is called when a different provider with the same authentication method overrides this provider in the SQL drivers registry. Avoid performing long-waiting task in this method, since it can block other threads from accessing the provider registry. + + + The authentication method. + Indicates whether the specified authentication method is supported. + + if the specified authentication method is supported; otherwise, . + To be added. + + + The Active Directory authentication parameters passed by the driver to authentication providers. + Acquires a security token from the authority. + Represents an asynchronous operation that returns the AD authentication token. + To be added. + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml new file mode 100644 index 0000000000..088628fe6b --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml @@ -0,0 +1,25 @@ + + + + Represents an AD authentication token. + To be added. + + + The access token. + The token expiration time. + Initializes a new instance of the class. + To be added. + The parameter is or empty. + + + Gets the token expiration time. + The token expiration time. + To be added. + + + Gets the token string. + The token string. + To be added. + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml new file mode 100644 index 0000000000..19556eb2cb --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml @@ -0,0 +1,849 @@ + + + + Lets you efficiently bulk load a SQL Server table with data from another source. + + + class lets you write managed code solutions that provide similar functionality. There are other ways to load data into a SQL + Server table (INSERT statements, for example), but offers a significant performance advantage over them. + The class can be used to write data only to SQL Server tables. However, the data source is not limited to SQL Server; any data source can be used, + as long as the data can be loaded to a instance or read with a instance. + will fail when bulk loading a column of type + into a SQL Server column whose type is one of the date/time types added in SQL Server 2008. + ]]> + + + + + The following console application demonstrates how to load data using the class. In this example, + a is used to copy data from the **Production.Product** table in the SQL Server **AdventureWorks** database to a + similar table in the same database. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + + + + The already open + instance that will be used to perform the bulk copy operation. If your connection string does not use + , you can use + to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string. + Initializes a new instance of the + class using the specified open instance of . + + + + instance is initialized, the connection remains open after the instance is closed. + ]]> + + If the `connection` argument is null, an is thrown. + + + + + is used to copy data from the **Production.Product** table in the SQL Server **AdventureWorks** database to a similar table in the same database. This example is for demonstration + purposes only. You would not use `SqlBulkCopy` to move data from one table to another in the same database in a production application. + Note that the source data does not have to be located on SQL Server; you can use any data source that can be read to an or loaded to a + . + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + + [!code-csharp[DataWorks BulkCopy.Single#1]((../../../samples/source.cs#1)] + ]]> + + + + + + The already open instance that will be used to perform the bulk copy. If your connection string does not use , you can use to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string. + A combination of values from the enumeration that determines which data source rows are copied to the destination table. + An existing instance under which the bulk copy will occur. + Initializes a new instance of the class using the supplied existing open instance of . The instance behaves according to options supplied in the parameter. If a non-null is supplied, the copy operations will be performed within that transaction. + + + + Performing Bulk Copy Operations + ADO.NET Overview + + + + The string defining the connection that will be opened for use by the instance. + If your connection string does not use , you can use + or + and to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string. + + Initializes and opens a new instance of based on the supplied . The constructor uses the + to initialize a new instance of the class. + + + + is thrown. If `connectionString` is an empty string, an is thrown. + + ]]> + + + + + instance is closed. + In this example, the source data is first read from a SQL Server table to a instance. + The source data does not have to be located on SQL Server; you can use any data source that can be read to an or loaded to a . + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + [!code-csharp[DataWorks SqlBulkCopy.ConnectionString#1](../../../samples/class.cs#1 SqlBulkCopy.ConnectionString/CS/source.cs#1)] + ]]> + + + If `connectionString` is an empty string, an is thrown. + + + The already open + instance that will be used to perform the bulk copy. If your connection string does not use + , + you can use + to pass the user ID and password more securely than by specifying the user ID + and password as text in the connection string. + + A combination of values from the + enumeration that determines which data source rows are copied to the destination table. + + An existing + instance under which the bulk copy will occur. + + Initializes a new instance of the + class using the supplied existing open instance of . + The + instance behaves according to options supplied in the + parameter. If a non-null + is supplied, the copy operations will be performed within that transaction. + + + + + + + + The string defining the connection that will be opened for use by the instance. If your connection string does not use + , you can use or + and + to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string. + + A combination of values from the enumeration that determines which data source rows are copied to the destination table. + Initializes and opens a new instance of based on the supplied . The constructor uses that + to initialize a new instance of the class. The + instance behaves according to options supplied in the parameter. + + + topic. ]]> + + + + instance. + The source table and destination table each include an Identity column. By default, a new value for the **Identity** column is generated in the destination table for each row added. + In this example, an option is set when the connection is opened that forces the bulk load process to use the **Identity** values from the source table instead. + To see how the option changes the way the bulk load works, run the sample with the **dbo.BulkCopyDemoMatchingColumns** table empty. All rows load from the source. + Then run the sample again without emptying the table. An exception is thrown and the code writes a message to the console notifying you that rows weren't + added because of primary key constraint violations. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). This code is provided to + demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement + to copy the data. + + + [!code-csharp[DataWorks SqlBulkCopy.KeepIdentity#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.KeepIdentity/CS/source.cs#1)] + ]]> + + + + + + Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server. + The integer value of the property, or zero if no value has been set. + + + rows have been processed or there are no more rows to send to the destination data source. + + Zero (the default) indicates that each operation is a single batch. + + If the instance has been declared without the option in effect, + rows are sent to the server rows at a time, but no transaction-related action is taken. + If is in effect, each batch of rows is inserted as a separate transaction. + + The property can be set at any time. If a bulk copy is already in progress, the current batch is sized according to the previous batch size. + Subsequent batches use the new size. If the is initially zero and changed while a + operation is already in progress, that operation loads the data as a single batch. Any subsequent + operations on the same instance use the new . + ]]> + + + + + + works with a transaction, see [Transaction and Bulk Copy Operations](~/docs/framework/data/adonet/sql/transaction-and-bulk-copy-operations.md). + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.BatchSize#1](../../../samples/class.cs#1 SqlBulkCopy.BatchSize/CS/source.cs#1)] + ]]> + + + + + Number of seconds for the operation to complete before it times out. + The integer value of the property. The default is 30 seconds. A value of 0 indicates no limit; the bulk copy will wait indefinitely. + + If the operation does time out, the transaction is not committed and all copied rows are removed from the destination table. + + + + instance. + The source data does not have to be located on SQL Server; you can use any data source that can be read to an or loaded to a + . + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + [!INCLUDE[tsql](~/includes/tsql-md.md)]`INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.Timeout#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.Timeout/CS/source.cs#1)] + ]]> + + + + + Enables or disables a object to stream data from an object + + if a object can stream data from an object; otherwise, false. The default is . + + is `true`, reads from an object using , + optimizing memory usage by using the streaming capabilities. When it's set to false, the class loads all the data returned by the + object into memory before sending it to SQL Server or SQL Azure. + ]]> + + + + + Returns a collection of items. Column mappings define the relationships between columns in the data source and columns in the destination. + A collection of column mappings. By default, it is an empty collection. + + + collection is unnecessary. However, if the column counts differ, + or the ordinal positions are not consistent, you must use to make sure that data is copied into the correct columns. + + During the execution of a bulk copy operation, this collection can be accessed, but it cannot be changed. Any attempt to change it will throw an . + ]]> + + + + + Name of the destination table on the server. + The string value of the property, or null if none as been supplied. + + has not been set when is called, an + is thrown. If is modified while a operation is running, + the change does not affect the current operation. The new value is used the next time a method is called. + + is a three-part name (`..`). You can qualify the table name with its database and owning schema if you choose. + However, if the table name uses an underscore ("_") or any other special characters, you must escape the name using surrounding brackets as in (`[..]`). + For more information, see [Database Identifiers](/sql/relational-databases/databases/database-identifiers). + + You can bulk-copy data to a temporary table by using a value such as `tempdb..#table` or `tempdb..#table` for the property. + ]]> + + + + + instance. The source data does not have to + be located on SQL Server; you can use any data source that can be read to an or loaded to a . + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + [!code-csharp[DataWorks SqlBulkCopy.Single#1](../../../samples SqlBulkCopy.Single/CS/source.cs#1)] + ]]> + + + + + Defines the number of rows to be processed before generating a notification event. + The integer value of the property, or zero if the property has not been set. + + property can be set at any time, even while a bulk copy operation is underway. Changes made during a bulk copy operation take effect after + the next notification. The new setting applies to all subsequent operations on the same instance. + + If is set to a number less than zero, an is thrown. + ]]> + + + + + property is set so that + the event handler is called after every 50 rows copied to the table. + + In this example, the connection is first used to read data from a SQL Server table to a instance. Then a second connection is opened to bulk copy the data. + Note that the source data does not have to be located on SQL Server; you can use any data source that can be read to an or loaded to a . + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). This code is provided to + demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` + statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.NotifyAfter#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.NotifyAfter/CS/source.cs#1)] + ]]> + + + + + Occurs every time that the number of rows specified by the property have been processed. + + + and are independent. Receipt of a + event does not imply that any rows have been sent to the server or committed. + + You cannot call SqlBulkCopy.Close () or SqlConnection.Close () from this event. + Doing this will cause an being thrown, and the object state will not change. If the user wants to cancel the + operation from the event, the property of the can be used. + (See [Transaction and Bulk Copy Operations](~/docs/framework/data/adonet/sql/transaction-and-bulk-copy-operations.md) for examples that use the + property.) + + No action, such as transaction activity, is supported in the connection during the execution of the bulk copy operation, and it is recommended that you not use the same connection used + during the event. However, you can open a different connection. + + ]]> + + + + + property is set so that + the event handler is called after every 50 rows copied to the table. + + In this example, the connection is first used to read data from a SQL Server table to a instance. Note that the source data does not have to be located on + SQL Server; you can use any data source that can be read to an or loaded to a . + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier + and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.NotifyAfter#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.NotifyAfter/CS/source.cs#1)] + ]]> + + + + + Releases all resources used by the current instance of the class. + + + . The `Dispose` method leaves the in an unusable state. + After calling `Dispose`, you must release all references to the so the garbage collector can reclaim the memory that the + was occupying. + + For more information, see [Cleaning Up Unmanaged Resources](~/docs/standard/garbage-collection/unmanaged.md) and + [Implementing a Dispose Method](~/docs/standard/garbage-collection/implementing-dispose.md). + + [!NOTE] + Always call `Dispose` before you release your last reference to the . Otherwise, the resources it is using will not be freed until the garbage collector calls + the object's `Finalize` method. + ]]> + + + + + A whose rows will be copied to the destination table. + Copies all rows from the supplied array to a destination table specified by the + property of the object. + To be added. + + + A whose rows will be copied to the destination table. + Copies all rows in the supplied to a destination table specified by the + property of the object. + + + + or a similar call, + so the next available row is the first row. To process multiple results, call on the data reader and call + again. + + Note that using modifies the state of the reader. The method will call + until it returns false, the operation is aborted, or an error occurs. This means that the data reader will be in a different state, probably at the end of the result set, + when the operation is complete. + + While the bulk copy operation is in progress, the associated destination is busy serving it, and no other operations can be performed on the connection. + + The collection maps from the data reader columns to the destination database table. + ]]> + + + + + . The destination table is a table in the **AdventureWorks** database. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). This code is provided + to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ConnectionString#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ConnectionString/CS/source.cs#1)] + ]]> + + + + + + A whose rows will be copied to the destination table. + A value from the enumeration. Only rows matching the row state are copied to the destination. + Copies only rows that match the supplied row state in the supplied to a destination table specified by the + property of the object. + + + that are in the states indicated in the `rowState` argument and have not been deleted are copied to the destination table. + + [!NOTE] + If is specified, any , , and + rows will also be copied to the server. No exception will be raised. + + While the bulk copy operation is in progress, the associated destination is busy serving it, and no other operations can be performed on the connection. + + The collection maps from the columns to the destination database table. + + ]]> + + + + + that match a specified state. In this case, only unchanged rows are added. The destination table is a table in the **AdventureWorks** database. + + In this example, a is created at run time and three rows are added to it. Before the method is executed, one of the rows is edited. The method is called with a `DataRowState.Unchanged` `rowState` argument, so only the two unchanged rows are bulk copied to the destination. + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.DataRowState#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.DataRowState/CS/source.cs#1)] + ]]> + + + + + A whose rows will be copied to the destination table. + A value from the enumeration. Only rows matching the row state are copied to the destination. + Copies only rows that match the supplied row state in the supplied to a destination table specified by the property of the object. + + + that are in the states indicated in the `rowState` argument and have not been deleted are copied to the destination table. + + [!NOTE] + If is specified, any , , and + rows will also be copied to the server. No exception will be raised. + + While the bulk copy operation is in progress, the associated destination is busy serving it, and no other operations can be performed on the connection. + + The collection maps from the columns to the destination database table. + ]]> + + + + + that match a specified state. In this case, only unchanged rows are added. The destination table is a table in the **AdventureWorks** database. + + In this example, a is created at run time and three rows are added to it. Before the method is executed, one of the rows is edited. The method is called with a `DataRowState.Unchanged` `rowState` argument, so only the two unchanged rows are bulk copied to the destination. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.DataRowState#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.DataRowState/CS/source.cs#1)] + ]]> + + + + + An array of objects that will be copied to the destination table. + The asynchronous version of , which copies all rows from the supplied array to a destination table specified by the property of the object. + A task representing the asynchronous operation. + + + + + + Calling + multiple times for the same instance before task completion. Calling and + for the same instance before task completion. + + The connection drops or is closed during execution. + + Returned in the task object, the object was closed during the method execution. + + Returned in the task object, there was a connection pool timeout. + + Returned in the task object, the object is closed before method execution. + + is specified in the connection string. + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + An array of objects that will be copied to the destination table. + The asynchronous version of , + which copies all rows from the supplied array to a destination table specified by the + property of the object. + + A task representing the asynchronous operation. + + + + + + Calling + multiple times for the same instance before task completion. Calling + and for the same instance before task completion. + + The connection drops or is closed during execution. + + Returned in the task object, the object was closed during the method execution. + + Returned in the task object, there was a connection pool timeout. + + Returned in the task object, the object is closed before method execution. + + is specified in the connection string. + + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + An array of objects that will be copied to the destination table. + The cancellation instruction. A value in this parameter makes this method equivalent to + . + The asynchronous version of , which copies all rows from the supplied + array to a destination table specified by the property of the object. + + The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object. + A task representing the asynchronous operation. + + + + + + Calling multiple times for the same instance before + task completion. Calling and + for the same instance before task completion. The connection drops or is closed during + execution. Returned in the task object, the + object was closed during the method execution. Returned in the task object, there was a connection pool timeout. Returned in the task object, the + object is closed before method execution. is specified in the connection string. + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + A whose rows will be copied to the destination table. + The asynchronous version of , which copies all rows in the supplied to a destination table specified by the property of the object. + A task representing the asynchronous operation. + + + + + + Calling + multiple times for the same instance before task completion. Calling + and for the same instance before task completion. + The connection drops or is closed during execution. + Returned in the task object, the object was closed during the method execution. + Returned in the task object, there was a connection pool timeout. + Returned in the task object, the object is closed before method execution. + The was closed before the completed returned. + The 's associated connection was closed before the completed returned. + is specified in the connection string. + + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + A whose rows will be copied to the destination table. + The cancellation instruction. A value in this parameter makes this method equivalent to + . + The asynchronous version of , which copies all rows from the supplied + array to a destination table specified by the + property of the object. + Returns . + To be added. + + + A whose rows will be copied to the destination table. + The asynchronous version of , which copies all rows in the supplied + to a destination table specified by the property of the object. + A task representing the asynchronous operation. + + + + + + Calling multiple times for the same + instance before task completion. + + Calling and + for the same instance before task completion. + + The connection drops or is closed during execution. + + Returned in the task object, the object was closed during the method execution. + + Returned in the task object, there was a connection pool timeout. + + Returned in the task object, the object is closed before method execution. + + The was closed before the completed returned. + + The 's associated connection was closed before the completed returned. + + is specified in the connection string. + + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + A whose rows will be copied to the destination table. + The cancellation instruction. A value in this parameter makes this method equivalent to + . + The asynchronous version of , which copies all rows in the supplied + to a destination table specified by the property of the object. + The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object. + + A task representing the asynchronous operation. + + + + + + Calling + multiple times for the same instance before task completion. + + Calling and for the same instance before task completion. + + The connection drops or is closed during execution. + + Returned in the task object, the object was closed during the method execution. + + Returned in the task object, there was a connection pool timeout. + + Returned in the task object, the object is closed before method execution. + + The was closed before the completed returned. + + The 's associated connection was closed before the completed returned. + + is specified in the connection string. + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + A whose rows will be copied to the destination table. + The asynchronous version of , which copies all rows in the supplied + to a destination table specified by the property of the + object. + A task representing the asynchronous operation. + + + + + + Calling + multiple times for the same instance before task completion. + + Calling and + for the same instance before task completion. + + The connection drops or is closed during execution. + + Returned in the task object, the object was closed during the method execution. + + Returned in the task object, there was a connection pool timeout. + + Returned in the task object, the object is closed before method execution. + + is specified in the connection string. + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + A whose rows will be copied to the destination table. + The cancellation instruction. A value in this parameter makes this method equivalent to + . + The asynchronous version of , which copies all rows in the supplied + to a destination table specified by the property of the + object. + + The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object. + A task representing the asynchronous operation. + + + + + + Calling + multiple times for the same instance before task completion. + + Calling and for the same instance before task completion. + + The connection drops or is closed during execution. + + Returned in the task object, the object was closed during the method execution. + + Returned in the task object, there was a connection pool timeout. + + Returned in the task object, the object is closed before method execution. + + is specified in the connection string. + + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + A whose rows will be copied to the destination table. + A value from the enumeration. Only rows matching the row state are copied to the destination. + The asynchronous version of , + which copies only rows that match the supplied row state in the supplied to a destination table specified by the + property of the object. + + A task representing the asynchronous operation. + + + + + + Calling + multiple times for the same instance before task completion. + + Calling and for the same instance before task completion. + + The connection drops or is closed during execution. + + Returned in the task object, the object was closed during the method execution. + + Returned in the task object, there was a connection pool timeout. + + Returned in the task object, the object is closed before method execution. + + is specified in the connection string. + + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + A whose rows will be copied to the destination table. + A value from the enumeration. Only rows matching the row state are copied to the destination. + The cancellation instruction. A value in this parameter makes this method equivalent to + . + + The asynchronous version of , + which copies only rows that match the supplied row state in the supplied to a destination table specified by the + property of the object. + + The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.\ + + A task representing the asynchronous operation. + + + + + + Calling + multiple times for the same instance before task completion. + + Calling and + for the same instance before task completion. + + The connection drops or is closed during execution. + + Returned in the task object, the object was closed during the method execution. + + Returned in the task object, there was a connection pool timeout. + + Returned in the task object, the object is closed before method execution. + + is specified in the connection string. + Returned in the task object, any error returned by SQL Server that occurred while opening the connection. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml new file mode 100644 index 0000000000..7a9d8d515d --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml @@ -0,0 +1,264 @@ + + + + + Defines the mapping between a column in a + instance's data source and a column in the instance's destination table. + + collection is empty - the columns are mapped implicitly based on ordinal position. + For this to work, source and target schemas must match. If they do not, an will be thrown. + + If the collection is not empty, not every column present in the data source has to be specified. Those not mapped by the collection + are ignored. + + You can refer to source and target columns by either name or ordinal. You can also mix by-name and by-ordinal column references in the same mappings collection. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. Although the number of columns in the + destination matches the number of columns in the source, and each destination column is in the same ordinal position as its corresponding source column, the column names do not match. + objects are used to create a column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMapping#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMapping/CS/source.cs#1)] + + ]]> + + + + Parameterless constructor that initializes a new object. + + + property or the property, and define the destination for the mapping using the + property or the property. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. + Although the number of columns in the destination matches the number of columns in the source, the column names and ordinal positions do not match. + objects are used to create a column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMapping#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMapping/CS/source.cs#1)] + + ]]> + + + + The ordinal position of the source column within the data source. + The ordinal position of the destination column within the destination table. + Creates a new column mapping, using column ordinals to refer to source and destination columns. + + objects are used to create a column map for the bulk copy based on the ordinal positions of the columns. + + [!IMPORTANT] + his sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier + and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingOrdinal#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingOrdinal/CS/source.cs#1)] + [!code-vb[DataWorks SqlBulkCopy.ColumnMappingOrdinal#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingOrdinal/VB/source.vb#1)] + + ]]> + + + + + The ordinal position of the source column within the data source. + The name of the destination column within the destination table. + Creates a new column mapping, using a column ordinal to refer to the source column and a column name for the target column. + + objects are used to create a + column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and + faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingOrdinalName#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingOrdinalName/CS/source.cs#1)] + + ]]> + + + + The name of the source column within the data source. + The ordinal position of the destination column within the destination table. + Creates a new column mapping, using a column name to refer to the source column and a column ordinal for the target column. + + objects are used to create + a column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). This code is + provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to + use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingNameOrdinal#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingNameOrdinal/CS/source.cs#1)] + + ]]> + + + + The name of the source column within the data source. + The name of the destination column within the destination table. + Creates a new column mapping, using column names to refer to source and destination columns. + + objects are used to create a + column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMapping#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMapping/CS/source.cs#1)] + + ]]> + + + + Name of the column being mapped in the destination database table. + The string value of the property. + + and properties are mutually exclusive. + The last value set takes precedence. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. + Although the number of columns in the destination matches the number of columns in the source, the column names and ordinal positions do not match. + objects are used to create a column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingDestinationColumn#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingDestinationColumn/CS/source.cs#1)] + + ]]> + + + + Ordinal value of the destination column within the destination table. + The integer value of the property, or -1 if the property has not been set. + + and properties are mutually exclusive. + The last value set takes precedence. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. Although the number of columns in the + destination matches the number of columns in the source, the column names and ordinal positions do not match. objects are used to create a + column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingDestinationOrdinal#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingDestinationOrdinal/CS/source.cs#1)] + + ]]> + + + + Name of the column being mapped in the data source. + The string value of the property. + + and properties are mutually exclusive. + The last value set takes precedence. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. Although the number of columns in the + destination matches the number of columns in the source, the column names and ordinal positions do not match. objects are used to create a + column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingDestinationColumn#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingDestinationColumn/CS/source.cs#1)] + + ]]> + + + + The ordinal position of the source column within the data source. + The integer value of the property. + + and properties are mutually exclusive. + The last value set takes precedence. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. Although the number of columns in the destination + matches the number of columns in the source, the column names and ordinal positions do not match. objects are used to create a column map for the + bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingDestinationOrdinal#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingDestinationOrdinal/CS/source.cs#1)] + + ]]> + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMappingCollection.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMappingCollection.xml new file mode 100644 index 0000000000..01927b7276 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMappingCollection.xml @@ -0,0 +1,327 @@ + + + + Collection of objects that inherits from . + + collection is empty - the columns are mapped implicitly based on ordinal position. + For this to work, source and target schemas must match. If they do not, an is thrown. + + If the collection is not empty, not every column present in the data source has to be specified. Those not mapped by the collection are + ignored. + + You can refer to source and target columns by either name or ordinal. You can mix by-name and by-ordinal column references in the same mappings collection. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. + Although the number of columns in the destination matches the number of columns in the source, the column names and ordinal positions do not match. + are added to the for the + object to create a column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to + use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy.ColumnMappingCollection#1](~/sqlClient/doc/samples/ SqlBulkCopy.ColumnMappingCollection/CS/source.cs#1)] + + ]]> + + + + The object that describes the mapping to be added to the collection. + Adds the specified mapping to the . + A object. + + objects are used to create a column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy.ColumnMapping#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMapping.cs)] + + ]]> + + + + + The ordinal position of the source column within the data source. + The ordinal position of the destination column within the destination table. + Creates a new and adds it to the collection, using ordinals to specify both source and destination columns. + A column mapping. + + is thrown. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. + Although the number of columns in the destination matches the number of columns in the source, the column names and ordinal positions do not match. + objects are used to create a column map for the bulk copy using the ordinal position of the source and destination columns. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy.ColumnMappingCollectionOrdinal#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMappingCollectionOrdinal.cs)] + + ]]> + + + + The ordinal position of the source column within the data source. + The name of the destination column within the destination table. + Creates a new and adds it to the collection, using an ordinal for the source column and a string for the destination column. + A column mapping. + + is thrown. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. Although the number of columns in the + destination matches the number of columns in the source, the column names and ordinal positions do not match. objects are used to create a + column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy_ColumnMappingIndexColName#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMappingIndexColName.cs)] + + ]]> + + + + The name of the source column within the data source. + The ordinal position of the destination column within the destination table. + Creates a new and adds it to the collection, using a column name to describe the source column and an ordinal to specify the destination column. + A column mapping. + + is thrown. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. + Although the number of columns in the destination matches the number of columns in the source, the column names and ordinal positions do not match. + objects are used to create a column map for the bulk copy. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy.ColumnMappingColNameIndex#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMappingColNameIndex.cs)] + + ]]> + + + + The name of the source column within the data source. + The name of the destination column within the destination table. + Creates a new and adds it to the collection, using column names to specify both source and destination columns. + A column mapping. + + is thrown. + + + + ## Examples + The following example bulk copies data from a source table in the **AdventureWorks** sample database to a destination table in the same database. + Although the number of columns in the destination matches the number of columns in the source, the column names and ordinal positions do not match. The code creates a + object by specifying the column names. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy.ColumnMappingCollection#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMappingCollection.cs)] + + ]]> + + + + Clears the contents of the collection. + + method is most commonly used when you use a single + instance to process more than one bulk copy operation. If you create column mappings for one bulk copy operation, you must clear the + after the method and before processing the next bulk copy. + + Performing several bulk copies using the same instance will usually be more efficient from a performance point of view than using a separate + for each operation. + + + + ## Examples + The following example performs two bulk copy operations. The first operation copies sales order header information, and the second copies sales order details. + Although not strictly necessary in this example (because the ordinal positions of the source and destination columns do match), the example defines column mappings for each bulk copy operation. + The method must be used after the first bulk copy is performed and before the next bulk copy's column mappings are defined. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy.ColumnMappingOrdersDetails#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMappingOrdersDetails.cs)] + + ]]> + + + + A valid object. + Gets a value indicating whether a specified object exists in the collection. + + if the specified mapping exists in the collection; otherwise . + To be added. + + + The one-dimensional array that is the destination of the elements copied from + . The array must have zero-based indexing. + The zero-based index in at which copying begins. + Copies the elements of the to an array of + items, starting at a particular index. + + To be added. + + + To be added. + To be added. + To be added. + + + To be added. + To be added. + To be added. + + + The object for which to search. + Gets the index of the specified object. + The zero-based index of the column mapping, or -1 if the column mapping is not found in the collection. + To be added. + + + Integer value of the location within the at which to insert the new + . + + object to be inserted in the collection. + Insert a new at the index specified. + To be added. + + + The zero-based index of the to find. + Gets the object at the specified index. + A object. + To be added. + + + + object to be removed from the collection. + Removes the specified element from the . + + method is most commonly used when you use a single + instance to process more than one bulk copy operation. If you create column mappings for one bulk copy operation, you must remove mappings that no longer apply after the + method is called and before defining mapping for the next bulk copy. You can clear the entire collection by using the + method, or remove mappings individually using the + method or the method. + + Performing several bulk copies using the same instance will usually be more efficient from a performance point of view than using a separate + for each operation. + + + + ## Examples + The following example performs two bulk copy operations. The first operation copies sales order header information, and the second copies sales order details. + Although not strictly necessary in this example (because the ordinal positions of the source and destination columns do match), the example defines column mappings for each bulk copy operation. + Both bulk copies include a mapping for the **SalesOrderID**, so rather than clearing the entire collection between bulk copy operations, the example removes all mappings except for the **SalesOrderID** + mapping and then adds the appropriate mappings for the second bulk copy operation. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy.ColumnMappingRemove#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMappingRemove.cs)] + + ]]> + + + + The zero-based index of the object to be removed from the collection. + Removes the mapping at the specified index from the collection. + + method is most commonly used when you use a single + instance to process more than one bulk copy operation. If you create column mappings for one bulk copy operation, you must remove mappings that no longer apply after the + method is called and before defining mapping for the next bulk copy. You can clear the entire collection by using the + method, or remove mappings individually using the + method or the method. + + Performing several bulk copies using the same instance will usually be more efficient from a performance point of view than using a separate + for each operation. + + + + ## Examples + The following example performs two bulk copy operations. The first operation copies sales order header information, and the second copies sales order details. + Although not strictly necessary in this example (because the ordinal positions of the source and destination columns do match), the example defines column mappings for each bulk copy operation. + Both bulk copies include a mapping for the **SalesOrderID**, so rather than clearing the entire collection between bulk copy operations, the example removes all mappings except for the + **SalesOrderID** mapping and then adds the appropriate mappings for the second bulk copy operation. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a + Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[SqlBulkCopy.ColumnMappingRemoveAt#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMappingRemoveAt.cs)] + + ]]> + + + + To be added. + To be added. + To be added. + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyOptions.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyOptions.xml new file mode 100644 index 0000000000..243e1f80dd --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyOptions.xml @@ -0,0 +1,66 @@ + + + + Bitwise flag that specifies one or more options to use with an instance of . + + enumeration when you construct a instance to change how the + methods for that instance behave. + + + + ## Examples + The following console application demonstrates how to perform a bulk load that copies the value in the identity column of the source table to the corresponding column in the destination table, + instead of generating a new value for each row's identity column. + + To see how the option changes the way the bulk load works, run the sample with the **dbo.BulkCopyDemoMatchingColumns** table empty. All rows load from the source. + Next, run the sample again without emptying the table. An exception is thrown, and the code writes a message to the console window notifying you that rows were not added because of + primary key violations. + + [!IMPORTANT] + This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). + This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, + it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. + + [!code-csharp[DataWorks SqlBulkCopy_KeepIdentity#1](~/sqlClient/doc/samples/ SqlBulkCopy_KeepIdentity.cs)] + + ]]> + + + + When specified, **AllowEncryptedValueModifications** enables bulk copying of encrypted data between tables or databases, without decrypting the data. Typically, + an application would select data from encrypted columns from one table without decrypting the data (the app would connect to the database with the column encryption setting keyword set + to disabled) and then would use this option to bulk insert the data, which is still encrypted. For more information, see + [Always Encrypted](/sql/relational-databases/security/encryption/always-encrypted-database-engine). + + Use caution when specifying **AllowEncryptedValueModifications** as this may lead to corrupting the database because the driver does not check if the data is indeed encrypted, + or if it is correctly encrypted using the same encryption type, algorithm and key as the target column. + + + + Check constraints while data is being inserted. By default, constraints are not checked. + + + Use the default values for all options. + + + When specified, cause the server to fire the insert triggers for the rows being inserted into the database. + + + Preserve source identity values. When not specified, identity values are assigned by the destination. + + + Preserve null values in the destination table regardless of the settings for default values. When not specified, null values are replaced by default values where applicable. + + + Obtain a bulk update lock for the duration of the bulk copy operation. When not specified, row locks are used. + + + When specified, each batch of the bulk-copy operation will occur within a transaction. If you indicate this option and also provide a + object to the constructor, an occurs. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml new file mode 100644 index 0000000000..b48d89c832 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml @@ -0,0 +1,176 @@ + + + + Represents a set of methods for creating instances of the provider's implementation of the data source classes. + To be added. + + + Gets a value that indicates whether a can be created. + + if a can be created; otherwise, . + + + class provides the property so that inheritors can indicate + whether they can provide a data source enumerator. The displays this property, but its value is always `true`. + + + + ## Examples + The following example displays a list of all available SQL Server data sources, using code that could enumerate data sources for any provider. + + [!code-csharp[DataWorks SqlClientFactory_DataSourceEnumerator#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlClientFactory_DataSourceEnumerator/CS/source.cs#1)] + + ]]> + + + + Returns a strongly typed instance. + A new strongly typed instance of . + + instance: + + + ```csharp + SqlClientFactory newFactory = SqlClientFactory.Instance; + DbCommand cmd = newFactory.CreateCommand(); + ``` + + ]]> + + + + Returns a strongly typed instance. + A new strongly typed instance of . + + instance: + + + ```csharp + SqlClientFactory newFactory = SqlClientFactory.Instance; + DbCommandBuilder cmd = newFactory.CreateCommandBuilder(); + ``` + + ]]> + + + + Returns a strongly typed instance. + A new strongly typed instance of . + + instance: + + + ```csharp + SqlClientFactory newFactory = SqlClientFactory.Instance; + DbConnection cmd = newFactory.CreateConnection(); + + ``` + + ]]> + + + + Returns a strongly typed instance. + A new strongly typed instance of . + + instance: + + ```csharp + SqlClientFactory newFactory = SqlClientFactory.Instance; + DbConnectionStringBuilder cmd = + newFactory.CreateConnectionStringBuilder(); + ``` + + ]]> + + + + Returns a strongly typed instance. + A new strongly typed instance of . + + instance: + + ```csharp + SqlClientFactory newFactory = SqlClientFactory.Instance; + DbDataAdapter cmd = newFactory.CreateDataAdapter(); + ``` + + ]]> + + + + Returns a new . + A new data source enumerator. + + + + + + Returns a strongly typed instance. + A new strongly typed instance of . + + instance: + + + ```csharp + SqlClientFactory newFactory = SqlClientFactory.Instance; + DbParameter cmd = newFactory.CreateParameter(); + ``` + + ]]> + + + + A member of the enumeration. + Returns a new . + A strongly typed instance of . + To be added. + + + Gets an instance of the . This can be used to retrieve strongly typed data objects. + + property to retrieve a **SqlClientFactory** instance, and then return a strongly typed + instance: + + + ```csharp + SqlClientFactory newFactory = SqlClientFactory.Instance; + DbCommand cmd = newFactory.CreateCommand(); + ``` + + ]]> + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml new file mode 100644 index 0000000000..87064b96a8 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml @@ -0,0 +1,43 @@ + + + + + Represents a SQL client logger. + To be added. + + + Initializes a new instance of the class. + To be added. + + + Gets a value that indicates whether bid tracing is enabled. + + if bid tracing is enabled; otherwise, . + To be added. + + + to log the message; otherwise, . + The type to be logged. + The logging method. + The message to be logged. + Logs the specified message if is . + if the message is not logged; otherwise, . + To be added. + + + The type to be logged. + The logging method. + The message to be logged. + Logs an error through a specified method of the current instance type. + To be added. + + + The type to be logged. + The logging method. + The message to be logged. + Logs information through a specified method of the current instance type. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml new file mode 100644 index 0000000000..795f40d91f --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml @@ -0,0 +1,38 @@ + + + + + Provides a list of constants for use with the **GetSchema** method to retrieve metadata collections. + To be added. + + + A constant for use with the **GetSchema** method that represents the **Columns** collection. + To be added. + + + A constant for use with the **GetSchema** method that represents the **Databases** collection. + To be added. + + + A constant for use with the **GetSchema** method that represents the **ForeignKeys** collection. + To be added. + + + A constant for use with the **GetSchema** method that represents the **IndexColumns** collection. + To be added. + + + A constant for use with the **GetSchema** method that represents the **Indexes** collection. + To be added. + + + A constant for use with the **GetSchema** method that represents the **Parameters** collection. + To be added. + + + A constant for use with the **GetSchema** method that represents the **ProcedureColumns** collection. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml new file mode 100644 index 0000000000..d0c291975e --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml @@ -0,0 +1,88 @@ + + + + + Enables the .NET Framework Data Provider for SQL Server to help make sure that a user has a security level sufficient to access a data source. + + property takes precedence over the property. + Therefore, if you set to `false`, you must also set + to `false` to prevent a user from making a connection using a blank password. + + [!NOTE] + When using code access security permissions for ADO.NET, the correct pattern is to start with the most restrictive case (no permissions at all) and then add the specific permissions that + are needed for the particular task that the code needs to perform. The opposite pattern, starting with all permissions and then denying a specific permission, + is not secure, because there are many ways of expressing the same connection string. For example, if you start with all permissions and then attempt to deny the use of the connection + string "server=someserver", the string "server=someserver.mycompany.com" would still be allowed. By always starting by granting no permissions at all, you reduce the chances that there are + holes in the permission set. + + ]]> + + + + Initializes a new instance of the class. + To be added. + + + One of the values. + Initializes a new instance of the class. + To be added. + + + One of the values. + Indicates whether a blank password is allowed. + Initializes a new instance of the class. + + enumeration takes precedence over the property. + Therefore, if you set to `false`, you must also set to `None` to + prevent a user from making a connection using a blank password. For an example demonstrating how to use security demands, see [Code Access Security and + ADO.NET](~/docs/framework/data/adonet/code-access-security.md). + + ]]> + + + + The connection string. + The key restrictions. + One of the enumerations. + Adds a new connection string and a set of restricted keywords to the object. + + + + + + Returns the as an . + A copy of the current permission object. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermissionAttribute.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermissionAttribute.xml new file mode 100644 index 0000000000..10d99c676a --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermissionAttribute.xml @@ -0,0 +1,20 @@ + + + + + Associates a security action with a custom security attribute. + To be added. + + + One of the values representing an action that can be performed by using declarative security. + Initializes a new instance of the class. + To be added. + + + Returns a object that is configured according to the attribute properties. + A object. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml new file mode 100644 index 0000000000..bf122d38e6 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml @@ -0,0 +1,54 @@ + + + + + The implementation of the key store provider for Windows Certificate Store. This class enables using certificates stored in the Windows Certificate Store as column master keys. + For details, see Always Encrypted. + To be added. + + + Key store provider for Windows Certificate Store. + To be added. + + + The master key path. + The encryption algorithm. Currently, the only valid value is: RSA_OAEP + The encrypted column encryption key. + Decrypts the specified encrypted value of a column encryption key. The encrypted value is expected to be encrypted using the certificate with the specified key path and using the specified + algorithm. The format of the key path should be "Local Machine/My/<certificate_thumbprint>" or "Current User/My/<certificate_thumbprint>". + + Returns . The decrypted column encryption key. + To be added. + + + The master key path. + The encryption algorithm. Currently, the only valid value is: RSA_OAEP + The encrypted column encryption key. + Encrypts a column encryption key using the certificate with the specified key path and using the specified algorithm. The format of the key path should be + "Local Machine/My/<certificate_thumbprint>" or "Current User/My/<certificate_thumbprint>". + + Returns . The encrypted column encryption key. + To be added. + + + The provider name. + To be added. + + + The column master key path. + to indicate that the column master key supports enclave computations; otherwise, . + Digitally signs the column master key metadata with the column master key referenced by the parameter. + The signature of the column master key metadata. + To be added. + + + The complete path of an asymmetric key. The path format is specific to a key store provider. + A Boolean that indicates if this key can be sent to the trusted enclave. + The master key metadata siognature. + This function must be implemented by the corresponding Key Store providers. This function should use an asymmetric key identified by a key path and verify the masterkey metadata consisting of (masterKeyPath, allowEnclaveComputations, providerName). + A Boolean value that indicates if the master key metadata can be verified based on the provided signature. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml new file mode 100644 index 0000000000..13b5785b5e --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml @@ -0,0 +1,69 @@ + + + + + The CMK Store provider implementation for using the Microsoft Cryptography API: Next Generation (CNG) with + Always Encrypted. + + + + + + + Initializes a new instance of the class. + To be added. + + + The master key path. + The encryption algorithm. + The encrypted column encryption key. + Decrypts the given encrypted value using an asymmetric key specified by the key path and the specified algorithm. The key path will be in the format of [ProviderName]/KeyIdentifier + and should be an asymmetric key stored in the specified CNG key store provider. The valid algorithm used to encrypt/decrypt the CEK is 'RSA_OAEP'. + + The decrypted column encryption key. + To be added. + + + The master key path. + The encryption algorithm. + The encrypted column encryption key. + Encrypts the given plain text column encryption key using an asymmetric key specified by the key path and the specified algorithm. The key path will be in the format of [ProviderName]/KeyIdentifier and should be an asymmetric key stored in the specified CNG key store provider. The valid algorithm used to encrypt/decrypt the CEK is 'RSA_OAEP'. + The encrypted column encryption key. + To be added. + + + A constant string for the provider name 'MSSQL_CNG_STORE'. + To be added. + + + The column master key path. The path format is specific to a key store provider. + to indicate that the column master key supports enclave computations; otherwise, . + Throws a exception in all cases. + The signature of the column master key metadata. + + method must be implemented by the corresponding key store providers. + should use an asymmetric key identified by a key path and sign the masterkey metadata consisting + of `masterKeyPath`, `allowEnclaveComputations`, and providerName. + + ]]> + + + + The complete path of an asymmetric key. The path format is specific to a key store provider. + A Boolean that indicates if this key can be sent to the trusted enclave. + The master key metadata signature. + This function must be implemented by the corresponding Key Store providers. This function should use an asymmetric key identified by a key path and verify the masterkey metadata consisting of (masterKeyPath, allowEnclaveComputations, providerName). + A Boolean that indicates if the master key metadata can be verified based on the provided signature. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml new file mode 100644 index 0000000000..13d07b9424 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml @@ -0,0 +1,69 @@ + + + + + The CMK Store provider implementation for using Microsoft CAPI based Cryptographic Service Providers (CSP) with + Always Encrypted. + + + + + + Initializes a new instance of the class. + To be added. + + + The master key path. + The encryption algorithm. + The encrypted column encryption key. + Decrypts the given encrypted value using an asymmetric key specified by the key path and algorithm. The key path will be in the format of [ProviderName]/KeyIdentifier and should be an + asymmetric key stored in the specified CSP provider. The valid algorithm used to encrypt/decrypt the CEK is 'RSA_OAEP'. + The decrypted column encryption key. + To be added. + + + The master key path. + The encryption algorithm. + The encrypted column encryption key. + Encrypts the given plain text column encryption key using an asymmetric key specified by the key path and the specified algorithm. The key path will be in the format of + [ProviderName]/KeyIdentifier and should be an asymmetric key stored in the specified CSP provider. The valid algorithm used to encrypt/decrypt the CEK is 'RSA_OAEP'. + The encrypted column encryption key. + To be added. + + + A constant string for the provider name 'MSSQL_CSP_PROVIDER'. + To be added. + + + The column master key path. The path format is specific to a key store provider. + to indicate that the column master key supports enclave computations; otherwise, . + Throws a exception in all cases. + The signature of the column master key metadata. + + method must be implemented by the corresponding key store providers. + should use an asymmetric key identified by a key path and sign the masterkey metadata + consisting of `masterKeyPath`, `allowEnclaveComputations`, and providerName. + + ]]> + + + + The complete path of an asymmetric key. The path format is specific to a key store provider. + A boolean that indicates if this key can be sent to the trusted enclave. + Master key metadata signature. + This function must be implemented by the corresponding Key Store providers. This function should use an asymmetric key identified by a key path and sign the masterkey metadata consisting of + (masterKeyPath, allowEnclaveComputations, providerName). + A Boolean that indicates if the master key metadata can be verified based on the provided signature. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml new file mode 100644 index 0000000000..9147c23ad8 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml @@ -0,0 +1,56 @@ + + + + + The base class that defines the interface for enclave providers for Always Encrypted. + + + + + + Initializes a new instance of the class + To be added. + + + The information the provider uses to attest the enclave and generate a symmetric key for the session. The format of this information is specific to the enclave + attestation protocol. + A Diffie-Hellman algorithm object that encapsulates a client-side key pair. + The endpoint of an attestation service for attesting the enclave. + The name of the SQL Server instance containing the enclave. + The requested enclave session or if the provider doesn't implement session caching. + A counter that the enclave provider is expected to increment each time SqlClient retrieves the session from the cache. The purpose of this field is to prevent replay attacks. + When overridden in a derived class, performs enclave attestation, generates a symmetric key for the session, creates a an enclave session and stores the session information in the cache. + To be added. + + + Gets the information that SqlClient subsequently uses to initiate the process of attesting the enclave and to establish a secure session with the enclave. + The information SqlClient subsequently uses to initiate the process of attesting the enclave and to establish a secure session with the enclave. + To be added. + + + The name of the SQL Server instance containing the enclave. + The endpoint of an attestation service, SqlClient contacts to attest the enclave. + When this method returns, the requested enclave session or if the provider doesn't implement session caching. This parameter is treated as + uninitialized. + A counter that the enclave provider is expected to increment each time SqlClient retrieves the session from the cache. The purpose of this field is to prevent replay attacks. + When overridden in a derived class, looks up an existing enclave session information in the enclave session cache. If the enclave provider doesn't implement enclave session caching, this + method is expected to return in the parameter. + + To be added. + + + The name of the SQL Server instance containing the enclave. + The endpoint of an attestation service, SqlClient contacts to attest the enclave. + The session to be invalidated. + When overridden in a derived class, looks up and evicts an enclave session from the enclave session cache, if the provider implements session caching. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml new file mode 100644 index 0000000000..662f232ba6 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml @@ -0,0 +1,65 @@ + + + + + Base class for all key store providers. A custom provider must derive from this class and override its member functions and then register it using + SqlConnection.RegisterColumnEncryptionKeyStoreProviders(). For details see, + Always Encrypted. + + To be added. + + + Initializes a new instance of the SqlColumnEncryptionKeyStoreProviderClass. + To be added. + + + The master key path. + The encryption algorithm. + The encrypted column encryption key. + Decrypts the specified encrypted value of a column encryption key. The encrypted value is expected to be encrypted using the column master key with the specified key path and using the + specified algorithm. + + Returns . The decrypted column encryption key. + To be added. + + + The master key path. + The encryption algorithm. + The encrypted column encryption key. + Encrypts a column encryption key using the column master key with the specified key path and using the specified algorithm. + Returns . The encrypted column encryption key. + To be added. + + + The column master key path. + to indicate that the column master key supports enclave computations; otherwise, . + When implemented in a derived class, digitally signs the column master key metadata with the column master key referenced by the parameter. + The input values used to generate the signature should be the specified values of the and parameters. + + The signature of the column master key metadata. + + method doesn't break applications that rely on an old API, it throws a + exception by default. + + The method will be used by client tools that generate Column Master Keys (CMK) for customers. + must be implemented by the corresponding key store providers that wish to use enclaves with + [Always Encrypted](https://docs.microsoft.com/sql/relational-databases/security/encryption/always-encrypted-database-engine). + + ]]> + + In all cases. + + + The column master key path. + Indicates whether the column master key supports enclave computations. + The signature of the column master key metadata. + When implemented in a derived class, this method is expected to verify the specified signature is valid for the column master key with the specified key path and the specified enclave behavior. The default implementation throws NotImplementedException. + When implemented in a derived class, the method is expected to return true if the specified signature is valid, or false if the specified signature is not valid. The default implementation throws NotImplementedException. + To be added. + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs new file mode 100644 index 0000000000..64460318f3 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs @@ -0,0 +1,40 @@ + + +using System; +using System.Data; +using Microsoft.Data.SqlClient; + + +namespace SqlCommandCS +{ + class Program + { + static void Main() + { + string str = "Data Source=(local);Initial Catalog=Northwind;" + + "Integrated Security=SSPI"; + string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;"; + CreateCommand(qs, str); + + } + // + private static void CreateCommand(string queryString, + string connectionString) + { + using (SqlConnection connection = new SqlConnection( + connectionString)) + { + SqlCommand command = new SqlCommand( + queryString, connection); + connection.Open(); + SqlDataReader reader = command.ExecuteReader(); + while (reader.Read()) + { + Console.WriteLine(String.Format("{0}, {1}", + reader[0], reader[1])); + } + } + } + // + } +} \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml new file mode 100644 index 0000000000..7492f86efb --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml @@ -0,0 +1,1900 @@ + + + + + Represents a Transact-SQL statement or stored procedure to execute against a SQL Server database. This class cannot be inherited. + + is created, the read/write properties are set to their initial values. For a list of these values, see the constructor. + + features the following methods for executing commands at a SQL Server database: + + |Item|Description| + |----------|-----------------| + ||Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this , generally executing commands such as INSERT, DELETE, UPDATE, and SET statements. Each call to must be paired with a call to which finishes the operation, typically on a separate thread.| + ||Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this and retrieves one or more results sets from the server. Each call to must be paired with a call to which finishes the operation, typically on a separate thread.| + ||Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this . Each call to `BeginExecuteXmlReader` must be paired with a call to `EndExecuteXmlReader`, which finishes the operation, typically on a separate thread, and returns an object.| + ||Executes commands that return rows. For increased performance, invokes commands using the Transact-SQL `sp_executesql` system stored procedure. Therefore, might not have the effect that you want if used to execute commands such as Transact-SQL SET statements.| + ||Executes commands such as Transact-SQL INSERT, DELETE, UPDATE, and SET statements.| + ||Retrieves a single value (for example, an aggregate value) from a database.| + ||Sends the to the and builds an object.| + + You can reset the property and reuse the object. However, you must close the before you can execute a new or previous command. + + If a is generated by the method executing a , the remains open when the severity level is 19 or less. When the severity level is 20 or greater, the server ordinarily closes the . However, the user can reopen the connection and continue. + + [!NOTE] + Nameless, also called ordinal, parameters are not supported by the .NET Framework Data Provider for SQL Server. + + + + ## Examples + The following example creates a , a , and a . The example reads through the data, writing it to the console. Finally, the example closes the and then the as it exits the `Using` code blocks. + + [!code-csharp[Classic WebData SqlCommand Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand Example/CS/source.cs#1)] + + The following sample shows how to create and execute different types of SqlCommand objects. + + First you must create the sample database, by executing the following script: + + ```sql + USE [master] + GO + + CREATE DATABASE [MySchool] + GO + + USE [MySchool] + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + CREATE procedure [dbo].[CourseExtInfo] @CourseId int + as + select c.CourseID,c.Title,c.Credits,d.Name as DepartmentName + from Course as c left outer join Department as d on c.DepartmentID=d.DepartmentID + where c.CourseID=@CourseId + + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + create procedure [dbo].[DepartmentInfo] @DepartmentId int,@CourseCount int output + as + select @CourseCount=Count(c.CourseID) + from course as c + where c.DepartmentID=@DepartmentId + + select d.DepartmentID,d.Name,d.Budget,d.StartDate,d.Administrator + from Department as d + where d.DepartmentID=@DepartmentId + + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + Create PROCEDURE [dbo].[GetDepartmentsOfSpecifiedYear] + @Year int,@BudgetSum money output + AS + BEGIN + SELECT @BudgetSum=SUM([Budget]) + FROM [MySchool].[dbo].[Department] + Where YEAR([StartDate])=@Year + + SELECT [DepartmentID] + ,[Name] + ,[Budget] + ,[StartDate] + ,[Administrator] + FROM [MySchool].[dbo].[Department] + Where YEAR([StartDate])=@Year + + END + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + CREATE TABLE [dbo].[Course]([CourseID] [nvarchar](10) NOT NULL, + [Year] [smallint] NOT NULL, + [Title] [nvarchar](100) NOT NULL, + [Credits] [int] NOT NULL, + [DepartmentID] [int] NOT NULL, + CONSTRAINT [PK_Course] PRIMARY KEY CLUSTERED + ( + [CourseID] ASC, + [Year] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] + + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + CREATE TABLE [dbo].[Department]([DepartmentID] [int] IDENTITY(1,1) NOT NULL, + [Name] [nvarchar](50) NOT NULL, + [Budget] [money] NOT NULL, + [StartDate] [datetime] NOT NULL, + [Administrator] [int] NULL, + CONSTRAINT [PK_Department] PRIMARY KEY CLUSTERED + ( + [DepartmentID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] + + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + CREATE TABLE [dbo].[Person]([PersonID] [int] IDENTITY(1,1) NOT NULL, + [LastName] [nvarchar](50) NOT NULL, + [FirstName] [nvarchar](50) NOT NULL, + [HireDate] [datetime] NULL, + [EnrollmentDate] [datetime] NULL, + CONSTRAINT [PK_School.Student] PRIMARY KEY CLUSTERED + ( + [PersonID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] + + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + CREATE TABLE [dbo].[StudentGrade]([EnrollmentID] [int] IDENTITY(1,1) NOT NULL, + [CourseID] [nvarchar](10) NOT NULL, + [StudentID] [int] NOT NULL, + [Grade] [decimal](3, 2) NOT NULL, + CONSTRAINT [PK_StudentGrade] PRIMARY KEY CLUSTERED + ( + [EnrollmentID] ASC + )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY] + + GO + + SET ANSI_NULLS ON + GO + SET QUOTED_IDENTIFIER ON + GO + create view [dbo].[EnglishCourse] + as + select c.CourseID,c.Title,c.Credits,c.DepartmentID + from Course as c join Department as d on c.DepartmentID=d.DepartmentID + where d.Name=N'English' + + GO + INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits], [DepartmentID]) VALUES (N'C1045', 2012, N'Calculus', 4, 7) + INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits], [DepartmentID]) VALUES (N'C1061', 2012, N'Physics', 4, 1) + INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits], [DepartmentID]) VALUES (N'C2021', 2012, N'Composition', 3, 2) + INSERT [dbo].[Course] ([CourseID], [Year], [Title], [Credits], [DepartmentID]) VALUES (N'C2042', 2012, N'Literature', 4, 2) + SET IDENTITY_INSERT [dbo].[Department] ON + + INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget], [StartDate], [Administrator]) VALUES (1, N'Engineering', 350000.0000, CAST(0x0000999C00000000 AS DateTime), 2) + INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget], [StartDate], [Administrator]) VALUES (2, N'English', 120000.0000, CAST(0x0000999C00000000 AS DateTime), 6) + INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget], [StartDate], [Administrator]) VALUES (4, N'Economics', 200000.0000, CAST(0x0000999C00000000 AS DateTime), 4) + INSERT [dbo].[Department] ([DepartmentID], [Name], [Budget], [StartDate], [Administrator]) VALUES (7, N'Mathematics', 250024.0000, CAST(0x0000999C00000000 AS DateTime), 3) + SET IDENTITY_INSERT [dbo].[Department] OFF + SET IDENTITY_INSERT [dbo].[Person] ON + + INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (1, N'Hu', N'Nan', NULL, CAST(0x0000A0BF00000000 AS DateTime)) + INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (2, N'Norman', N'Laura', NULL, CAST(0x0000A0BF00000000 AS DateTime)) + INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (3, N'Olivotto', N'Nino', NULL, CAST(0x0000A0BF00000000 AS DateTime)) + INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (4, N'Anand', N'Arturo', NULL, CAST(0x0000A0BF00000000 AS DateTime)) + INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (5, N'Jai', N'Damien', NULL, CAST(0x0000A0BF00000000 AS DateTime)) + INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (6, N'Holt', N'Roger', CAST(0x000097F100000000 AS DateTime), NULL) + INSERT [dbo].[Person] ([PersonID], [LastName], [FirstName], [HireDate], [EnrollmentDate]) VALUES (7, N'Martin', N'Randall', CAST(0x00008B1A00000000 AS DateTime), NULL) + SET IDENTITY_INSERT [dbo].[Person] OFF + SET IDENTITY_INSERT [dbo].[StudentGrade] ON + + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (1, N'C1045', 1, CAST(3.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (2, N'C1045', 2, CAST(3.00 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (3, N'C1045', 3, CAST(2.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (4, N'C1045', 4, CAST(4.00 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (5, N'C1045', 5, CAST(3.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (6, N'C1061', 1, CAST(4.00 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (7, N'C1061', 3, CAST(3.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (8, N'C1061', 4, CAST(2.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (9, N'C1061', 5, CAST(1.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (10, N'C2021', 1, CAST(2.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (11, N'C2021', 2, CAST(3.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (12, N'C2021', 4, CAST(3.00 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (13, N'C2021', 5, CAST(3.00 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (14, N'C2042', 1, CAST(2.00 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (15, N'C2042', 2, CAST(3.50 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (16, N'C2042', 3, CAST(4.00 AS Decimal(3, 2))) + INSERT [dbo].[StudentGrade] ([EnrollmentID], [CourseID], [StudentID], [Grade]) VALUES (17, N'C2042', 5, CAST(3.00 AS Decimal(3, 2))) + SET IDENTITY_INSERT [dbo].[StudentGrade] OFF + ALTER TABLE [dbo].[Course] WITH CHECK ADD CONSTRAINT [FK_Course_Department] FOREIGN KEY([DepartmentID]) + REFERENCES [dbo].[Department] ([DepartmentID]) + GO + ALTER TABLE [dbo].[Course] CHECK CONSTRAINT [FK_Course_Department] + GO + ALTER TABLE [dbo].[StudentGrade] WITH CHECK ADD CONSTRAINT [FK_StudentGrade_Student] FOREIGN KEY([StudentID]) + REFERENCES [dbo].[Person] ([PersonID]) + GO + ALTER TABLE [dbo].[StudentGrade] CHECK CONSTRAINT [FK_StudentGrade_Student] + GO + ``` + + Next, compile and execute the following: + + ```csharp + using System; + using System.Data; + using Microsoft.Data.SqlClient; + using System.Threading.Tasks; + + class Program { + + static class SqlHelper { + // Set the connection, command, and then execute the command with non query. + public static Int32 ExecuteNonQuery(String connectionString, String commandText, + CommandType commandType, params SqlParameter[] parameters) { + using (SqlConnection conn = new SqlConnection(connectionString)) { + using (SqlCommand cmd = new SqlCommand(commandText, conn)) { + // There're three command types: StoredProcedure, Text, TableDirect. The TableDirect + // type is only for OLE DB. + cmd.CommandType = commandType; + cmd.Parameters.AddRange(parameters); + + conn.Open(); + return cmd.ExecuteNonQuery(); + } + } + } + + // Set the connection, command, and then execute the command and only return one value. + public static Object ExecuteScalar(String connectionString, String commandText, + CommandType commandType, params SqlParameter[] parameters) { + using (SqlConnection conn = new SqlConnection(connectionString)) { + using (SqlCommand cmd = new SqlCommand(commandText, conn)) { + cmd.CommandType = commandType; + cmd.Parameters.AddRange(parameters); + + conn.Open(); + return cmd.ExecuteScalar(); + } + } + } + + // Set the connection, command, and then execute the command with query and return the reader. + public static SqlDataReader ExecuteReader(String connectionString, String commandText, + CommandType commandType, params SqlParameter[] parameters) { + SqlConnection conn = new SqlConnection(connectionString); + + using (SqlCommand cmd = new SqlCommand(commandText, conn)) { + cmd.CommandType = commandType; + cmd.Parameters.AddRange(parameters); + + conn.Open(); + // When using CommandBehavior.CloseConnection, the connection will be closed when the + // IDataReader is closed. + SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); + + return reader; + } + } + } + + static void Main(string[] args) { + String connectionString = "Data Source=(local);Initial Catalog=MySchool;Integrated Security=True;Asynchronous Processing=true;"; + + CountCourses(connectionString, 2012); + Console.WriteLine(); + + Console.WriteLine("Following result is the departments that started from 2007:"); + GetDepartments(connectionString, 2007); + Console.WriteLine(); + + Console.WriteLine("Add the credits when the credits of course is lower than 4."); + AddCredits(connectionString, 4); + Console.WriteLine(); + + Console.WriteLine("Please press any key to exit..."); + Console.ReadKey(); + } + + static void CountCourses(String connectionString, Int32 year) { + String commandText = "Select Count([CourseID]) FROM [MySchool].[dbo].[Course] Where Year=@Year"; + SqlParameter parameterYear = new SqlParameter("@Year", SqlDbType.Int); + parameterYear.Value = year; + + Object oValue = SqlHelper.ExecuteScalar(connectionString, commandText, CommandType.Text, parameterYear); + Int32 count; + if (Int32.TryParse(oValue.ToString(), out count)) + Console.WriteLine("There {0} {1} course{2} in {3}.", count > 1 ? "are" : "is", count, count > 1 ? "s" : null, year); + } + + // Display the Departments that start from the specified year. + static void GetDepartments(String connectionString, Int32 year) { + String commandText = "dbo.GetDepartmentsOfSpecifiedYear"; + + // Specify the year of StartDate + SqlParameter parameterYear = new SqlParameter("@Year", SqlDbType.Int); + parameterYear.Value = year; + + // When the direction of parameter is set as Output, you can get the value after + // executing the command. + SqlParameter parameterBudget = new SqlParameter("@BudgetSum", SqlDbType.Money); + parameterBudget.Direction = ParameterDirection.Output; + + using (SqlDataReader reader = SqlHelper.ExecuteReader(connectionString, commandText, + CommandType.StoredProcedure, parameterYear, parameterBudget)) { + Console.WriteLine("{0,-20}{1,-20}{2,-20}{3,-20}", "Name", "Budget", "StartDate", + "Administrator"); + while (reader.Read()) { + Console.WriteLine("{0,-20}{1,-20:C}{2,-20:d}{3,-20}", reader["Name"], + reader["Budget"], reader["StartDate"], reader["Administrator"]); + } + } + Console.WriteLine("{0,-20}{1,-20:C}", "Sum:", parameterBudget.Value); + } + + // If credits of course is lower than the certain value, the method will add the credits. + static void AddCredits(String connectionString, Int32 creditsLow) { + String commandText = "Update [MySchool].[dbo].[Course] Set Credits=Credits+1 Where Credits<@Credits"; + + SqlParameter parameterCredits = new SqlParameter("@Credits", creditsLow); + + Int32 rows = SqlHelper.ExecuteNonQuery(connectionString, commandText, CommandType.Text, parameterCredits); + + Console.WriteLine("{0} row{1} {2} updated.", rows, rows > 1 ? "s" : null, rows > 1 ? "are" : "is"); + } + } + ``` + + ]]> + + + + + Initializes a new instance of the class. + + . + + |Properties|Initial value| + |----------------|-------------------| + ||empty string ("")| + ||30| + ||`CommandType.Text`| + ||Null| + + You can change the value for any of these properties through a separate call to the property. + + + + ## Examples + The following example creates a and sets the `CommandTimeout` property. + + [!code-csharp[Classic WebData IDbCommand_CommandTimeout.cs](~/sqlClient/doc/samples/ IDbCommand_CommandTimeout.cs)] + + ]]> + + + + The text of the query. + Initializes a new instance of the class with the text of the query. + + is created, the following read/write properties are set to initial values. + + |Properties|Initial value| + |----------------|-------------------| + ||`cmdText`| + ||30| + ||`CommandType.Text`| + ||null| + + You can change the value for any of these properties through a separate call to the property. + + + + ## Examples + The following example creates a , passing in the connection string and command text. + + [!code-csharp[SqlCommand_SqlCommand1](~/sqlClient/doc/samples/ SqlCommand_SqlCommand1.cs.cs)] + + ]]> + + + + The text of the query. + A that represents the connection to an instance of SQL Server. + Initializes a new instance of the class with the text of the query and a . + + . + + |Properties|Initial value| + |----------------|-------------------| + ||`cmdText`| + ||30| + ||`CommandType.Text`| + ||A new that is the value for the `connection` parameter.| + + You can change the value for any of these parameters by setting the related property. + + + + ## Examples + The following example creates a and sets some of its properties. + + [!code-csharp[SqlCommand_SqlCommand2.cs](~/sqlClient/doc/samples/ SqlCommand_SqlCommand2.cs)] + + ]]> + + + + The text of the query. + A that represents the connection to an instance of SQL Server. + The in which the executes. + Initializes a new instance of the class with the text of the query, a , and the . + + . + + |Properties|Initial value| + |----------------|-------------------| + ||`cmdText`| + ||30| + ||`CommandType.Text`| + ||A new that is the value for the `connection` parameter.| + + You can change the value for any of these parameters by setting the related property. + + ]]> + + + + The text of the query. + A that represents the connection to an instance of SQL Server. + The in which the executes. + The encryption setting. For more information, see [Always Encrypted](/sql/relational-databases/security/encryption/always-encrypted-database-engine). + Initializes a new instance of the class with specified command text, connection, transaction, and encryption setting. + To be added. + + + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this . + An that can be used to poll or wait for results, or both; this value is also needed when invoking , which returns the number of affected rows. + + method starts the process of asynchronously executing a [!INCLUDE[tsql](~/includes/tsql-md.md)] statement or stored procedure that does not return rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the method to finish the operation. The method returns immediately ( has no effect on ), but until the code executes the corresponding method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same object. Calling the before the command's execution is completed causes the object to block until the execution is finished. + + Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous. + + Because this overload does not support a callback procedure, developers must either poll to determine whether the command has completed, using the property of the returned by the method; or wait for the completion of one or more commands using the property of the returned . + + + + ## Examples + The following console application creates updates data within the **AdventureWorks** sample database, doing its work asynchronously. In order to emulate a long-running process, this example inserts a WAITFOR statement in the command text. Normally, you would not take efforts to make your commands run slower, but doing this in this case makes it easier to demonstrate the asynchronous behavior. + + [!code-csharp[SqlCommand_BeginExecuteNonQuery](~/sqlClient/doc/samples/ SqlCommand_BeginExecuteNonQuery.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + Any error that occurred while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + An delegate that is invoked when the command's execution has completed. Pass ( in Microsoft Visual Basic) to indicate that no callback is required. + A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the property. + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this , given a callback procedure and state information. + An that can be used to poll or wait for results, or both; this value is also needed when invoking , which returns the number of affected rows. + + method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that does not return rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the method to finish the operation. The method returns immediately ( has no effect on ), but until the code executes the corresponding method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same object. Calling the before the command's execution is completed causes the object to block until the execution is finished. + + The `callback` parameter lets you specify an delegate that is called when the statement has completed. You can call the method from within this delegate procedure, or from any other location within your application. In addition, you can pass any object in the `asyncStateObject` parameter, and your callback procedure can retrieve this information using the property. + + Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous. + + Because the callback procedure executes from within a background thread supplied by the Microsoft .NET common language runtime, it is very important that you take a rigorous approach to handling cross-thread interactions from within your applications. For example, you must not interact with a form's contents from within your callback procedure; should you have to update the form, you must switch back to the form's thread in order to do your work. The example in this topic demonstrates this behavior. + + All errors that occur during the execution of the operation are thrown as exceptions in the callback procedure. You must handle the exception in the callback procedure, not in the main application. See the example in this topic for additional information on handling exceptions in the callback procedure. + + + + ## Examples + The following Windows application demonstrates the use of the method, executing a Transact-SQL statement that includes a delay of several seconds (emulating a long-running command). + + This example demonstrates many important techniques. This includes calling a method that interacts with the form from a separate thread. In addition, this example demonstrates how you must block users from executing a command multiple times concurrently, and how you must make sure that the form does not close before the callback procedure is called. + + To set up this example, create a new Windows application. Put a control and a control on the form (accepting the default name for each control). Add the following code to the form's class, modifying the connection string as needed for your environment. + + [!code-csharp[DataWorks SqlCommand_BeginExecuteNonQueryForm#1](~/sqlClient/doc/samples/ SqlCommand_BeginExecuteNonQueryForm.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + Any error that occurred while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this , and retrieves one or more result sets from the server. + An that can be used to poll or wait for results, or both; this value is also needed when invoking , which returns a instance that can be used to retrieve the returned rows. + + method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that returns rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the method to finish the operation and retrieve the returned by the command. The method returns immediately, but until the code executes the corresponding method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same object. Calling the before the command's execution is completed causes the object to block until the execution is finished. + + Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous. Although command execution is asynchronous, value fetching is still synchronous. This means that calls to may block if more data is required and the underlying network's read operation blocks. + + Because this overload does not support a callback procedure, developers must either poll to determine whether the command has completed, using the property of the returned by the method; or wait for the completion of one or more commands using the property of the returned . + + If you use or to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + + + + ## Examples + The following console application starts the process of retrieving a data reader asynchronously. While waiting for the results, this simple application sits in a loop, investigating the property value. As soon as the process has completed, the code retrieves the and displays its contents. + + [!code-csharp[SqlCommand_BeginExecuteReader#1](~/sqlClient/doc/samples/ SqlCommand_BeginExecuteReader.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + Any error that occurred while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + One of the values, indicating options for statement execution and data retrieval. + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this using one of the values. + An that can be used to poll, wait for results, or both; this value is also needed when invoking , which returns a instance that can be used to retrieve the returned rows. + + method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that returns rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the method to finish the operation and retrieve the returned by the command. The method returns immediately, but until the code executes the corresponding method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same object. Calling the before the command's execution is completed causes the object to block until the execution is finished. + + The `behavior` parameter lets you specify options that control the behavior of the command and its connection. These values can be combined together (using the programming language's `OR` operator); generally, developers use the `CommandBehavior.CloseConnection` value to make sure that the connection is closed by the runtime when the is closed. + + Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous. Although command execution is asynchronous, value fetching is still synchronous. This means that calls to may block if more data is required and the underlying network's read operation blocks. + + Because this overload does not support a callback procedure, developers must either poll to determine whether the command has completed, using the property of the returned by the method; or wait for the completion of one or more commands using the property of the returned . + + If you use or to access XML data, SQL Server returns any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + + + + ## Examples + The following console application starts the process of retrieving a data reader asynchronously. While waiting for the results, this simple application sits in a loop, investigating the property value. Once the process has completed, the code retrieves the and displays its contents. + + This example also passes the `CommandBehavior.CloseConnection` and `CommandBehavior.SingleRow` values in the behavior parameter, causing the connection to be closed with the returned is closed, and to optimize for a single row result. + + [!code-csharp[SqlCommand_BeginExecuteReaderAsyncSimple](~/sqlClient/doc/samples/ SqlCommand_BeginExecuteReaderAsyncSimple.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + Any error that occurred while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + An delegate that is invoked when the command's execution has completed. Pass ( in Microsoft Visual Basic) to indicate that no callback is required. + A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the property. + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this and retrieves one or more result sets from the server, given a callback procedure and state information. + An that can be used to poll, wait for results, or both; this value is also needed when invoking , which returns a instance which can be used to retrieve the returned rows. + + method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that returns rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the method to finish the operation and retrieve the returned by the command. The method returns immediately, but until the code executes the corresponding method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same object. Calling the before the command's execution is completed cause the object to block until the execution is finished. + + The `callback` parameter lets you specify an delegate that is called when the statement has completed. You can call the method from within this delegate procedure, or from any other location within your application. In addition, you can pass any object in the `stateObject` parameter, and your callback procedure can retrieve this information using the property. + + Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous. Although command execution is asynchronous, value fetching is still synchronous. This means that calls to may block if more data is required and the underlying network's read operation blocks. + + Because the callback procedure executes from within a background thread supplied by the Microsoft .NET runtime, it is very important that you take a rigorous approach to handling cross-thread interactions from within your applications. For example, you must not interact with a form's contents from within your callback procedure; should you have to update the form, you must switch back to the form's thread in order to do your work. The example in this topic demonstrates this behavior. + + All errors that occur during the execution of the operation are thrown as exceptions in the callback procedure. You must handle the exception in the callback procedure, not in the main application. See the example in this topic for additional information on handling exceptions in the callback procedure. + + If you use or to access XML data, SQL Server returns any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + + + + ## Examples + The following Windows application demonstrates the use of the method, executing a Transact-SQL statement that includes a delay of a few seconds (emulating a long-running command). Because the sample executes the command asynchronously, the form remains responsive while awaiting the results. This example passes the executing object as the `stateObject` parameter; doing so makes it simple to retrieve the object from within the callback procedure, so that the code can call the method corresponding to the initial call to . + + This example demonstrates many important techniques. This includes calling a method that interacts with the form from a separate thread. In addition, this example demonstrates how you must block users from executing a command multiple times concurrently, and how you must make sure that the form does not close before the callback procedure is called. + + To set up this example, create a new Windows application. Put a control, a control, and a control on the form (accepting the default name for each control). Add the following code to the form's class, modifying the connection string as needed for your environment. + + [!code-csharp[SqlCommand_BeginExecuteReaderAsync.cs](~/sqlClient/doc/samples/ SqlCommand_BeginExecuteReaderAsync.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + Any error that occurred while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + The name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + + An delegate that is invoked when the command's execution has completed. Pass ( in Microsoft Visual Basic) to indicate that no callback is required. + A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the property. + One of the values, indicating options for statement execution and data retrieval. + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this , using one of the values, and retrieving one or more result sets from the server, given a callback procedure and state information. + An that can be used to poll or wait for results, or both; this value is also needed when invoking , which returns a instance which can be used to retrieve the returned rows. + + method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that returns rows, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the method to finish the operation and retrieve the returned by the command. The method returns immediately, but until the code executes the corresponding method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same object. Calling the before the command's execution is completed causes the object to block until the execution is finished. + + The `callback` parameter lets you specify an delegate that is called when the statement has completed. You can call the method from within this delegate procedure, or from any other location within your application. In addition, you can pass any object in the `stateObject` parameter, and your callback procedure can retrieve this information using the property. + + The `behavior` parameter lets you specify options that control the behavior of the command and its connection. These values can be combined together (using the programming language's `Or` operator); generally, developers use the `CloseConnection` value to make sure that the connection is closed by the runtime when the is closed. Developers can also optimize the behavior of the by specifying the `SingleRow` value when it is known in advance that the Transact-SQL statement or stored procedure only returns a single row. + + Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous. Although command execution is asynchronous, value fetching is still synchronous. This means that calls to may block if more data is required and the underlying network's read operation blocks. + + Because the callback procedure executes from within a background thread supplied by the Microsoft .NET common language runtime, it is very important that you take a rigorous approach to handling cross-thread interactions from within your applications. For example, you must not interact with a form's contents from within your callback procedure--should you have to update the form, you must switch back to the form's thread in order to do your work. The example in this topic demonstrates this behavior. + + All errors that occur during the execution of the operation are thrown as exceptions in the callback procedure. You must handle the exception in the callback procedure, not in the main application. See the example in this topic for additional information on handling exceptions in the callback procedure. + + If you use or to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + + + + ## Examples + The following Windows application demonstrates the use of the method, executing a Transact-SQL statement that includes a delay of a few seconds (emulating a long-running command). Because the sample executes the command asynchronously, the form remains responsive while awaiting the results. This example passes the executing object as the `stateObject` parameter; doing so makes it simple to retrieve the object from within the callback procedure, so that the code can call the method corresponding to the initial call to . + + This example demonstrates many important techniques. This includes calling a method that interacts with the form from a separate thread. In addition, this example demonstrates how you must block users from executing a command multiple times concurrently, and how you must make sure that the form does not close before the callback procedure is called. + + To set up this example, create a new Windows application. Put a control, a control, and a control on the form (accepting the default name for each control). Add the following code to the form's class, modifying the connection string as needed for your environment. + + This example passes the `CommandBehavior.CloseConnection` value in the `behavior` parameter, causing the returned to automatically close its connection when it is closed. + + [!code-csharp[SqlCommand_BeginExecuteReaderAsyncBehavior](~/sqlClient/doc/samples/ SqlCommand_BeginExecuteReaderAsyncBehavior.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + Any error that occurred while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this and returns results as an object. + An that can be used to poll or wait for results, or both; this value is also needed when invoking , which returns a single XML value. + + method starts the process of asynchronously executing a Transact-SQL statement that returns rows as XML, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the `EndExecuteXmlReader` method to finish the operation and retrieve the XML returned by the command. The method returns immediately, but until the code executes the corresponding `EndExecuteXmlReader` method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same object. Calling the `EndExecuteXmlReader` before the command's execution is completed causes the object to block until the execution is finished. + + The property ordinarily specifies a Transact-SQL statement with a valid FOR XML clause. However, `CommandText` can also specify a statement that returns `ntext` data that contains valid XML. + + A typical query can be formatted as in the following C# example: + + ```csharp + SqlCommand command = new SqlCommand("SELECT ContactID, FirstName, LastName FROM dbo.Contact FOR XML AUTO, XMLDATA", SqlConn); + ``` + + This method can also be used to retrieve a single-row, single-column result set. In this case, if more than one row is returned, the `EndExecuteXmlReader` method attaches the to the value on the first row, and discards the rest of the result set. + + The multiple active result set (MARS) feature lets multiple actions use the same connection. + + Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters are sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous. Although command execution is asynchronous, value fetching is still synchronous. + + Because this overload does not support a callback procedure, developers need to either poll to determine whether the command has completed, using the property of the returned by the method; or wait for the completion of one or more commands using the property of the returned . + + If you use or to access XML data, SQL Server returns any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + + + + ## Examples + The following console application starts the process of retrieving XML data asynchronously. While waiting for the results, this simple application sits in a loop, investigating the property value. Once the process has completed, the code retrieves the XML and displays its contents. + + [!code-csharp[SqlCommand_BeginExecuteXmlReader#1]((~/sqlClient/doc/samples/ SqlCommand_BeginExecuteXmlReader.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + Any error that occurred while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + The name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + An delegate that is invoked when the command's execution has completed. Pass ( in Microsoft Visual Basic) to indicate that no callback is required. + A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback procedure using the property. + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this and returns results as an object, using a callback procedure. + An that can be used to poll, wait for results, or both; this value is also needed when the is called, which returns the results of the command as XML. + + method starts the process of asynchronously executing a Transact-SQL statement or stored procedure that returns rows as XML, so that other tasks can run concurrently while the statement is executing. When the statement has completed, developers must call the method to finish the operation and retrieve the requested XML data. The method returns immediately, but until the code executes the corresponding method call, it must not execute any other calls that start a synchronous or asynchronous execution against the same object. Calling the before the command's execution is completed causes the object to block until the execution is finished. + + The property ordinarily specifies a Transact-SQL statement with a valid FOR XML clause. However, `CommandText` can also specify a statement that returns data that contains valid XML. This method can also be used to retrieve a single-row, single-column result set. In this case, if more than one row is returned, the method attaches the to the value on the first row, and discards the rest of the result set. + + A typical query can be formatted as in the following C# example: + + ```csharp + SqlCommand command = new SqlCommand("SELECT ContactID, FirstName, LastName FROM Contact FOR XML AUTO, XMLDATA", SqlConn); + ``` + + This method can also be used to retrieve a single-row, single-column result set. In this case, if more than one row is returned, the method attaches the to the value on the first row, and discards the rest of the result set. + + The multiple active result set (MARS) feature lets multiple actions use the same connection. + + The `callback` parameter lets you specify an delegate that is called when the statement has completed. You can call the method from within this delegate procedure, or from any other location within your application. In addition, you can pass any object in the `stateObject` parameter, and your callback procedure can retrieve this information using the property. + + Note that the command text and parameters are sent to the server synchronously. If a large command or many parameters is sent, this method may block during writes. After the command is sent, the method returns immediately without waiting for an answer from the server--that is, reads are asynchronous. + + All errors that occur during the execution of the operation are thrown as exceptions in the callback procedure. You must handle the exception in the callback procedure, not in the main application. See the example in this topic for additional information on handling exceptions in the callback procedure. + + If you use or to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + + + + ## Examples + The following Windows application demonstrates the use of the method, executing a Transact-SQL statement that includes a delay of a few seconds (emulating a long-running command). This example passes the executing object as the `stateObject` parameter--doing so makes it simple to retrieve the object from within the callback procedure, so that the code can call the method corresponding to the initial call to . + + This example demonstrates many important techniques. This includes calling a method that interacts with the form from a separate thread. In addition, this example demonstrates how you must block users from executing a command multiple times concurrently, and how you must make sure that the form does not close before the callback procedure is called. + + To set up this example, create a new Windows application. Put a control, a control, and a control on the form (accepting the default name for each control). Add the following code to the form's class, modifying the connection string as needed for your environment. + + [!code-csharp[SqlCommand_BeginExecuteXmlReaderAsync](~/sqlClient/doc/samples/ SqlCommand_BeginExecuteXmlReaderAsync.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + Any error that occurred while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + The name/value pair "Asynchronous Processing=true" was not included within the connection string defining the connection for this . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + + + Tries to cancel the execution of a . + + , then call (implicitly or explicitly) before calling , and then call , the cancel command will not be sent to SQL Server and the result set can continue to stream after you call . To avoid this, make sure that you call before closing the reader or connection. + + + + ## Examples + The following example demonstrates the use of the method. + + [!code-csharp[SqlCommand_Cancel](~/sqlClient/doc/samples/ WebData SqlCommand_Cancel.cs)] + + ]]> + + + + Creates a new object that is a copy of the current instance. + A new object that is a copy of this instance. + To be added. + + + Gets or sets the column encryption setting for this command. + The column encryption setting for this command. + To be added. + + + Gets or sets the Transact-SQL statement, table name or stored procedure to execute at the data source. + The Transact-SQL statement or stored procedure to execute. The default is an empty string. + + property is set to `StoredProcedure`, the property should be set to the name of the stored procedure. The user may be required to use escape character syntax if the stored procedure name contains any special characters. The command executes this stored procedure when you call one of the `Execute` methods. + + The Microsoft .NET Framework Data Provider for SQL Server does not support the question mark (?) placeholder for passing parameters to a Transact-SQL statement or a stored procedure called by a command of `CommandType.Text`. In this case, named parameters must be used. For example: + + ```sql + SELECT * FROM dbo.Customers WHERE CustomerID = @CustomerID + ``` + + For more information, see [Configuring Parameters and Parameter Data Types](~/docs/framework/data/adonet/configuring-parameters-and-parameter-data-types.md). + + + + ## Examples + The following example creates a and sets some of its properties. + + [!code-csharp[SqlCommand_CommandText](~/sqlClient/doc/samples/ SqlCommand_CommandText.cs)] + + ]]> + + + + Gets or sets the wait time before terminating the attempt to execute a command and generating an error. + The time in seconds to wait for the command to execute. The default is 30 seconds. + + property will be ignored during asynchronous method calls such as . + + has no effect when the command is executed against a context connection (a opened with "context connection=true" in the connection string). + + [!NOTE] + This property is the cumulative time-out (for all network packets that are read during the invocation of a method) for all network reads during command execution or processing of the results. A time-out can still occur after the first row is returned, and does not include user processing time, only network read time. + + For example, with a 30 second time out, if requires two network packets, then it has 30 seconds to read both network packets. If you call again, it will have another 30 seconds to read any data that it requires. + + ```csharp + using System; + using Microsoft.Data.SqlClient; + /// + public class A { + /// + public static void Main() { + string connectionString = ""; + // Wait for 5 second delay in the command + string queryString = "waitfor delay '00:00:05'"; + using (SqlConnection connection = new SqlConnection(connectionString)) { + connection.Open(); + SqlCommand command = new SqlCommand(queryString, connection); + // Setting command timeout to 1 second + command.CommandTimeout = 1; + try { + command.ExecuteNonQuery(); + } + catch (SqlException e) { + Console.WriteLine("Got expected SqlException due to command timeout "); + Console.WriteLine(e); + } + } + } + } + ``` + + ]]> + + + + Gets or sets a value indicating how the property is to be interpreted. + One of the values. The default is . + + property to `StoredProcedure`, you should set the property to the name of the stored procedure. The command executes this stored procedure when you call one of the Execute methods. + + The Microsoft .NET Framework Data Provider for SQL Server does not support the question mark (?) placeholder for passing parameters to a SQL Statement or a stored procedure called with a of . In this case, named parameters must be used. For example: + + SELECT * FROM Customers WHERE CustomerID = @CustomerID + + For more information, see [Configuring Parameters and Parameter Data Types](~/docs/framework/data/adonet/configuring-parameters-and-parameter-data-types.md). + + + + ## Examples + The following example creates a and sets some of its properties. + + [!code-csharp[IDbCommand_CommandTimeout](~/sqlClient/doc/samples/ IDbCommand_CommandTimeout.cs)] + + ]]> + + + + Gets or sets the used by this instance of the . + The connection to a data source. The default value is . + + . + + If the property is not null and the transaction has already been committed or rolled back, is set to null. + + + + ## Examples + The following example creates a and sets some of its properties. + + [!code-csharp[SqlCommand_Connection](~/sqlClient/doc/samples/ SqlCommand_Connection.cs)] + + ]]> + + The property was changed while the command was enlisted in a transaction. + + + + + + To be added. + To be added. + To be added. + + + Creates a new instance of a object. + A object. + + method is a strongly-typed version of . + + ]]> + + + + To be added. + To be added. + To be added. + + + To be added. + To be added. + To be added. + + + To be added. + To be added. + To be added. + + + Gets or sets a value indicating whether the command object should be visible in a Windows Form Designer control. + A value indicating whether the command object should be visible in a control. The default is . + To be added. + + + To be added. + To be added. + To be added. + + + The returned by the call to . + Finishes asynchronous execution of a Transact-SQL statement. + The number of rows affected (the same behavior as ). + + to execute a [!INCLUDE[tsql](~/includes/tsql-md.md)] statement, you must call in order to complete the operation. If the process of executing the command has not yet finished, this method blocks until the operation is complete. Users can verify that the command has completed its operation by using the instance returned by the method. If a callback procedure was specified in the call to , this method must be called. + + + + ## Examples + For examples demonstrating the use of the method, see . + + ]]> + + parameter is null ( in Microsoft Visual Basic) + + was called more than once for a single command execution, or the method was mismatched against its execution method (for example, the code called to complete execution of a call to . + + The amount of time specified in elapsed and the asynchronous operation specified with is not complete. + + -or- + + In some situations, can be set to incorrectly. If this occurs and is called, EndExecuteNonQuery could raise a SqlException error if the amount of time specified in elapsed and the asynchronous operation specified with is not complete. To correct this situation, you should either increase the value of CommandTimeout or reduce the work being done by the asynchronous operation. + + + + The returned by the call to . + Finishes asynchronous execution of a Transact-SQL statement, returning the requested . + A object that can be used to retrieve the requested rows. + + to execute a Transact-SQL statement, you must call in order to complete the operation. If the process of executing the command has not yet finished, this method blocks until the operation is complete. Users can verify that the command has completed its operation by using the instance returned by the method. If a callback procedure was specified in the call to , this method must be called. + + + + ## Examples + For examples demonstrating the use of the method, see . + + ]]> + + parameter is null ( in Microsoft Visual Basic) + + was called more than once for a single command execution, or the method was mismatched against its execution method (for example, the code called to complete execution of a call to . + + + + The returned by the call to . + Finishes asynchronous execution of a Transact-SQL statement, returning the requested data as XML. + An object that can be used to fetch the resulting XML data. + + to execute a Transact-SQL statement, you must call in order to complete the operation. If the process of executing the command has not yet finished, this method blocks until the operation is complete. Users can verify that the command has completed its operation by using the instance returned by the method. If a callback procedure was specified in the call to , this method must be called. + + + + ## Examples + For examples demonstrating the use of the method, see . + + ]]> + + + parameter is null ( in Microsoft Visual Basic) + + was called more than once for a single command execution, or the method was mismatched against its execution method (for example, the code called to complete execution of a call to . + + + + To be added. + To be added. + To be added. + To be added. + + + To be added. + To be added. + To be added. + To be added. + To be added. + + + Executes a Transact-SQL statement against the connection and returns the number of rows affected. + The number of rows affected. + + to perform catalog operations (for example, querying the structure of a database or creating database objects such as tables), or to change the data in a database without using a by executing UPDATE, INSERT, or DELETE statements. + + Although the returns no rows, any output parameters or return values mapped to parameters are populated with data. + + For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. For all other types of statements, the return value is -1. + When a trigger exists on a table being inserted or updated, the return value includes the number of rows affected by both the insert or update operation and the number of rows affected by the trigger or triggers. + When SET NOCOUNT ON is set on the connection (before or as part of executing the command, or as part of a trigger initiated by the execution of the command) the rows affected by individual statements stop contributing to the count of rows affected that is returned by this method. + If no statements are detected that contribute to the count, the return value is -1. If a rollback occurs, the return value is also -1. + ## Examples + The following example creates a and then executes it using . The example is passed a string that is a Transact-SQL statement (such as UPDATE, INSERT, or DELETE) and a string to use to connect to the data source. + + [!code-csharp[SqlCommand_ExecuteNonQuery](~/sqlClient/doc/samples/ SqlCommand_ExecuteNonQuery.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + An exception occurred while executing the command against a locked row. This exception is not generated when you are using Microsoft .NET Framework version 1.0. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + The cancellation instruction. + An asynchronous version of , which executes a [!INCLUDE[tsql](~/includes/tsql-md.md)] statement against the connection and returns the number of rows affected. The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object. + A task representing the asynchronous operation. + + + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + Calling more than once for the same instance before task completion. + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + is specified in the connection string. + + SQL Server returned an error while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + Sends the to the and builds a . + A object. + + property is set to `StoredProcedure`, the property should be set to the name of the stored procedure. The command executes this stored procedure when you call . + + [!NOTE] + If a transaction is deadlocked, an exception may not be thrown until is called. + + The multiple active result set (MARS) feature allows for multiple actions using the same connection. + + If you use or to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + + + + ## Examples + The following example creates a , and then executes it by passing a string that is a Transact-SQL SELECT statement, and a string to use to connect to the data source. + + [!code-csharp[SqlCommand_ExecuteReader](~/sqlClient/doc/samples/ SqlCommand_ExecuteReader.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + An exception occurred while executing the command against a locked row. This exception is not generated when you are using Microsoft .NET Framework version 1.0. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + The current state of the connection is closed. requires an open . + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + One of the values. + Sends the to the , and builds a using one of the values. + A object. + + property is set to `StoredProcedure`, the property should be set to the name of the stored procedure. The command executes this stored procedure when you call . + + [!NOTE] + Use to retrieve large values and binary data. Otherwise, an might occur and the connection will be closed. + + The multiple active result set (MARS) feature allows for multiple actions using the same connection. + + If you use or to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + + + + ## Examples + The following example creates a , and then executes it by passing a string that is a Transact-SQL SELECT statement, and a string to use to connect to the data source. is set to . + + [!code-csharp[SqlCommand_ExecuteReader2](~/sqlClient/doc/samples/ SqlCommand.ExecuteReader2_.cs)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + An asynchronous version of , which sends the to the and builds a . Exceptions will be reported via the returned Task object. + A task representing the asynchronous operation. + + + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + An invalid value. + Calling more than once for the same instance before task completion. + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + is specified in the connection string. + + SQL Server returned an error while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + Options for statement execution and data retrieval. When is set to , reads the entire row before returning a complete Task. + An asynchronous version of , which sends the to the , and builds a . Exceptions will be reported via the returned Task object. + A task representing the asynchronous operation. + + + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + An invalid value. + Calling more than once for the same instance before task completion. + + -or- + + closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + is specified in the connection string. + + SQL Server returned an error while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + The cancellation instruction. + An asynchronous version of , which sends the to the and builds a . + + The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object. + + A task representing the asynchronous operation. + + + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + An invalid value. + Calling more than once for the same instance before task completion. + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + is specified in the connection string. + + SQL Server returned an error while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + Options for statement execution and data retrieval. When is set to , reads the entire row before returning a complete Task. + The cancellation instruction. + An asynchronous version of , which sends the to the , and builds a + + The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object. + A task representing the asynchronous operation. + + + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + An invalid value. + Calling more than once for the same instance before task completion. + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + is specified in the connection string. + SQL Server returned an error while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + + Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored. + The first column of the first row in the result set, or a null reference ( in Visual Basic) if the result set is empty. Returns a maximum of 2033 characters. + + method to retrieve a single value (for example, an aggregate value) from a database. This requires less code than using the method, and then performing the operations that you need to generate the single value using the data returned by a . + + A typical query can be formatted as in the following C# example: + + ```csharp + cmd.CommandText = "SELECT COUNT(*) FROM dbo.region"; + Int32 count = (Int32) cmd.ExecuteScalar(); + ``` + + ## Examples + The following example creates a and then executes it using . The example is passed a string representing a new value to be inserted into a table, and a string to use to connect to the data source. The function returns the new **Identity** column value if a new row was inserted, 0 on failure. + + [!code-csharp[DataWorks SqlCommand.ExecuteScalar#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlCommand.ExecuteScalar/CS/source.cs#1)] + [!code-vb[DataWorks SqlCommand.ExecuteScalar#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/DataWorks SqlCommand.ExecuteScalar/VB/source.vb#1)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + An exception occurred while executing the command against a locked row. This exception is not generated when you are using Microsoft .NET Framework version 1.0. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + The cancellation instruction. + An asynchronous version of , which executes the query asynchronously and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored. + + The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object. + + A task representing the asynchronous operation. + + + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + Calling more than once for the same instance before task completion. + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + is specified in the connection string. + SQL Server returned an error while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + Sends the to the and builds an object. + An object. + + property ordinarily specifies a [!INCLUDE[tsql](~/includes/tsql-md.md)] statement with a valid FOR XML clause. However, can also specify a statement that returns `ntext` or `nvarchar` data that contains valid XML, or the contents of a column defined with the `xml` data type. + + A typical query can be formatted as in the following Microsoft Visual C# example: + + ```csharp + SqlCommand command = new SqlCommand("SELECT * FROM dbo.Customers FOR XML AUTO, XMLDATA", SqlConn); + ``` + + This method can also be used to retrieve a single-row, single-column result set that contains XML data. In this case, if more than one row is returned, the method attaches the to the value on the first row, and discards the rest of the result set. + + The multiple active result set (MARS) feature allows for multiple actions using the same connection. + + If you use or to access XML data, SQL Server will return any XML results greater than 2,033 characters in length in multiple rows of 2,033 characters each. To avoid this behavior, use or to read FOR XML queries. + ## Examples + The following example creates a and then executes it using . The example is passed a string that is a Transact-SQL FOR XML SELECT statement, and a string to use to connect to the data source. + + [!code-csharp[Classic WebData SqlCommand.ExecuteXmlReader#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteXmlReader/CS/mysample.cs#1)] + [!code-vb[Classic WebData SqlCommand.ExecuteXmlReader#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteXmlReader/VB/mysample.vb#1)] + + ]]> + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + An exception occurred while executing the command against a locked row. This exception is not generated when you are using Microsoft .NET Framework version 1.0. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + An asynchronous version of , which sends the to the and builds an object. + + Exceptions will be reported via the returned Task object. + + A task representing the asynchronous operation. + + + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + Calling more than once for the same instance before task completion. + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + is specified in the connection string. + + SQL Server returned an error while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + The cancellation instruction. + An asynchronous version of , which sends the to the and builds an object. + + The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object. + + A task representing the asynchronous operation. + + + + A other than **Binary** or **VarBinary** was used when was set to . For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + A other than **Char**, **NChar**, **NVarChar**, **VarChar**, or **Xml** was used when was set to . + + -or- + + A other than **Xml** was used when was set to . + + Calling more than once for the same instance before task completion. + + -or- + + The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + -or- + + is specified in the connection string. + + SQL Server returned an error while executing the command text. + + -or- + + A timeout occurred during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). + + + Gets or sets a value that specifies the object bound to this command. + When set to null (default), no notification should be requested. + + + + + + Gets or sets a value indicating whether the application should automatically receive query notifications from a common object. + + if the application should automatically receive query notifications; otherwise . The default value is . + + + + + + + Gets the . + The parameters of the Transact-SQL statement or stored procedure. The default is an empty collection. + + and add parameters to the . + + [!code-csharp[DataWorks SqlParameterCollection.AddWithValue#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlParameterCollection.AddWithValue/CS/source.cs#1)] + + ]]> + + + + Creates a prepared version of the command on an instance of SQL Server. + + is set to `StoredProcedure`, the call to should succeed, although it may cause a no-op. + + Before you call , specify the data type of each parameter in the statement to be prepared. For each parameter that has a variable length data type, you must set the property to the maximum size needed. returns an error if these conditions are not met. + + [!NOTE] + If the database context is changed by executing the Transact-SQL `USE ` statement, or by calling the method, then must be called a second time. + + If you call an `Execute` method after calling , any parameter value that is larger than the value specified by the property is automatically truncated to the original specified size of the parameter, and no truncation errors are returned. + + Output parameters (whether prepared or not) must have a user-specified data type. If you specify a variable length data type, you must also specify the maximum . + + Prior to Visual Studio 2010, threw an exception. Beginning in Visual Studio 2010, this method does not throw an exception. + + ## Examples + The following example demonstrates the use of the method. + + [!code-csharp[Classic WebData SqlCommand.Prepare#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand.Prepare/CS/Source.cs#1)] + + ]]> + + + + Resets the property to its default value. + + is 30 seconds. + + ]]> + + + + Occurs when the execution of a Transact-SQL statement completes. + To be added. + + + Creates a new instance of a object. + A object. + To be added. + + + Gets or sets the within which the executes. + The . The default value is . + + property if it is already set to a specific value, and the command is in the process of executing. If you set the transaction property to a object that is not connected to the same as the object, an exception is thrown the next time that you attempt to execute a statement. + + ]]> + + + + Gets or sets how command results are applied to the when used by the **Update** method of the . + One of the values. + + value is **Both** unless the command is automatically generated (as in the case of the ), in which case the default is **None**. + + For more information about using the **UpdatedRowSource** property, see [DataAdapter Parameters](~/docs/framework/data/adonet/dataadapter-parameters.md). + + ]]> + + + + + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml new file mode 100644 index 0000000000..c7a0738e02 --- /dev/null +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml @@ -0,0 +1,37 @@ + + + + + Automatically generates single-table commands that are used to reconcile changes made to a with the associated SQL Server database. This class cannot be inherited. + + does not automatically generate the Transact-SQL statements required to reconcile changes made to a with the associated instance of SQL Server. However, you can create a object to automatically generate Transact-SQL statements for single-table updates if you set the property of the . Then, any additional Transact-SQL statements that you do not set are generated by the . + + The registers itself as a listener for events whenever you set the property. You can only associate one or object with each other at one time. + + To generate INSERT, UPDATE, or DELETE statements, the uses the property to retrieve a required set of metadata automatically. If you change the after the metadata has been retrieved, such as after the first update, you should call the method to update the metadata. + + The `SelectCommand` must also return at least one primary key or unique column. If none are present, an **InvalidOperation** exception is generated, and the commands are not generated. + + The also uses the , , and properties referenced by the . The user should call if one or more of these properties are modified, or if the itself is replaced. Otherwise the , , and properties retain their previous values. + + If you call , the is disassociated from the , and the generated commands are no longer used. + + + + ## Examples + The following example uses the , along and , to select rows from a data source. The example is passed a connection string, a query string that is a Transact-SQL SELECT statement, and a string that is the name of the database table. The example then creates a . + + [!code-csharp[Classic WebData SqlCommandBuilder#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommandBuilder/CS/Source.cs#1)] + + ]]> + + Retrieving and Modifying Data in ADO.NET + SQL Server and ADO.NET + ADO.NET Overview + + + + \ No newline at end of file diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs index 9e6af8cd0b..f8582d59e8 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs @@ -4,12 +4,13 @@ namespace Microsoft.Data.SqlClient { - /// - /// represents the application workload type when connecting to a server - /// + /// public enum ApplicationIntent { + /// ReadWrite = 0, + + /// ReadOnly = 1, } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/OnChangedEventHandler.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/OnChangedEventHandler.cs index 6b272b7162..79f03dedfb 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/OnChangedEventHandler.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/OnChangedEventHandler.cs @@ -4,5 +4,6 @@ namespace Microsoft.Data.SqlClient { + /// public delegate void OnChangeEventHandler(object sender, SqlNotificationEventArgs e); } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs index df8eed3c08..4bfedeb1e9 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs @@ -4,10 +4,16 @@ namespace Microsoft.Data.SqlClient { + /// public enum PoolBlockingPeriod { + /// Auto = 0, // Blocking period OFF for Azure SQL servers, but ON for all other SQL servers. - AlwaysBlock = 1, // Blocking period ON for all SQL servers including Azure SQL servers. + + /// + AlwaysBlock = 1, // Blocking period ON for all SQL servers including Azure SQL servers. + + /// NeverBlock = 2, // Blocking period OFF for all SQL servers including Azure SQL servers. } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SortOrder.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SortOrder.cs index 47eb6ae8df..4ce62535ef 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SortOrder.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SortOrder.cs @@ -4,10 +4,16 @@ namespace Microsoft.Data.SqlClient { + /// public enum SortOrder { + /// Unspecified = -1, + + /// Ascending = 0, + + /// Descending = 1 } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs index c3b9b6c6f5..e44af08a0e 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs @@ -9,51 +9,34 @@ namespace Microsoft.Data.SqlClient { - /// - /// AD Authentication parameters passed by driver to auth providers. - /// + /// public class SqlAuthenticationParameters { - /// - /// Authentication method. - /// + /// public SqlAuthenticationMethod AuthenticationMethod { get; } - /// - /// Resource URI. - /// + /// public string[] Scopes { get; } - /// - /// Authority URI. - /// + /// public string Authority { get; } - /// - /// User login name/id. - /// + /// public string UserId { get; } - /// - /// User password. - /// + /// public string Password { get; } - /// - /// Connection Id. - /// + /// public Guid ConnectionId { get; } - /// - /// Server name. - /// + /// public string ServerName { get; } - /// - /// Database name. - /// + /// public string DatabaseName { get; } + /// protected SqlAuthenticationParameters( SqlAuthenticationMethod authenticationMethod, string serverName, diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProvider.cs index 00dcf95f7d..f9f1fbcd44 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProvider.cs @@ -7,57 +7,31 @@ namespace Microsoft.Data.SqlClient { - /// - /// The public base class for auth providers. - /// Implementations of this class must provide a default constructor if they are intended to be instantiated from app.config. - /// + /// public abstract class SqlAuthenticationProvider { - /// - /// Get an authentication provider by method. - /// - /// Authentication method. - /// Authentication provider or null if not found. + /// public static SqlAuthenticationProvider GetProvider(SqlAuthenticationMethod authenticationMethod) { return SqlAuthenticationProviderManager.Instance.GetProvider(authenticationMethod); } - /// - /// Set an authentication provider by method. - /// - /// Authentication method. - /// Authentication provider. - /// True if succeeded, false otherwise, e.g., the existing provider disallows overriding. + /// public static bool SetProvider(SqlAuthenticationMethod authenticationMethod, SqlAuthenticationProvider provider) { return SqlAuthenticationProviderManager.Instance.SetProvider(authenticationMethod, provider); } - /// - /// This is called immediately before the provider is added in SQL driver's registry. - /// Avoid performing long-waiting task in this method as it can block other threads from accessing provider registry. - /// - /// The authentication type in lower case. + /// public virtual void BeforeLoad(SqlAuthenticationMethod authenticationMethod) { } - /// - /// This is called immediately before the provider is removed from SQL driver's registry. - /// E.g., when a different provider with the same authentication overrides this provider in SQL driver's registry. - /// Avoid performing long-waiting task in this method as it can block other threads from accessing provider registry. - /// - /// The authentication type in lower case. + /// public virtual void BeforeUnload(SqlAuthenticationMethod authenticationMethod) { } - /// - /// A query method to check whether an authentication method is supported. - /// - /// Authentication method in lower case. + /// public abstract bool IsSupported(SqlAuthenticationMethod authenticationMethod); - /// - /// Get a token. - /// + /// public abstract Task AcquireTokenAsync(SqlAuthenticationParameters parameters); } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs index 4f69d8bd5b..f9c63ea336 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs @@ -178,14 +178,10 @@ internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSect public string InitializerType => base["initializerType"] as string; } - /// - /// The abstract initializer class that users can implement to initialize their component before SqlAuthenticationProviderManager starts. - /// + /// public abstract class SqlAuthenticationInitializer { - /// - /// The initialize callback from SqlAuthenticationProviderManager. This is called before SqlAuthenticationProviderManager loads providers. - /// + /// public abstract void Initialize(); } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs index 138e90bfb7..bbe46a3f45 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs @@ -7,25 +7,16 @@ namespace Microsoft.Data.SqlClient { - - /// - /// AD authentication token. - /// + /// public class SqlAuthenticationToken { - /// - /// Token expiration time. - /// + /// public DateTimeOffset ExpiresOn { get; } - /// - /// Token string. - /// + /// public string AccessToken { get; } - /// - /// Constructor. - /// + /// public SqlAuthenticationToken(string accessToken, DateTimeOffset expiresOn) { if (string.IsNullOrEmpty(accessToken)) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs index b53c5c74f4..2d12f1ccab 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs @@ -124,6 +124,8 @@ internal object[] CreateRowBuffer() } } + // ------------------------------------------------------------------------------------------------- + /// public sealed class SqlBulkCopy : IDisposable { private enum ValueSourceType @@ -235,6 +237,9 @@ internal static bool SetAlwaysTaskOnWrite } #endif + // ctor + // + /// public SqlBulkCopy(SqlConnection connection) { if (connection == null) @@ -245,6 +250,7 @@ public SqlBulkCopy(SqlConnection connection) _columnMappings = new SqlBulkCopyColumnMappingCollection(); } + /// public SqlBulkCopy(SqlConnection connection, SqlBulkCopyOptions copyOptions, SqlTransaction externalTransaction) : this(connection) { @@ -260,6 +266,7 @@ public SqlBulkCopy(SqlConnection connection, SqlBulkCopyOptions copyOptions, Sql } } + /// public SqlBulkCopy(string connectionString) { if (connectionString == null) @@ -271,12 +278,14 @@ public SqlBulkCopy(string connectionString) _ownConnection = true; } + /// public SqlBulkCopy(string connectionString, SqlBulkCopyOptions copyOptions) : this(connectionString) { _copyOptions = copyOptions; } + /// public int BatchSize { get @@ -296,6 +305,7 @@ public int BatchSize } } + /// public int BulkCopyTimeout { get @@ -312,6 +322,7 @@ public int BulkCopyTimeout } } + /// public bool EnableStreaming { get @@ -324,6 +335,7 @@ public bool EnableStreaming } } + public SqlBulkCopyColumnMappingCollection ColumnMappings { get @@ -1562,6 +1574,7 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re } } + /// public void WriteToServer(DbDataReader reader) { if (reader == null) @@ -1594,6 +1607,7 @@ public void WriteToServer(DbDataReader reader) } } + /// public void WriteToServer(IDataReader reader) { if (reader == null) @@ -1624,8 +1638,10 @@ public void WriteToServer(IDataReader reader) } } + /// public void WriteToServer(DataTable table) => WriteToServer(table, 0); + /// public void WriteToServer(DataTable table, DataRowState rowState) { if (table == null) @@ -1658,6 +1674,7 @@ public void WriteToServer(DataTable table, DataRowState rowState) } } + /// public void WriteToServer(DataRow[] rows) { SqlStatistics statistics = Statistics; @@ -1699,8 +1716,10 @@ public void WriteToServer(DataRow[] rows) } } + /// public Task WriteToServerAsync(DataRow[] rows) => WriteToServerAsync(rows, CancellationToken.None); + /// public Task WriteToServerAsync(DataRow[] rows, CancellationToken cancellationToken) { Task resultTask = null; @@ -1745,8 +1764,10 @@ public Task WriteToServerAsync(DataRow[] rows, CancellationToken cancellationTok return resultTask; } + /// public Task WriteToServerAsync(DbDataReader reader) => WriteToServerAsync(reader, CancellationToken.None); + /// public Task WriteToServerAsync(DbDataReader reader, CancellationToken cancellationToken) { Task resultTask = null; @@ -1779,8 +1800,10 @@ public Task WriteToServerAsync(DbDataReader reader, CancellationToken cancellati return resultTask; } + /// public Task WriteToServerAsync(IDataReader reader) => WriteToServerAsync(reader, CancellationToken.None); + /// public Task WriteToServerAsync(IDataReader reader, CancellationToken cancellationToken) { Task resultTask = null; @@ -1814,12 +1837,16 @@ public Task WriteToServerAsync(IDataReader reader, CancellationToken cancellatio return resultTask; } + /// public Task WriteToServerAsync(DataTable table) => WriteToServerAsync(table, 0, CancellationToken.None); + /// public Task WriteToServerAsync(DataTable table, CancellationToken cancellationToken) => WriteToServerAsync(table, 0, cancellationToken); + /// public Task WriteToServerAsync(DataTable table, DataRowState rowState) => WriteToServerAsync(table, rowState, CancellationToken.None); + /// public Task WriteToServerAsync(DataTable table, DataRowState rowState, CancellationToken cancellationToken) { Task resultTask = null; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs index 923bab21a2..c7a6097c36 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs @@ -10,7 +10,7 @@ namespace Microsoft.Data.SqlClient // this class helps allows the user to create association between source- and targetcolumns // // - + /// public sealed class SqlBulkCopyColumnMapping { internal string _destinationColumnName; @@ -23,6 +23,7 @@ public sealed class SqlBulkCopyColumnMapping internal int _internalDestinationColumnOrdinal; internal int _internalSourceColumnOrdinal; // -1 indicates an undetermined value + /// public string DestinationColumn { get @@ -40,6 +41,7 @@ public string DestinationColumn } } + /// public int DestinationOrdinal { get @@ -60,6 +62,7 @@ public int DestinationOrdinal } } + /// public string SourceColumn { get @@ -77,6 +80,7 @@ public string SourceColumn } } + /// public int SourceOrdinal { get @@ -97,29 +101,34 @@ public int SourceOrdinal } } + /// public SqlBulkCopyColumnMapping() { _internalSourceColumnOrdinal = -1; } + /// public SqlBulkCopyColumnMapping(string sourceColumn, string destinationColumn) { SourceColumn = sourceColumn; DestinationColumn = destinationColumn; } + /// public SqlBulkCopyColumnMapping(int sourceColumnOrdinal, string destinationColumn) { SourceOrdinal = sourceColumnOrdinal; DestinationColumn = destinationColumn; } + /// public SqlBulkCopyColumnMapping(string sourceColumn, int destinationOrdinal) { SourceColumn = sourceColumn; DestinationOrdinal = destinationOrdinal; } + /// public SqlBulkCopyColumnMapping(int sourceColumnOrdinal, int destinationOrdinal) { SourceOrdinal = sourceColumnOrdinal; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMappingCollection.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMappingCollection.cs index f2ea25adad..98a592ab57 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMappingCollection.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMappingCollection.cs @@ -7,6 +7,7 @@ namespace Microsoft.Data.SqlClient { + /// public sealed class SqlBulkCopyColumnMappingCollection : CollectionBase { private enum MappingSchema @@ -28,6 +29,7 @@ internal SqlBulkCopyColumnMappingCollection() public SqlBulkCopyColumnMapping this[int index] => (SqlBulkCopyColumnMapping)this.List[index]; + /// public SqlBulkCopyColumnMapping Add(SqlBulkCopyColumnMapping bulkCopyColumnMapping) { AssertWriteAccess(); @@ -41,18 +43,21 @@ public SqlBulkCopyColumnMapping Add(SqlBulkCopyColumnMapping bulkCopyColumnMappi return bulkCopyColumnMapping; } + /// public SqlBulkCopyColumnMapping Add(string sourceColumn, string destinationColumn) { AssertWriteAccess(); return Add(new SqlBulkCopyColumnMapping(sourceColumn, destinationColumn)); } + /// public SqlBulkCopyColumnMapping Add(int sourceColumnIndex, string destinationColumn) { AssertWriteAccess(); return Add(new SqlBulkCopyColumnMapping(sourceColumnIndex, destinationColumn)); } + /// public SqlBulkCopyColumnMapping Add(string sourceColumn, int destinationColumnIndex) { AssertWriteAccess(); @@ -64,6 +69,7 @@ public SqlBulkCopyColumnMapping Add(int sourceColumnIndex, int destinationColumn return Add(new SqlBulkCopyColumnMapping(sourceColumnIndex, destinationColumnIndex)); } + /// private void AssertWriteAccess() { if (ReadOnly) @@ -72,14 +78,17 @@ private void AssertWriteAccess() } } + /// public new void Clear() { AssertWriteAccess(); base.Clear(); } + /// public bool Contains(SqlBulkCopyColumnMapping value) => InnerList.Contains(value); + /// public void CopyTo(SqlBulkCopyColumnMapping[] array, int index) => InnerList.CopyTo(array, index); internal void CreateDefaultMapping(int columnCount) @@ -90,20 +99,24 @@ internal void CreateDefaultMapping(int columnCount) } } + /// public int IndexOf(SqlBulkCopyColumnMapping value) => InnerList.IndexOf(value); + /// public void Insert(int index, SqlBulkCopyColumnMapping value) { AssertWriteAccess(); InnerList.Insert(index, value); } + /// public void Remove(SqlBulkCopyColumnMapping value) { AssertWriteAccess(); InnerList.Remove(value); } + /// public new void RemoveAt(int index) { AssertWriteAccess(); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs index add2b8548b..4a9b5bd54c 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs @@ -6,16 +6,32 @@ namespace Microsoft.Data.SqlClient { + /// [Flags] public enum SqlBulkCopyOptions { + /// Default = 0, + + /// KeepIdentity = 1 << 0, + + /// CheckConstraints = 1 << 1, + + /// TableLock = 1 << 2, + + /// KeepNulls = 1 << 3, + + /// FireTriggers = 1 << 4, + + /// UseInternalTransaction = 1 << 5, + + /// AllowEncryptedValueModifications = 1 << 6, } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs index cb82a805a1..957ca1bdaa 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientFactory.cs @@ -6,6 +6,7 @@ namespace Microsoft.Data.SqlClient { + /// public sealed partial class SqlClientFactory : DbProviderFactory { public static readonly SqlClientFactory Instance = new SqlClientFactory(); @@ -14,31 +15,37 @@ private SqlClientFactory() { } + /// public override DbCommand CreateCommand() { return new SqlCommand(); } + /// public override DbCommandBuilder CreateCommandBuilder() { return new SqlCommandBuilder(); } + /// public override DbConnection CreateConnection() { return new SqlConnection(); } + /// public override DbConnectionStringBuilder CreateConnectionStringBuilder() { return new SqlConnectionStringBuilder(); } + /// public override DbDataAdapter CreateDataAdapter() { return new SqlDataAdapter(); } + /// public override DbParameter CreateParameter() { return new SqlParameter(); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsEnums.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsEnums.cs index 7b90a1e1e7..37730346fa 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsEnums.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsEnums.cs @@ -1082,12 +1082,22 @@ public enum SqlCommandColumnEncryptionSetting Disabled, } + /// public enum SqlAuthenticationMethod { + /// NotSpecified = 0, + + /// SqlPassword, + + /// ActiveDirectoryPassword, + + /// ActiveDirectoryIntegrated, + + /// ActiveDirectoryInteractive } // This enum indicates the state of TransparentNetworkIPResolution diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs index 89302df067..556aa65b9c 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs @@ -27,6 +27,7 @@ public enum ApplicationIntent ReadOnly = 1, ReadWrite = 0 } + public delegate void OnChangeEventHandler(object sender, Microsoft.Data.SqlClient.SqlNotificationEventArgs e); public enum PoolBlockingPeriod { @@ -1265,4 +1266,4 @@ public SensitivityProperty(Microsoft.Data.SqlClient.DataClassification.Label lab public Microsoft.Data.SqlClient.DataClassification.InformationType InformationType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } public Microsoft.Data.SqlClient.DataClassification.Label Label { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } } } -} \ No newline at end of file +} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/RelationshipConverter.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/RelationshipConverter.cs index 895649fc72..ac6539a356 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/RelationshipConverter.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/RelationshipConverter.cs @@ -29,47 +29,6 @@ public override bool CanConvertTo(ITypeDescriptorContext context, Type destinati } return base.CanConvertTo(context, destinationType); } - - /// - /// Converts the given object to another type. The most common types to convert - /// are to and from a string object. The default implementation will make a call - /// to ToString on the object if the object is valid and if the destination - /// type is string. If this cannot convert to the desitnation type, this will - /// throw a NotSupportedException. - /// - //public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { - // if (destinationType == null) { - // throw new ArgumentNullException("destinationType"); - // } - - // System.Reflection.ConstructorInfo ctor = null; - // object[] values = null; - - // if (destinationType == typeof(InstanceDescriptor) && value is DataRelation) { - // DataRelation rel = (DataRelation) value; - // DataTable parentTable = rel.ParentKey.Table; - // DataTable childTable = rel.ChildKey.Table; - - // if (Microsoft.Data.Common.ADP.IsEmpty(parentTable.Namespace) && Microsoft.Data.Common.ADP.IsEmpty(childTable.Namespace)) { - // ctor = typeof(DataRelation).GetConstructor(new Type[] { typeof(string) /*relationName*/, typeof(string) /*parentTableName*/, typeof(string) /*childTableName */, - // typeof(string[]) /*parentColumnNames */, typeof(string[]) /*childColumnNames*/, typeof(bool) /*nested*/ } ); - - // values = new object[] { rel.RelationName, rel.ParentKey.Table.TableName, rel.ChildKey.Table.TableName,rel.ParentColumnNames, rel.ChildColumnNames, rel.Nested }; - // } - // else { - // ctor = typeof(DataRelation).GetConstructor(new Type[] { typeof(string)/*relationName*/, typeof(string)/*parentTableName*/, typeof(string)/*parentTableNamespace*/, - // typeof(string)/*childTableName */, typeof(string)/*childTableNamespace */, - // typeof(string[])/*parentColumnNames */, typeof(string[]) /*childColumnNames*/, typeof(bool) /*nested*/} ); - - // values = new object[] { rel.RelationName, rel.ParentKey.Table.TableName, rel.ParentKey.Table.Namespace, rel.ChildKey.Table.TableName, - // rel.ChildKey.Table.Namespace, rel.ParentColumnNames, rel.ChildColumnNames, rel.Nested }; - // } - - // return new InstanceDescriptor(ctor, values); - // } - - // return base.ConvertTo(context, culture, value, destinationType); - //} } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ApplicationIntent.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ApplicationIntent.cs index d402ecdaec..a9a7d3b636 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ApplicationIntent.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ApplicationIntent.cs @@ -7,13 +7,15 @@ namespace Microsoft.Data.SqlClient { - /// - /// represents the application workload type when connecting to a server - /// + + /// [Serializable] public enum ApplicationIntent { + /// ReadWrite = 0, + + /// ReadOnly = 1, } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/OnChangedEventHandler.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/OnChangedEventHandler.cs index 07620907ea..8187a149dd 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/OnChangedEventHandler.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/OnChangedEventHandler.cs @@ -4,6 +4,7 @@ namespace Microsoft.Data.SqlClient { + /// public delegate void OnChangeEventHandler(object sender, SqlNotificationEventArgs e); } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs index 0504e62977..35a2c5fb00 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs @@ -6,14 +6,18 @@ namespace Microsoft.Data.SqlClient { - /// - /// represents the Pool Blocking Period behaviour for connections in connection pool - /// + + /// [Serializable] public enum PoolBlockingPeriod { + /// Auto = 0, + + /// AlwaysBlock = 1, + + /// NeverBlock = 2, } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SortOrder.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SortOrder.cs index 91ee556041..d07d406464 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SortOrder.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SortOrder.cs @@ -4,10 +4,16 @@ namespace Microsoft.Data.SqlClient { + /// public enum SortOrder { + /// Unspecified = -1, + + /// Ascending = 0, + + /// Descending = 1 } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs index c3b9b6c6f5..e44af08a0e 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationParameters.cs @@ -9,51 +9,34 @@ namespace Microsoft.Data.SqlClient { - /// - /// AD Authentication parameters passed by driver to auth providers. - /// + /// public class SqlAuthenticationParameters { - /// - /// Authentication method. - /// + /// public SqlAuthenticationMethod AuthenticationMethod { get; } - /// - /// Resource URI. - /// + /// public string[] Scopes { get; } - /// - /// Authority URI. - /// + /// public string Authority { get; } - /// - /// User login name/id. - /// + /// public string UserId { get; } - /// - /// User password. - /// + /// public string Password { get; } - /// - /// Connection Id. - /// + /// public Guid ConnectionId { get; } - /// - /// Server name. - /// + /// public string ServerName { get; } - /// - /// Database name. - /// + /// public string DatabaseName { get; } + /// protected SqlAuthenticationParameters( SqlAuthenticationMethod authenticationMethod, string serverName, diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationProvider.cs index bbc59eea80..ff3793ac13 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationProvider.cs @@ -7,57 +7,31 @@ namespace Microsoft.Data.SqlClient { - /// - /// The public base class for auth providers. - /// Implementations of this class must provide a default constructor if they are intended to be instantiated from app.config. - /// + /// public abstract class SqlAuthenticationProvider { - - /// Get an authentication provider by method. - /// - /// Authentication method. - /// Authentication provider or null if not found. + /// public static SqlAuthenticationProvider GetProvider(SqlAuthenticationMethod authenticationMethod) { return SqlAuthenticationProviderManager.Instance.GetProvider(authenticationMethod); } - /// - /// Set an authentication provider by method. - /// - /// Authentication method. - /// Authentication provider. - /// True if succeeded, false otherwise, e.g., the existing provider disallows overriding. + /// public static bool SetProvider(SqlAuthenticationMethod authenticationMethod, SqlAuthenticationProvider provider) { return SqlAuthenticationProviderManager.Instance.SetProvider(authenticationMethod, provider); } - /// - /// This is called immediately before the provider is added in SQL driver's registry. - /// Avoid performing long-waiting task in this method as it can block other threads from accessing provider registry. - /// - /// The authentication type in lower case. + /// public virtual void BeforeLoad(SqlAuthenticationMethod authenticationMethod) { } - /// - /// This is called immediately before the provider is removed from SQL driver's registry. - /// E.g., when a different provider with the same authentication overrides this provider in SQL driver's registry. - /// Avoid performing long-waiting task in this method as it can block other threads from accessing provider registry. - /// - /// The authentication type in lower case. + /// public virtual void BeforeUnload(SqlAuthenticationMethod authenticationMethod) { } - /// - /// A query method to check whether an authentication method is supported. - /// - /// Authentication method in lower case. + /// public abstract bool IsSupported(SqlAuthenticationMethod authenticationMethod); - /// - /// Get a token. - /// + /// public abstract Task AcquireTokenAsync(SqlAuthenticationParameters parameters); } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs index 49f216deac..9e948e391a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs @@ -202,14 +202,12 @@ internal class SqlAuthenticationProviderConfigurationSection : ConfigurationSect public string InitializerType => base["initializerType"] as string; } - /// - /// The abstract initializer class that users can implement to initialize their component before SqlAuthenticationProviderManager starts. - /// + + /// public abstract class SqlAuthenticationInitializer { - /// - /// The initialize callback from SqlAuthenticationProviderManager. This is called before SqlAuthenticationProviderManager loads providers. - /// + + /// public abstract void Initialize(); } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs index 138e90bfb7..140e7c3b93 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs @@ -8,24 +8,16 @@ namespace Microsoft.Data.SqlClient { - /// - /// AD authentication token. - /// + /// public class SqlAuthenticationToken { - /// - /// Token expiration time. - /// + /// public DateTimeOffset ExpiresOn { get; } - /// - /// Token string. - /// + /// public string AccessToken { get; } - /// - /// Constructor. - /// + /// public SqlAuthenticationToken(string accessToken, DateTimeOffset expiresOn) { if (string.IsNullOrEmpty(accessToken)) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs index c0cbcc261a..50579a92de 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs @@ -168,8 +168,7 @@ internal object[] CreateRowBuffer() } // ------------------------------------------------------------------------------------------------- - // - // + /// public sealed class SqlBulkCopy : IDisposable { private enum TableNameComponents @@ -300,6 +299,7 @@ internal static bool SetAlwaysTaskOnWrite { #endif // ctor // + /// public SqlBulkCopy(SqlConnection connection) { if (connection == null) @@ -310,6 +310,7 @@ public SqlBulkCopy(SqlConnection connection) _columnMappings = new SqlBulkCopyColumnMappingCollection(); } + /// public SqlBulkCopy(SqlConnection connection, SqlBulkCopyOptions copyOptions, SqlTransaction externalTransaction) : this(connection) { @@ -326,6 +327,7 @@ public SqlBulkCopy(SqlConnection connection, SqlBulkCopyOptions copyOptions, Sql } } + /// public SqlBulkCopy(string connectionString) : this(new SqlConnection(connectionString)) { if (connectionString == null) @@ -337,12 +339,14 @@ public SqlBulkCopy(string connectionString) : this(new SqlConnection(connectionS _ownConnection = true; } + /// public SqlBulkCopy(string connectionString, SqlBulkCopyOptions copyOptions) : this(connectionString) { _copyOptions = copyOptions; } + /// public int BatchSize { get @@ -362,6 +366,7 @@ public int BatchSize } } + /// public int BulkCopyTimeout { get @@ -378,6 +383,7 @@ public int BulkCopyTimeout } } + /// public bool EnableStreaming { get @@ -390,6 +396,7 @@ public bool EnableStreaming } } + /// public SqlBulkCopyColumnMappingCollection ColumnMappings { get @@ -398,6 +405,7 @@ public SqlBulkCopyColumnMappingCollection ColumnMappings } } + /// public string DestinationTableName { get @@ -418,6 +426,7 @@ public string DestinationTableName } } + /// public int NotifyAfter { get @@ -476,6 +485,7 @@ internal SqlStatistics Statistics //================================================================ // IDisposable //================================================================ + /// void IDisposable.Dispose() { this.Dispose(true); @@ -1716,6 +1726,7 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re } } + /// public void WriteToServer(DbDataReader reader) { SqlConnection.ExecutePermission.Demand(); @@ -1753,6 +1764,7 @@ public void WriteToServer(DbDataReader reader) } } + /// public void WriteToServer(IDataReader reader) { SqlConnection.ExecutePermission.Demand(); @@ -1789,11 +1801,13 @@ public void WriteToServer(IDataReader reader) } } + /// public void WriteToServer(DataTable table) { WriteToServer(table, 0); } + /// public void WriteToServer(DataTable table, DataRowState rowState) { SqlConnection.ExecutePermission.Demand(); @@ -1828,6 +1842,7 @@ public void WriteToServer(DataTable table, DataRowState rowState) } } + /// public void WriteToServer(DataRow[] rows) { SqlConnection.ExecutePermission.Demand(); @@ -1871,12 +1886,14 @@ public void WriteToServer(DataRow[] rows) } } + /// /*Async overloads start here*/ public Task WriteToServerAsync(DataRow[] rows) { return WriteToServerAsync(rows, CancellationToken.None); } + /// public Task WriteToServerAsync(DataRow[] rows, CancellationToken cancellationToken) { Task resultTask = null; @@ -1930,10 +1947,13 @@ public Task WriteToServerAsync(DataRow[] rows, CancellationToken cancellationTok return resultTask; } + /// public Task WriteToServerAsync(DbDataReader reader) { return WriteToServerAsync(reader, CancellationToken.None); } + + /// public Task WriteToServerAsync(DbDataReader reader, CancellationToken cancellationToken) { Task resultTask = null; @@ -1968,10 +1988,13 @@ public Task WriteToServerAsync(DbDataReader reader, CancellationToken cancellati return resultTask; } + /// public Task WriteToServerAsync(IDataReader reader) { return WriteToServerAsync(reader, CancellationToken.None); } + + /// public Task WriteToServerAsync(IDataReader reader, CancellationToken cancellationToken) { Task resultTask = null; @@ -2006,18 +2029,25 @@ public Task WriteToServerAsync(IDataReader reader, CancellationToken cancellatio return resultTask; } + /// public Task WriteToServerAsync(DataTable table) { return WriteToServerAsync(table, 0, CancellationToken.None); } + + /// public Task WriteToServerAsync(DataTable table, CancellationToken cancellationToken) { return WriteToServerAsync(table, 0, cancellationToken); } + + /// public Task WriteToServerAsync(DataTable table, DataRowState rowState) { return WriteToServerAsync(table, rowState, CancellationToken.None); } + + /// public Task WriteToServerAsync(DataTable table, DataRowState rowState, CancellationToken cancellationToken) { Task resultTask = null; @@ -2276,6 +2306,7 @@ internal void OnConnectionClosed() } } + /// private void OnRowsCopied(SqlRowsCopiedEventArgs value) { SqlRowsCopiedEventHandler handler = _rowsCopiedEventHandler; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs index 923bab21a2..601fd144ba 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs @@ -10,7 +10,7 @@ namespace Microsoft.Data.SqlClient // this class helps allows the user to create association between source- and targetcolumns // // - + /// public sealed class SqlBulkCopyColumnMapping { internal string _destinationColumnName; @@ -23,6 +23,7 @@ public sealed class SqlBulkCopyColumnMapping internal int _internalDestinationColumnOrdinal; internal int _internalSourceColumnOrdinal; // -1 indicates an undetermined value + /// public string DestinationColumn { get @@ -40,6 +41,7 @@ public string DestinationColumn } } + /// public int DestinationOrdinal { get @@ -60,6 +62,7 @@ public int DestinationOrdinal } } + /// public string SourceColumn { get @@ -77,6 +80,7 @@ public string SourceColumn } } + /// public int SourceOrdinal { get @@ -97,29 +101,34 @@ public int SourceOrdinal } } + /// public SqlBulkCopyColumnMapping() { _internalSourceColumnOrdinal = -1; } + /// public SqlBulkCopyColumnMapping(string sourceColumn, string destinationColumn) { SourceColumn = sourceColumn; DestinationColumn = destinationColumn; } + /// public SqlBulkCopyColumnMapping(int sourceColumnOrdinal, string destinationColumn) { SourceOrdinal = sourceColumnOrdinal; DestinationColumn = destinationColumn; } + /// public SqlBulkCopyColumnMapping(string sourceColumn, int destinationOrdinal) { SourceColumn = sourceColumn; DestinationOrdinal = destinationOrdinal; } + /// public SqlBulkCopyColumnMapping(int sourceColumnOrdinal, int destinationOrdinal) { SourceOrdinal = sourceColumnOrdinal; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMappingCollection.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMappingCollection.cs index 17bbd19f28..ce98c36fab 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMappingCollection.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMappingCollection.cs @@ -8,6 +8,7 @@ namespace Microsoft.Data.SqlClient { + /// public sealed class SqlBulkCopyColumnMappingCollection : CollectionBase { @@ -47,7 +48,7 @@ internal bool ReadOnly } } - + /// public SqlBulkCopyColumnMapping Add(SqlBulkCopyColumnMapping bulkCopyColumnMapping) { AssertWriteAccess(); @@ -61,6 +62,7 @@ public SqlBulkCopyColumnMapping Add(SqlBulkCopyColumnMapping bulkCopyColumnMappi return bulkCopyColumnMapping; } + /// public SqlBulkCopyColumnMapping Add(string sourceColumn, string destinationColumn) { AssertWriteAccess(); @@ -68,6 +70,7 @@ public SqlBulkCopyColumnMapping Add(string sourceColumn, string destinationColum return Add(column); } + /// public SqlBulkCopyColumnMapping Add(int sourceColumnIndex, string destinationColumn) { AssertWriteAccess(); @@ -75,12 +78,15 @@ public SqlBulkCopyColumnMapping Add(int sourceColumnIndex, string destinationCol return Add(column); } + /// public SqlBulkCopyColumnMapping Add(string sourceColumn, int destinationColumnIndex) { AssertWriteAccess(); SqlBulkCopyColumnMapping column = new SqlBulkCopyColumnMapping(sourceColumn, destinationColumnIndex); return Add(column); } + + /// public SqlBulkCopyColumnMapping Add(int sourceColumnIndex, int destinationColumnIndex) { AssertWriteAccess(); @@ -96,17 +102,20 @@ private void AssertWriteAccess() } } + /// new public void Clear() { AssertWriteAccess(); base.Clear(); } + /// public bool Contains(SqlBulkCopyColumnMapping value) { return (-1 != InnerList.IndexOf(value)); } + /// public void CopyTo(SqlBulkCopyColumnMapping[] array, int index) { InnerList.CopyTo(array, index); @@ -120,23 +129,27 @@ internal void CreateDefaultMapping(int columnCount) } } + /// public int IndexOf(SqlBulkCopyColumnMapping value) { return InnerList.IndexOf(value); } + /// public void Insert(int index, SqlBulkCopyColumnMapping value) { AssertWriteAccess(); InnerList.Insert(index, value); } + /// public void Remove(SqlBulkCopyColumnMapping value) { AssertWriteAccess(); InnerList.Remove(value); } + /// new public void RemoveAt(int index) { AssertWriteAccess(); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs index 7592d39d6b..4a9b5bd54c 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopyOptions.cs @@ -6,17 +6,32 @@ namespace Microsoft.Data.SqlClient { - + /// [Flags] public enum SqlBulkCopyOptions { + /// Default = 0, + + /// KeepIdentity = 1 << 0, + + /// CheckConstraints = 1 << 1, + + /// TableLock = 1 << 2, + + /// KeepNulls = 1 << 3, + + /// FireTriggers = 1 << 4, + + /// UseInternalTransaction = 1 << 5, + + /// AllowEncryptedValueModifications = 1 << 6, } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.cs index dcf1eadaf4..45e288c368 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientFactory.cs @@ -11,7 +11,7 @@ namespace Microsoft.Data.SqlClient { - + /// public sealed class SqlClientFactory : DbProviderFactory, IServiceProvider { @@ -21,6 +21,7 @@ private SqlClientFactory() { } + /// public override bool CanCreateDataSourceEnumerator { get @@ -29,41 +30,49 @@ public override bool CanCreateDataSourceEnumerator } } + /// public override DbCommand CreateCommand() { return new SqlCommand(); } + /// public override DbCommandBuilder CreateCommandBuilder() { return new SqlCommandBuilder(); } + /// public override DbConnection CreateConnection() { return new SqlConnection(); } + /// public override DbConnectionStringBuilder CreateConnectionStringBuilder() { return new SqlConnectionStringBuilder(); } + /// public override DbDataAdapter CreateDataAdapter() { return new SqlDataAdapter(); } + /// public override DbParameter CreateParameter() { return new SqlParameter(); } + /// public override CodeAccessPermission CreatePermission(PermissionState state) { return new SqlClientPermission(state); } + /// public override DbDataSourceEnumerator CreateDataSourceEnumerator() { return SqlDataSourceEnumerator.Instance; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsEnums.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsEnums.cs index 74ebb081ac..3f8ab8368d 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsEnums.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsEnums.cs @@ -1046,12 +1046,22 @@ public enum SqlCommandColumnEncryptionSetting Disabled, } + /// public enum SqlAuthenticationMethod { + /// NotSpecified = 0, + + /// SqlPassword, + + /// ActiveDirectoryPassword, + + /// ActiveDirectoryIntegrated, + + /// ActiveDirectoryInteractive, #if ADONET_CERT_AUTH SqlCertificate From eb05ec393d20c30ef4f4b079d6a5fabd87dd2dee Mon Sep 17 00:00:00 2001 From: Javad Date: Thu, 19 Sep 2019 11:37:08 -0700 Subject: [PATCH 2/9] Documentation updated --- doc/samples/DataTableReader_GetValues.cs | 4 +- doc/samples/IDbCommand_CommandTimeout.cs | 2 +- doc/samples/SqlBulkCopy_ColumnMapping.cs | 2 +- .../SqlBulkCopy_ColumnMappingCollection.cs | 2 +- ...BulkCopy_ColumnMappingCollectionOrdinal.cs | 2 +- .../SqlBulkCopy_ColumnMappingIndexColName.cs | 2 +- .../SqlBulkCopy_ColumnMappingRemove.cs | 2 +- ...qlCommand.BeginExecuteReaderAsyncSimple.cs | 2 +- .../SqlCommand_BeginExecuteNonQuery.cs | 2 +- .../SqlCommand_BeginExecuteNonQueryForm.cs | 4 +- ...Command_BeginExecuteReaderAsyncBehavior.cs | 2 +- .../SqlCommand_BeginExecuteXmlReader.cs | 2 +- .../SqlCommand_BeginExecuteXmlReaderAsync.cs | 2 +- doc/samples/SqlCommand_CommandText.cs | 3 +- doc/samples/SqlCommand_Connection.cs | 3 +- doc/samples/SqlCommand_ExecuteNonQuery.cs | 2 +- doc/samples/SqlCommand_ExecuteReader.cs | 5 +- doc/samples/SqlCommand_ExecuteReader2.cs | 5 +- doc/samples/SqlCommand_SqlCommand1.cs | 2 +- doc/samples/SqlConnectionStringBuilder.cs | 2 +- doc/samples/SqlConnectionStringBuilder2.cs | 2 +- doc/samples/SqlConnectionStringBuilder3.cs | 2 +- ...ConnectionStringBuilder_ApplicationName.cs | 2 +- ...onnectionStringBuilder_AttachDBFilename.cs | 2 +- .../SqlConnectionStringBuilder_Clear.cs | 2 +- ...lConnectionStringBuilder_ConnectTimeout.cs | 2 +- .../SqlConnectionStringBuilder_ContainsKey.cs | 2 +- .../SqlConnectionStringBuilder_DataSource.cs | 2 +- ...lConnectionStringBuilder_InitialCatalog.cs | 2 +- ...nectionStringBuilder_IntegratedSecurity.cs | 2 +- .../SqlConnectionStringBuilder_Keys.cs | 2 +- ...nStringBuilder_MultipleActiveResultSets.cs | 2 +- .../SqlConnectionStringBuilder_Password.cs | 2 +- .../SqlConnectionStringBuilder_Remove.cs | 2 +- .../SqlConnectionStringBuilder_TryGetValue.cs | 2 +- .../SqlConnectionStringBuilder_Values.cs | 2 +- doc/samples/SqlConnection_BeginTransaction.cs | 2 +- .../SqlConnection_BeginTransaction1.cs | 2 +- .../SqlConnection_BeginTransaction2.cs | 2 +- .../SqlConnection_BeginTransaction3.cs | 2 +- doc/samples/SqlConnection_ConnectionString.cs | 2 +- .../SqlConnection_ConnectionString1.cs | 2 +- .../SqlConnection_ConnectionTimeout.cs | 2 +- doc/samples/SqlConnection_DataSource.cs | 2 +- doc/samples/SqlConnection_Database.cs | 2 +- doc/samples/SqlConnection_Open.cs | 2 +- doc/samples/SqlConnection_PacketSize.cs | 2 +- doc/samples/SqlConnection_ServerVersion.cs | 2 +- doc/samples/SqlConnection_SqlConnection.cs | 2 +- doc/samples/SqlConnection_SqlConnection1.cs | 2 +- doc/samples/SqlConnection_WorkstationId.cs | 2 +- doc/samples/SqlDataAdapter.cs | 2 +- doc/samples/SqlDataAdapter_RowUpdated.cs | 2 +- doc/samples/SqlDataAdapter_SelectCommand.cs | 2 +- doc/samples/SqlDataAdapter_SqlDataAdapter.cs | 2 +- doc/samples/SqlDataAdapter_SqlDataAdapter1.cs | 2 +- doc/samples/SqlDataAdapter_SqlDataAdapter2.cs | 2 +- doc/samples/SqlDataAdapter_SqlDataAdapter3.cs | 2 +- doc/samples/SqlDataReader_Close.cs | 2 +- doc/samples/SqlDataReader_GetOrdinal.cs | 2 +- doc/samples/SqlDataReader_IsDBNull.cs | 2 +- doc/samples/SqlDataReader_Read.cs | 2 +- doc/samples/SqlError_State.cs | 2 +- doc/samples/SqlError_ToString.cs | 2 +- doc/samples/SqlException_Errors1.cs | 2 +- doc/samples/SqlException_Errors2.cs | 2 +- doc/samples/SqlParameter.cs | 5 +- doc/samples/SqlParameterCollection_Add.cs | 2 +- doc/samples/SqlParameterCollection_Add1.cs | 2 +- doc/samples/SqlParameterCollection_Add3.cs | 2 +- doc/samples/SqlParameterCollection_Add5.cs | 2 +- doc/samples/SqlParameterCollection_Add6.cs | 2 +- .../SqlParameterCollection_AddWithValue.cs | 2 +- doc/samples/SqlParameterCollection_Count.cs | 2 +- doc/samples/SqlParameterCollection_Remove.cs | 2 +- doc/samples/SqlParameter_IsNullable.cs | 2 +- doc/samples/SqlParameter_ParameterName.cs | 2 +- doc/samples/SqlParameter_Precision.cs | 2 +- doc/samples/SqlParameter_SqlParameter.cs | 2 +- doc/samples/SqlParameter_SqlParameter1.cs | 2 +- doc/samples/SqlParameter_SqlParameter2.cs | 2 +- doc/samples/SqlParameter_SqlParameter5.cs | 2 +- doc/samples/SqlParameter_SqlParameter6.cs | 2 +- doc/samples/SqlRowUpdatingEventArgs.cs | 2 +- doc/samples/TransactionIsolationLevels.cs | 2 +- .../Microsoft.Data.SqlClient/SQLDebugging.xml | 1 - .../SqlClientLogger.xml | 4 +- .../SqlClientMetaDataCollectionNames.xml | 18 +- .../SqlClientPermission.xml | 6 +- .../SqlClientPermissionAttribute.xml | 2 - .../SqlColumnEncryptionCngProvider.xml | 4 +- .../SqlColumnEncryptionCspProvider.xml | 7 +- .../SqlColumnEncryptionEnclaveProvider.xml | 4 +- .../SqlColumnEncryptionKeyStoreProvider.xml | 4 +- .../Microsoft.Data.SqlClient/SqlCommand.xml | 40 +-- .../SqlConnection.xml | 10 +- .../kernel32/Interop.IoControlCodeAccess.cs | 4 - .../SqlClientMetaDataCollectionNames.cs | 26 ++ .../SqlColumnEncryptionCngProvider.Windows.cs | 51 +-- .../SqlColumnEncryptionEnclaveProvider.cs | 24 +- .../Microsoft/Data/SqlClient/SqlCommand.cs | 84 +++-- ...SqlClientEncryptionAlgorithmFactoryList.cs | 8 +- .../Data/SqlClient/SqlClientLogger.cs | 20 +- .../SqlClientMetaDataCollectionNames.cs | 28 +- .../Data/SqlClient/SqlClientPermission.cs | 7 +- ...olumnEncryptionCertificateStoreProvider.cs | 43 +-- .../SqlColumnEncryptionCngProvider.cs | 51 +-- .../SqlColumnEncryptionCspProvider.cs | 55 +--- .../SqlColumnEncryptionEnclaveProvider.cs | 33 +- .../SqlColumnEncryptionKeyStoreProvider.cs | 47 +-- .../Microsoft/Data/SqlClient/SqlCommand.cs | 296 ++++++++++++------ .../Microsoft/Data/SqlClient/SqlConnection.cs | 3 +- 112 files changed, 508 insertions(+), 557 deletions(-) diff --git a/doc/samples/DataTableReader_GetValues.cs b/doc/samples/DataTableReader_GetValues.cs index 48f2737b5c..184ff94c3d 100644 --- a/doc/samples/DataTableReader_GetValues.cs +++ b/doc/samples/DataTableReader_GetValues.cs @@ -1,3 +1,4 @@ +// using System; using System.Data; using Microsoft.Data.SqlClient; @@ -7,7 +8,6 @@ class Program static void Main() { } - // // using Microsoft.Data.SqlClient; private static void TestGetValues(DataTableReader reader) { @@ -72,4 +72,4 @@ private static void TestGetValues(SqlDataReader reader) Console.WriteLine(values[i]); } // -} +} \ No newline at end of file diff --git a/doc/samples/IDbCommand_CommandTimeout.cs b/doc/samples/IDbCommand_CommandTimeout.cs index 4b2b5c675e..74a5372a42 100644 --- a/doc/samples/IDbCommand_CommandTimeout.cs +++ b/doc/samples/IDbCommand_CommandTimeout.cs @@ -1,3 +1,4 @@ +// using System; using System.Xml; using System.Data; @@ -11,7 +12,6 @@ public class Form1: Form protected DataGrid dataGrid1; -// public void CreateSqlCommand() { SqlCommand command = new SqlCommand(); diff --git a/doc/samples/SqlBulkCopy_ColumnMapping.cs b/doc/samples/SqlBulkCopy_ColumnMapping.cs index 5f1c1d12f2..5a35ffdfde 100644 --- a/doc/samples/SqlBulkCopy_ColumnMapping.cs +++ b/doc/samples/SqlBulkCopy_ColumnMapping.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft..Data.SqlClient; class Program diff --git a/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs b/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs index 7db2818f0c..81880874fa 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; class Program diff --git a/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs b/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs index ac4f3f3cad..53f6b55edc 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; class Program diff --git a/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs b/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs index ac4f3f3cad..53f6b55edc 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; class Program diff --git a/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs b/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs index ce2742d250..f5e7fa8e7f 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; class Program diff --git a/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs b/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs index ca54cf210a..0079c6abe7 100644 --- a/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs +++ b/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; class Class1 { diff --git a/doc/samples/SqlCommand_BeginExecuteNonQuery.cs b/doc/samples/SqlCommand_BeginExecuteNonQuery.cs index 2e1f72719e..05cfb37a4c 100644 --- a/doc/samples/SqlCommand_BeginExecuteNonQuery.cs +++ b/doc/samples/SqlCommand_BeginExecuteNonQuery.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; class Class1 diff --git a/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs b/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs index 1b342459a8..d8e4019899 100644 --- a/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs +++ b/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs @@ -1,3 +1,4 @@ +// using System; using System.Collections.Generic; using System.ComponentModel; @@ -5,8 +6,7 @@ using System.Drawing; using System.Text; using System.Windows.Forms; -// -using System.Data.SqlClient; +using Microsoft.Data.SqlClient; namespace Microsoft.AdoDotNet.CodeSamples { diff --git a/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs b/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs index c815a80edb..4d4e670cd2 100644 --- a/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs +++ b/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs @@ -1,3 +1,4 @@ +// using System; using System.Collections.Generic; using System.ComponentModel; @@ -5,7 +6,6 @@ using System.Drawing; using System.Text; using System.Windows.Forms; -// using Microsoft.Data.SqlClient; namespace Microsoft.AdoDotNet.CodeSamples diff --git a/doc/samples/SqlCommand_BeginExecuteXmlReader.cs b/doc/samples/SqlCommand_BeginExecuteXmlReader.cs index 5b179dfb0b..83c800183a 100644 --- a/doc/samples/SqlCommand_BeginExecuteXmlReader.cs +++ b/doc/samples/SqlCommand_BeginExecuteXmlReader.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; using System.Xml; diff --git a/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs b/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs index 4e47a52f09..e5e3785ed3 100644 --- a/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs +++ b/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs @@ -1,3 +1,4 @@ +// using System; using System.Collections.Generic; using System.ComponentModel; @@ -5,7 +6,6 @@ using System.Drawing; using System.Text; using System.Windows.Forms; -// using Microsoft.Data.SqlClient; using System.Xml; diff --git a/doc/samples/SqlCommand_CommandText.cs b/doc/samples/SqlCommand_CommandText.cs index 936e3f9247..77cb7343da 100644 --- a/doc/samples/SqlCommand_CommandText.cs +++ b/doc/samples/SqlCommand_CommandText.cs @@ -1,3 +1,4 @@ +// using System; using System.Xml; using System.Data; @@ -10,8 +11,6 @@ public class Form1: Form protected DataSet DataSet1; protected DataGrid dataGrid1; - -// public void CreateCommand() { SqlCommand command = new SqlCommand(); diff --git a/doc/samples/SqlCommand_Connection.cs b/doc/samples/SqlCommand_Connection.cs index 58febc807f..54a20aa4e4 100644 --- a/doc/samples/SqlCommand_Connection.cs +++ b/doc/samples/SqlCommand_Connection.cs @@ -1,3 +1,4 @@ + // using System; using System.Data; using Microsoft.Data.SqlClient; @@ -14,7 +15,7 @@ static void Main() string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;"; CreateCommand(qs, str); } - // + private static void CreateCommand(string queryString, string connectionString) { diff --git a/doc/samples/SqlCommand_ExecuteNonQuery.cs b/doc/samples/SqlCommand_ExecuteNonQuery.cs index 16a5b474c1..53ecbdecdb 100644 --- a/doc/samples/SqlCommand_ExecuteNonQuery.cs +++ b/doc/samples/SqlCommand_ExecuteNonQuery.cs @@ -1,6 +1,6 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; namespace SqlCommandCS diff --git a/doc/samples/SqlCommand_ExecuteReader.cs b/doc/samples/SqlCommand_ExecuteReader.cs index bfce377e10..cad1726171 100644 --- a/doc/samples/SqlCommand_ExecuteReader.cs +++ b/doc/samples/SqlCommand_ExecuteReader.cs @@ -1,3 +1,4 @@ + // using System; using System.Data; using Microsoft.Data.SqlClient; @@ -13,7 +14,7 @@ static void Main() string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;"; CreateCommand(qs, str); } - // + private static void CreateCommand(string queryString, string connectionString) { @@ -31,4 +32,4 @@ private static void CreateCommand(string queryString, } } // -} +} \ No newline at end of file diff --git a/doc/samples/SqlCommand_ExecuteReader2.cs b/doc/samples/SqlCommand_ExecuteReader2.cs index 6f201a158d..bf67077951 100644 --- a/doc/samples/SqlCommand_ExecuteReader2.cs +++ b/doc/samples/SqlCommand_ExecuteReader2.cs @@ -1,3 +1,4 @@ + // using System; using System.Data; using Microsoft.Data.SqlClient; @@ -11,7 +12,7 @@ static void Main() string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;"; CreateCommand(qs, str); } - // + private static void CreateCommand(string queryString, string connectionString) { @@ -29,4 +30,4 @@ private static void CreateCommand(string queryString, } } // -} +} \ No newline at end of file diff --git a/doc/samples/SqlCommand_SqlCommand1.cs b/doc/samples/SqlCommand_SqlCommand1.cs index d84a5001bb..7488723c89 100644 --- a/doc/samples/SqlCommand_SqlCommand1.cs +++ b/doc/samples/SqlCommand_SqlCommand1.cs @@ -1,3 +1,4 @@ +// using System; using System.Xml; using System.Data; @@ -11,7 +12,6 @@ public class Form1: Form protected DataGrid dataGrid1; -// public void CreateCommand() { string queryString = "SELECT * FROM Categories ORDER BY CategoryID"; diff --git a/doc/samples/SqlConnectionStringBuilder.cs b/doc/samples/SqlConnectionStringBuilder.cs index bb19d43b16..483193d3cb 100644 --- a/doc/samples/SqlConnectionStringBuilder.cs +++ b/doc/samples/SqlConnectionStringBuilder.cs @@ -51,4 +51,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder2.cs b/doc/samples/SqlConnectionStringBuilder2.cs index f4e71b2e9e..fc2d827e1b 100644 --- a/doc/samples/SqlConnectionStringBuilder2.cs +++ b/doc/samples/SqlConnectionStringBuilder2.cs @@ -22,4 +22,4 @@ static void Main() Console.ReadLine(); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder3.cs b/doc/samples/SqlConnectionStringBuilder3.cs index ec14c38184..6026f888bd 100644 --- a/doc/samples/SqlConnectionStringBuilder3.cs +++ b/doc/samples/SqlConnectionStringBuilder3.cs @@ -31,4 +31,4 @@ static void Main() } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_ApplicationName.cs b/doc/samples/SqlConnectionStringBuilder_ApplicationName.cs index 81db8b8f45..d05941517a 100644 --- a/doc/samples/SqlConnectionStringBuilder_ApplicationName.cs +++ b/doc/samples/SqlConnectionStringBuilder_ApplicationName.cs @@ -30,4 +30,4 @@ static void Main() } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_AttachDBFilename.cs b/doc/samples/SqlConnectionStringBuilder_AttachDBFilename.cs index 0b0402b1ec..d56e69257c 100644 --- a/doc/samples/SqlConnectionStringBuilder_AttachDBFilename.cs +++ b/doc/samples/SqlConnectionStringBuilder_AttachDBFilename.cs @@ -35,4 +35,4 @@ static void Main() } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_Clear.cs b/doc/samples/SqlConnectionStringBuilder_Clear.cs index b91587ebe0..056463c1de 100644 --- a/doc/samples/SqlConnectionStringBuilder_Clear.cs +++ b/doc/samples/SqlConnectionStringBuilder_Clear.cs @@ -22,4 +22,4 @@ static void Main() Console.ReadLine(); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_ConnectTimeout.cs b/doc/samples/SqlConnectionStringBuilder_ConnectTimeout.cs index 7c700150bc..db9c06a8c8 100644 --- a/doc/samples/SqlConnectionStringBuilder_ConnectTimeout.cs +++ b/doc/samples/SqlConnectionStringBuilder_ConnectTimeout.cs @@ -30,4 +30,4 @@ static void Main() } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_ContainsKey.cs b/doc/samples/SqlConnectionStringBuilder_ContainsKey.cs index 7a9fd3b13a..73f3b2a895 100644 --- a/doc/samples/SqlConnectionStringBuilder_ContainsKey.cs +++ b/doc/samples/SqlConnectionStringBuilder_ContainsKey.cs @@ -38,4 +38,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_DataSource.cs b/doc/samples/SqlConnectionStringBuilder_DataSource.cs index 14ef063e11..a5208443dc 100644 --- a/doc/samples/SqlConnectionStringBuilder_DataSource.cs +++ b/doc/samples/SqlConnectionStringBuilder_DataSource.cs @@ -23,4 +23,4 @@ static void Main() Console.ReadLine(); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_InitialCatalog.cs b/doc/samples/SqlConnectionStringBuilder_InitialCatalog.cs index 576fe9e8c0..b2d3a1bc9b 100644 --- a/doc/samples/SqlConnectionStringBuilder_InitialCatalog.cs +++ b/doc/samples/SqlConnectionStringBuilder_InitialCatalog.cs @@ -45,4 +45,4 @@ static void Main() Console.ReadLine(); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_IntegratedSecurity.cs b/doc/samples/SqlConnectionStringBuilder_IntegratedSecurity.cs index c6e572128b..b3a01a98ca 100644 --- a/doc/samples/SqlConnectionStringBuilder_IntegratedSecurity.cs +++ b/doc/samples/SqlConnectionStringBuilder_IntegratedSecurity.cs @@ -49,4 +49,4 @@ static void Main() Console.ReadLine(); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_Keys.cs b/doc/samples/SqlConnectionStringBuilder_Keys.cs index 1c31194cb1..ea85d8a5a0 100644 --- a/doc/samples/SqlConnectionStringBuilder_Keys.cs +++ b/doc/samples/SqlConnectionStringBuilder_Keys.cs @@ -23,4 +23,4 @@ static void Main() Console.ReadLine(); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_MultipleActiveResultSets.cs b/doc/samples/SqlConnectionStringBuilder_MultipleActiveResultSets.cs index 849951f4b1..dded117686 100644 --- a/doc/samples/SqlConnectionStringBuilder_MultipleActiveResultSets.cs +++ b/doc/samples/SqlConnectionStringBuilder_MultipleActiveResultSets.cs @@ -26,4 +26,4 @@ static void Main() Console.ReadLine(); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_Password.cs b/doc/samples/SqlConnectionStringBuilder_Password.cs index 25ef3ac3a6..ea31db3b06 100644 --- a/doc/samples/SqlConnectionStringBuilder_Password.cs +++ b/doc/samples/SqlConnectionStringBuilder_Password.cs @@ -22,4 +22,4 @@ public static void Main() { } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_Remove.cs b/doc/samples/SqlConnectionStringBuilder_Remove.cs index 7de94386a1..8c640f35ea 100644 --- a/doc/samples/SqlConnectionStringBuilder_Remove.cs +++ b/doc/samples/SqlConnectionStringBuilder_Remove.cs @@ -44,4 +44,4 @@ static void Main() Console.ReadLine(); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_TryGetValue.cs b/doc/samples/SqlConnectionStringBuilder_TryGetValue.cs index 6724adeb94..4c447b1ce3 100644 --- a/doc/samples/SqlConnectionStringBuilder_TryGetValue.cs +++ b/doc/samples/SqlConnectionStringBuilder_TryGetValue.cs @@ -58,4 +58,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnectionStringBuilder_Values.cs b/doc/samples/SqlConnectionStringBuilder_Values.cs index 57cc6f4135..9eab245e18 100644 --- a/doc/samples/SqlConnectionStringBuilder_Values.cs +++ b/doc/samples/SqlConnectionStringBuilder_Values.cs @@ -26,4 +26,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_BeginTransaction.cs b/doc/samples/SqlConnection_BeginTransaction.cs index 9665c33c12..f00ead429c 100644 --- a/doc/samples/SqlConnection_BeginTransaction.cs +++ b/doc/samples/SqlConnection_BeginTransaction.cs @@ -67,4 +67,4 @@ private static void ExecuteSqlTransaction(string connectionString) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_BeginTransaction1.cs b/doc/samples/SqlConnection_BeginTransaction1.cs index c7b7b6b651..9148909d79 100644 --- a/doc/samples/SqlConnection_BeginTransaction1.cs +++ b/doc/samples/SqlConnection_BeginTransaction1.cs @@ -62,4 +62,4 @@ private static void ExecuteSqlTransaction(string connectionString) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_BeginTransaction2.cs b/doc/samples/SqlConnection_BeginTransaction2.cs index 9665c33c12..f00ead429c 100644 --- a/doc/samples/SqlConnection_BeginTransaction2.cs +++ b/doc/samples/SqlConnection_BeginTransaction2.cs @@ -67,4 +67,4 @@ private static void ExecuteSqlTransaction(string connectionString) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_BeginTransaction3.cs b/doc/samples/SqlConnection_BeginTransaction3.cs index 44eb020ff7..ed4437f7c1 100644 --- a/doc/samples/SqlConnection_BeginTransaction3.cs +++ b/doc/samples/SqlConnection_BeginTransaction3.cs @@ -66,4 +66,4 @@ private static void ExecuteSqlTransaction(string connectionString) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_ConnectionString.cs b/doc/samples/SqlConnection_ConnectionString.cs index 0b5ed5a00b..996fb845a5 100644 --- a/doc/samples/SqlConnection_ConnectionString.cs +++ b/doc/samples/SqlConnection_ConnectionString.cs @@ -35,4 +35,4 @@ static private string GetConnectionString() + "Integrated Security=true;"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_ConnectionString1.cs b/doc/samples/SqlConnection_ConnectionString1.cs index c587c162f5..ee24b7c827 100644 --- a/doc/samples/SqlConnection_ConnectionString1.cs +++ b/doc/samples/SqlConnection_ConnectionString1.cs @@ -108,4 +108,4 @@ private static string GetConnectionString() return builder.ConnectionString; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_ConnectionTimeout.cs b/doc/samples/SqlConnection_ConnectionTimeout.cs index 0ad488ebde..9d0a64994f 100644 --- a/doc/samples/SqlConnection_ConnectionTimeout.cs +++ b/doc/samples/SqlConnection_ConnectionTimeout.cs @@ -32,4 +32,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;Connection Timeout=30"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_DataSource.cs b/doc/samples/SqlConnection_DataSource.cs index 779a5af14f..c626b6e53e 100644 --- a/doc/samples/SqlConnection_DataSource.cs +++ b/doc/samples/SqlConnection_DataSource.cs @@ -32,4 +32,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_Database.cs b/doc/samples/SqlConnection_Database.cs index 4cedb11b22..bc9aec7ddc 100644 --- a/doc/samples/SqlConnection_Database.cs +++ b/doc/samples/SqlConnection_Database.cs @@ -37,4 +37,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_Open.cs b/doc/samples/SqlConnection_Open.cs index 932b17fe3f..8150eb2d39 100644 --- a/doc/samples/SqlConnection_Open.cs +++ b/doc/samples/SqlConnection_Open.cs @@ -32,4 +32,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_PacketSize.cs b/doc/samples/SqlConnection_PacketSize.cs index 7503818c30..160ad39685 100644 --- a/doc/samples/SqlConnection_PacketSize.cs +++ b/doc/samples/SqlConnection_PacketSize.cs @@ -31,4 +31,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;Packet Size=512"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_ServerVersion.cs b/doc/samples/SqlConnection_ServerVersion.cs index 2572dbf60e..aed6aeb478 100644 --- a/doc/samples/SqlConnection_ServerVersion.cs +++ b/doc/samples/SqlConnection_ServerVersion.cs @@ -25,4 +25,4 @@ private static void CreateSqlConnection(string connectionString) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_SqlConnection.cs b/doc/samples/SqlConnection_SqlConnection.cs index 59e5587e5a..decc295569 100644 --- a/doc/samples/SqlConnection_SqlConnection.cs +++ b/doc/samples/SqlConnection_SqlConnection.cs @@ -31,4 +31,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_SqlConnection1.cs b/doc/samples/SqlConnection_SqlConnection1.cs index 19a9d5c5a5..c61438899f 100644 --- a/doc/samples/SqlConnection_SqlConnection1.cs +++ b/doc/samples/SqlConnection_SqlConnection1.cs @@ -34,4 +34,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlConnection_WorkstationId.cs b/doc/samples/SqlConnection_WorkstationId.cs index 2edd6d878f..1efc18d588 100644 --- a/doc/samples/SqlConnection_WorkstationId.cs +++ b/doc/samples/SqlConnection_WorkstationId.cs @@ -32,4 +32,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataAdapter.cs b/doc/samples/SqlDataAdapter.cs index aed3c92111..961ba545cf 100644 --- a/doc/samples/SqlDataAdapter.cs +++ b/doc/samples/SqlDataAdapter.cs @@ -62,4 +62,4 @@ public static SqlDataAdapter CreateCustomerAdapter( return adapter; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataAdapter_RowUpdated.cs b/doc/samples/SqlDataAdapter_RowUpdated.cs index 9cc7bf637c..7cbdb660f2 100644 --- a/doc/samples/SqlDataAdapter_RowUpdated.cs +++ b/doc/samples/SqlDataAdapter_RowUpdated.cs @@ -74,4 +74,4 @@ private static void PrintEventArgs(SqlRowUpdatedEventArgs args) " status=" + args.Status + ")"); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataAdapter_SelectCommand.cs b/doc/samples/SqlDataAdapter_SelectCommand.cs index aecd1db331..8532a06c2f 100644 --- a/doc/samples/SqlDataAdapter_SelectCommand.cs +++ b/doc/samples/SqlDataAdapter_SelectCommand.cs @@ -25,4 +25,4 @@ private static DataSet SelectRows(DataSet dataset, } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataAdapter_SqlDataAdapter.cs b/doc/samples/SqlDataAdapter_SqlDataAdapter.cs index beb2486cbd..ff67e101f3 100644 --- a/doc/samples/SqlDataAdapter_SqlDataAdapter.cs +++ b/doc/samples/SqlDataAdapter_SqlDataAdapter.cs @@ -46,4 +46,4 @@ public static SqlDataAdapter CreateSqlDataAdapter(SqlConnection connection) return adapter; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataAdapter_SqlDataAdapter1.cs b/doc/samples/SqlDataAdapter_SqlDataAdapter1.cs index f181c5ffc2..abac49f890 100644 --- a/doc/samples/SqlDataAdapter_SqlDataAdapter1.cs +++ b/doc/samples/SqlDataAdapter_SqlDataAdapter1.cs @@ -45,4 +45,4 @@ public static SqlDataAdapter CreateSqlDataAdapter(SqlCommand selectCommand, return adapter; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataAdapter_SqlDataAdapter2.cs b/doc/samples/SqlDataAdapter_SqlDataAdapter2.cs index 275dd4c02a..dced33ff37 100644 --- a/doc/samples/SqlDataAdapter_SqlDataAdapter2.cs +++ b/doc/samples/SqlDataAdapter_SqlDataAdapter2.cs @@ -47,4 +47,4 @@ public static SqlDataAdapter CreateSqlDataAdapter(string commandText, return adapter; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataAdapter_SqlDataAdapter3.cs b/doc/samples/SqlDataAdapter_SqlDataAdapter3.cs index 721e9ef75b..33ff5161d0 100644 --- a/doc/samples/SqlDataAdapter_SqlDataAdapter3.cs +++ b/doc/samples/SqlDataAdapter_SqlDataAdapter3.cs @@ -46,4 +46,4 @@ public static SqlDataAdapter CreateSqlDataAdapter(string commandText, return adapter; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataReader_Close.cs b/doc/samples/SqlDataReader_Close.cs index 102fa6de85..c2499e5313 100644 --- a/doc/samples/SqlDataReader_Close.cs +++ b/doc/samples/SqlDataReader_Close.cs @@ -40,4 +40,4 @@ private static void ReadOrderData(string connectionString) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataReader_GetOrdinal.cs b/doc/samples/SqlDataReader_GetOrdinal.cs index ff69173616..ae12f6bff2 100644 --- a/doc/samples/SqlDataReader_GetOrdinal.cs +++ b/doc/samples/SqlDataReader_GetOrdinal.cs @@ -38,4 +38,4 @@ private static void ReadGetOrdinal(string connectionString) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataReader_IsDBNull.cs b/doc/samples/SqlDataReader_IsDBNull.cs index 903ac8f424..381b045661 100644 --- a/doc/samples/SqlDataReader_IsDBNull.cs +++ b/doc/samples/SqlDataReader_IsDBNull.cs @@ -26,4 +26,4 @@ static void Main(string[] args) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlDataReader_Read.cs b/doc/samples/SqlDataReader_Read.cs index 3a61b61cfd..abecefe3c7 100644 --- a/doc/samples/SqlDataReader_Read.cs +++ b/doc/samples/SqlDataReader_Read.cs @@ -43,4 +43,4 @@ private static void ReadSingleRow(IDataRecord record) } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlError_State.cs b/doc/samples/SqlError_State.cs index f4f10738af..7a79f8460e 100644 --- a/doc/samples/SqlError_State.cs +++ b/doc/samples/SqlError_State.cs @@ -31,4 +31,4 @@ public void DisplaySqlErrors(SqlException exception) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlError_ToString.cs b/doc/samples/SqlError_ToString.cs index b6645049a2..2b7e8442e0 100644 --- a/doc/samples/SqlError_ToString.cs +++ b/doc/samples/SqlError_ToString.cs @@ -49,4 +49,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlException_Errors1.cs b/doc/samples/SqlException_Errors1.cs index 30c54b08f2..470476bae6 100644 --- a/doc/samples/SqlException_Errors1.cs +++ b/doc/samples/SqlException_Errors1.cs @@ -48,4 +48,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlException_Errors2.cs b/doc/samples/SqlException_Errors2.cs index 3f8b3e3e4c..125e7d3331 100644 --- a/doc/samples/SqlException_Errors2.cs +++ b/doc/samples/SqlException_Errors2.cs @@ -50,4 +50,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter.cs b/doc/samples/SqlParameter.cs index 443bc9fb2e..4a8def986f 100644 --- a/doc/samples/SqlParameter.cs +++ b/doc/samples/SqlParameter.cs @@ -1,5 +1,6 @@ using System; using System.Data; +// using Microsoft.Data.SqlClient; class Program @@ -8,7 +9,7 @@ static void Main() { } - // + // using Microsoft.Data.SqlClient; static void CreateSqlParameterOutput() { @@ -87,4 +88,4 @@ static void CreateSqlParameterVersion() parameter.Value = "garden hose"; } // -} +} \ No newline at end of file diff --git a/doc/samples/SqlParameterCollection_Add.cs b/doc/samples/SqlParameterCollection_Add.cs index cb03a57e27..0a22a5eda9 100644 --- a/doc/samples/SqlParameterCollection_Add.cs +++ b/doc/samples/SqlParameterCollection_Add.cs @@ -10,4 +10,4 @@ public void AddSqlParameter(SqlCommand command) command.Parameters.Add(new SqlParameter("Description", "Beverages")); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameterCollection_Add1.cs b/doc/samples/SqlParameterCollection_Add1.cs index 6af67ef415..1042727cef 100644 --- a/doc/samples/SqlParameterCollection_Add1.cs +++ b/doc/samples/SqlParameterCollection_Add1.cs @@ -13,4 +13,4 @@ public void AddSqlParameter(SqlCommand command) command.Parameters.Add(param); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameterCollection_Add3.cs b/doc/samples/SqlParameterCollection_Add3.cs index 9feff70a03..d8e6a87877 100644 --- a/doc/samples/SqlParameterCollection_Add3.cs +++ b/doc/samples/SqlParameterCollection_Add3.cs @@ -13,4 +13,4 @@ public void AddSqlParameter(SqlCommand command) param.Value = "Beverages"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameterCollection_Add5.cs b/doc/samples/SqlParameterCollection_Add5.cs index 661a665f36..8e246e31a7 100644 --- a/doc/samples/SqlParameterCollection_Add5.cs +++ b/doc/samples/SqlParameterCollection_Add5.cs @@ -10,4 +10,4 @@ public void AddSqlParameter(SqlCommand cmd) SqlParameter p1 = cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 16, "Description"); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameterCollection_Add6.cs b/doc/samples/SqlParameterCollection_Add6.cs index 8ce73cf5dc..f2c8502551 100644 --- a/doc/samples/SqlParameterCollection_Add6.cs +++ b/doc/samples/SqlParameterCollection_Add6.cs @@ -27,4 +27,4 @@ public void AddSqlParameters() } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameterCollection_AddWithValue.cs b/doc/samples/SqlParameterCollection_AddWithValue.cs index abd2d0577c..1864e3d98c 100644 --- a/doc/samples/SqlParameterCollection_AddWithValue.cs +++ b/doc/samples/SqlParameterCollection_AddWithValue.cs @@ -52,4 +52,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameterCollection_Count.cs b/doc/samples/SqlParameterCollection_Count.cs index e9e5224236..7f20fa7b32 100644 --- a/doc/samples/SqlParameterCollection_Count.cs +++ b/doc/samples/SqlParameterCollection_Count.cs @@ -72,4 +72,4 @@ static private string GetConnectionString() "Integrated Security=SSPI"; } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameterCollection_Remove.cs b/doc/samples/SqlParameterCollection_Remove.cs index f4fbc7f06d..a5790ff631 100644 --- a/doc/samples/SqlParameterCollection_Remove.cs +++ b/doc/samples/SqlParameterCollection_Remove.cs @@ -22,4 +22,4 @@ public void SearchSqlParams() command.Parameters.Remove(param); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter_IsNullable.cs b/doc/samples/SqlParameter_IsNullable.cs index 63f0e30401..518f4454eb 100644 --- a/doc/samples/SqlParameter_IsNullable.cs +++ b/doc/samples/SqlParameter_IsNullable.cs @@ -30,4 +30,4 @@ private static void SetParameterToNull(IDataParameter parameter) } } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter_ParameterName.cs b/doc/samples/SqlParameter_ParameterName.cs index 0796eb1c03..90c537def6 100644 --- a/doc/samples/SqlParameter_ParameterName.cs +++ b/doc/samples/SqlParameter_ParameterName.cs @@ -19,4 +19,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter_Precision.cs b/doc/samples/SqlParameter_Precision.cs index b207fbd1b4..dfb413bbb6 100644 --- a/doc/samples/SqlParameter_Precision.cs +++ b/doc/samples/SqlParameter_Precision.cs @@ -18,4 +18,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter_SqlParameter.cs b/doc/samples/SqlParameter_SqlParameter.cs index ed2b909323..8039855e3b 100644 --- a/doc/samples/SqlParameter_SqlParameter.cs +++ b/doc/samples/SqlParameter_SqlParameter.cs @@ -20,4 +20,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter_SqlParameter1.cs b/doc/samples/SqlParameter_SqlParameter1.cs index 7d3567364d..9641778d52 100644 --- a/doc/samples/SqlParameter_SqlParameter1.cs +++ b/doc/samples/SqlParameter_SqlParameter1.cs @@ -19,4 +19,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter_SqlParameter2.cs b/doc/samples/SqlParameter_SqlParameter2.cs index 0519e133ba..a589f3dc8c 100644 --- a/doc/samples/SqlParameter_SqlParameter2.cs +++ b/doc/samples/SqlParameter_SqlParameter2.cs @@ -19,4 +19,4 @@ private static void AddSqlParameter(SqlCommand command, string paramValue) command.Parameters.Add(parameter); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter_SqlParameter5.cs b/doc/samples/SqlParameter_SqlParameter5.cs index 153ff32d19..964723ba1d 100644 --- a/doc/samples/SqlParameter_SqlParameter5.cs +++ b/doc/samples/SqlParameter_SqlParameter5.cs @@ -18,4 +18,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlParameter_SqlParameter6.cs b/doc/samples/SqlParameter_SqlParameter6.cs index cb6da89383..5034ad68d7 100644 --- a/doc/samples/SqlParameter_SqlParameter6.cs +++ b/doc/samples/SqlParameter_SqlParameter6.cs @@ -18,4 +18,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// +// \ No newline at end of file diff --git a/doc/samples/SqlRowUpdatingEventArgs.cs b/doc/samples/SqlRowUpdatingEventArgs.cs index 554adccc0a..b16f0c94f6 100644 --- a/doc/samples/SqlRowUpdatingEventArgs.cs +++ b/doc/samples/SqlRowUpdatingEventArgs.cs @@ -72,4 +72,4 @@ private static void PrintEventArgs(SqlRowUpdatedEventArgs args) " status=" + args.Status + ")"); } } -// +// \ No newline at end of file diff --git a/doc/samples/TransactionIsolationLevels.cs b/doc/samples/TransactionIsolationLevels.cs index 4cca4ab684..dc85d9447b 100644 --- a/doc/samples/TransactionIsolationLevels.cs +++ b/doc/samples/TransactionIsolationLevels.cs @@ -525,4 +525,4 @@ internal static void Main(string[] args) } } } -// +// \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml b/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml index ec36d3d264..c36ca88904 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml @@ -1,4 +1,3 @@ - diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml index 87064b96a8..27a134c954 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml @@ -1,4 +1,3 @@ - @@ -39,5 +38,4 @@ To be added. - - \ No newline at end of file + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml index 795f40d91f..dfe38422b3 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml @@ -1,4 +1,3 @@ - @@ -33,6 +32,21 @@ A constant for use with the **GetSchema** method that represents the **ProcedureColumns** collection. To be added. + + To be added. + To be added. + + + To be added. + To be added. + + + To be added. + To be added. + + + To be added. + To be added. + - \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml index d0c291975e..799ae14b10 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml @@ -1,4 +1,3 @@ - @@ -21,7 +20,7 @@ ]]> - + Initializes a new instance of the class. To be added. @@ -84,5 +83,4 @@ To be added. - - \ No newline at end of file + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermissionAttribute.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermissionAttribute.xml index 10d99c676a..55152f22cb 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermissionAttribute.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermissionAttribute.xml @@ -1,4 +1,3 @@ - @@ -17,4 +16,3 @@ - \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml index 13b5785b5e..5a193981c0 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml @@ -1,4 +1,3 @@ - @@ -65,5 +64,4 @@ To be added. - - \ No newline at end of file + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml index 13d07b9424..77b18ae303 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml @@ -1,9 +1,9 @@ - The CMK Store provider implementation for using Microsoft CAPI based Cryptographic Service Providers (CSP) with - Always Encrypted. + Always Encrypted. + To be added. - - \ No newline at end of file + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml index 9147c23ad8..1b81cd8bfa 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml @@ -1,4 +1,3 @@ - @@ -52,5 +51,4 @@ To be added. - - \ No newline at end of file + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml index 662f232ba6..4b788afbf2 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml @@ -1,4 +1,3 @@ - @@ -61,5 +60,4 @@ To be added. - - \ No newline at end of file + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml index 7492f86efb..a4a5c33e16 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml @@ -1,4 +1,3 @@ - @@ -359,7 +358,7 @@ - + Initializes a new instance of the class. Initializes a new instance of the class with specified command text, connection, transaction, and encryption setting. To be added. - + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this . An that can be used to poll or wait for results, or both; this value is also needed when invoking , which returns the number of affected rows. @@ -570,7 +569,7 @@ The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). - + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this , and retrieves one or more result sets from the server. An that can be used to poll or wait for results, or both; this value is also needed when invoking , which returns a instance that can be used to retrieve the returned rows. @@ -790,7 +789,7 @@ An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). - + Initiates the asynchronous execution of the Transact-SQL statement or stored procedure that is described by this and returns results as an object. An that can be used to poll or wait for results, or both; this value is also needed when invoking , which returns a single XML value. @@ -1074,9 +1073,7 @@ ]]> The property was changed while the command was enlisted in a transaction. - - - + To be added. @@ -1128,12 +1125,12 @@ to execute a [!INCLUDE[tsql](~/includes/tsql-md.md)] statement, you must call in order to complete the operation. If the process of executing the command has not yet finished, this method blocks until the operation is complete. Users can verify that the command has completed its operation by using the instance returned by the method. If a callback procedure was specified in the call to , this method must be called. + When you call to execute a [!INCLUDE[tsql](~/includes/tsql-md.md)] statement, you must call in order to complete the operation. If the process of executing the command has not yet finished, this method blocks until the operation is complete. Users can verify that the command has completed its operation by using the instance returned by the method. If a callback procedure was specified in the call to , this method must be called. ## Examples - For examples demonstrating the use of the method, see . + For examples demonstrating the use of the method, see . ]]> @@ -1141,13 +1138,17 @@ was called more than once for a single command execution, or the method was mismatched against its execution method (for example, the code called to complete execution of a call to . - The amount of time specified in elapsed and the asynchronous operation specified with is not complete. + The amount of time specified in elapsed and the asynchronous operation specified with is not complete. -or- - In some situations, can be set to incorrectly. If this occurs and is called, EndExecuteNonQuery could raise a SqlException error if the amount of time specified in elapsed and the asynchronous operation specified with is not complete. To correct this situation, you should either increase the value of CommandTimeout or reduce the work being done by the asynchronous operation. + In some situations, can be set to incorrectly. If this occurs and is called, EndExecuteNonQuery could raise a SqlException error if the amount of time specified in elapsed and the asynchronous operation specified with is not complete. To correct this situation, you should either increase the value of CommandTimeout or reduce the work being done by the asynchronous operation. + + To be added. + To be added. + The returned by the call to . Finishes asynchronous execution of a Transact-SQL statement, returning the requested . @@ -1200,13 +1201,13 @@ To be added. - To be added. - To be added. + To be added. + To be added. To be added. To be added. To be added. - + Executes a Transact-SQL statement against the connection and returns the number of rows affected. The number of rows affected. @@ -1288,7 +1289,7 @@ An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). - + Sends the to the and builds a . A object. @@ -1378,7 +1379,7 @@ The closed or dropped during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). - + An asynchronous version of , which sends the to the and builds a . Exceptions will be reported via the returned Task object. A task representing the asynchronous operation. @@ -1634,7 +1635,7 @@ An error occurred in a , or object during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). The , or object was closed during a streaming operation. For more information about streaming, see [SqlClient Streaming Support](~/docs/framework/data/adonet/sqlclient-streaming-support.md). - + Sends the to the and builds an object. An object. @@ -1896,5 +1897,4 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml index a5283680da..d6205ee34c 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml @@ -1226,11 +1226,11 @@ class Program { An object that represents the new transaction. or method. -]]> + ## Remarks + Once the transaction has completed, you must explicitly commit or roll back the transaction by using the or method. + ]]> - + One of the values. Begins a database transaction with the specified value. @@ -1241,7 +1241,7 @@ Once the transaction has completed, you must explicitly commit or roll back the Once the transaction has completed, you must explicitly commit or roll back the transaction by using the or method. ]]> - + Creates and returns a Command object that is associated with the connection. A Command object that is associated with the connection. diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/kernel32/Interop.IoControlCodeAccess.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/kernel32/Interop.IoControlCodeAccess.cs index 3c03e00792..c16cf8a0f2 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/kernel32/Interop.IoControlCodeAccess.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/kernel32/Interop.IoControlCodeAccess.cs @@ -32,10 +32,6 @@ public enum IoControlCodeAccess /// data from system memory to its device. /// FILE_WRITE_DATA = 0x02 - - /// - ///FILE_READ_DATA and FILE_WRITE_DATA can be ORed together if the caller must have both read and write access rights. - /// } } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientMetaDataCollectionNames.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientMetaDataCollectionNames.cs index a16e500634..56379c7552 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientMetaDataCollectionNames.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientMetaDataCollectionNames.cs @@ -5,20 +5,46 @@ namespace Microsoft.Data.SqlClient { + /// public static class SqlClientMetaDataCollectionNames { + /// public static readonly string Columns = "Columns"; + + /// public static readonly string Databases = "Databases"; + + /// public static readonly string ForeignKeys = "ForeignKeys"; + + /// public static readonly string IndexColumns = "IndexColumns"; + + /// public static readonly string Indexes = "Indexes"; + + /// public static readonly string Parameters = "Parameters"; + + /// public static readonly string ProcedureColumns = "ProcedureColumns"; + + /// public static readonly string Procedures = "Procedures"; + + /// public static readonly string Tables = "Tables"; + + /// public static readonly string UserDefinedTypes = "UserDefinedTypes"; + + /// public static readonly string Users = "Users"; + + /// public static readonly string ViewColumns = "ViewColumns"; + + /// public static readonly string Views = "Views"; } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.Windows.cs index 5223b112b6..a61f0589d0 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.Windows.cs @@ -9,24 +9,10 @@ namespace Microsoft.Data.SqlClient { - /// - /// Provides implementation similar to certificate store provider. - /// A CEK encrypted with certificate provider should be decryptable by this provider and vice versa. - /// - /// Envolope Format for the encrypted column encryption key - /// version + keyPathLength + ciphertextLength + keyPath + ciphertext + signature - /// version: A single byte indicating the format version. - /// keyPathLength: Length of the keyPath. - /// ciphertextLength: ciphertext length - /// keyPath: keyPath used to encrypt the column encryption key. This is only used for troubleshooting purposes and is not verified during decryption. - /// ciphertext: Encrypted column encryption key - /// signature: Signature of the entire byte array. Signature is validated before decrypting the column encryption key. - /// + /// public class SqlColumnEncryptionCngProvider : SqlColumnEncryptionKeyStoreProvider { - /// - /// Name for the CNG key store provider. - /// + /// public const string ProviderName = @"MSSQL_CNG_STORE"; /// @@ -40,14 +26,7 @@ public class SqlColumnEncryptionCngProvider : SqlColumnEncryptionKeyStoreProvide /// private readonly byte[] _version = new byte[] { 0x01 }; - /// - /// This function uses the asymmetric key specified by the key path - /// and decrypts an encrypted CEK with RSA encryption algorithm. - /// - /// Complete path of an asymmetric key in CNG - /// Asymmetric Key Encryption Algorithm - /// Encrypted Column Encryption Key - /// Plain text column encryption key + /// public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey) { // Validate the input parameters @@ -141,14 +120,7 @@ public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string e return RSADecrypt(rsaCngProvider, cipherText); } - /// - /// This function uses the asymmetric key specified by the key path - /// and encrypts CEK with RSA encryption algorithm. - /// - /// Complete path of an asymmetric key in AKV - /// Asymmetric Key Encryption Algorithm - /// Plain text column encryption key - /// Encrypted column encryption key + /// public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey) { // Validate the input parameters @@ -238,24 +210,13 @@ public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string e return encryptedColumnEncryptionKey; } - /// - /// Throws NotSupportedException. In this version of .NET Framework this provider does not support signing column master key metadata. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Encrypted column encryption key + /// public override byte[] SignColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations) { throw new NotSupportedException(); } - /// - /// Throws NotSupportedException. In this version of .NET Framework this provider does not support verifying signatures of column master key metadata. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Signature for the master key metadata - /// Boolean indicating whether the master key metadata can be verified based on the provided signature + /// public override bool VerifyColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations, byte[] signature) { throw new NotSupportedException(); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionEnclaveProvider.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionEnclaveProvider.cs index 0a667c8021..72c5fa73d8 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionEnclaveProvider.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlColumnEncryptionEnclaveProvider.cs @@ -4,32 +4,16 @@ namespace Microsoft.Data.SqlClient { - /// - /// The base class that defines the interface for enclave providers for Always Encrypted. An enclave is a protected region of memory inside SQL Server, used for computations on encrypted columns. An enclave provider encapsulates the client-side implementation details of the enclave attestation protocol as well as the logic for creating and caching enclave sessions. - /// + /// public abstract partial class SqlColumnEncryptionEnclaveProvider { - /// - /// Looks up an existing enclave session information in the enclave session cache. If the enclave provider does not implement enclave session caching, this method is expected to return null. - /// - /// The name of the SQL Server instance containing the enclave. - /// The endpoint of an attestation service, SqlClient contacts to attest the enclave. - /// The requested enclave session or null if the provider does not implement session caching. - /// A counter that the enclave provider is expected to increment each time SqlClient retrieves the session from the cache. The purpose of this field is to prevent replay attacks. + /// public abstract void GetEnclaveSession(string serverName, string attestationUrl, out SqlEnclaveSession sqlEnclaveSession, out long counter); - /// - /// Returns the information SqlClient subsequently uses to initiate the process of attesting the enclave and to establish a secure session with the enclave. - /// - /// Enclave attestation parameters. + /// public abstract SqlEnclaveAttestationParameters GetAttestationParameters(); - /// - /// Looks up and evicts an enclave session from the enclave session cache, if the provider implements session caching. - /// - /// The name of the SQL Server instance containing the enclave. - /// The endpoint of an attestation service, SqlClient contacts to attest the enclave. - /// The session to be invalidated. + /// public abstract void InvalidateEnclaveSession(string serverName, string enclaveAttestationUrl, SqlEnclaveSession enclaveSession); } } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs index bd41fbace4..9197919e8f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -22,6 +22,7 @@ namespace Microsoft.Data.SqlClient { + /// public sealed partial class SqlCommand : DbCommand, ICloneable { private string _commandText; @@ -303,22 +304,26 @@ private CachedAsyncState cachedAsyncState /// internal bool CachingQueryMetadataPostponed { get; set; } + /// public SqlCommand() : base() { GC.SuppressFinalize(this); } + /// public SqlCommand(string cmdText) : this() { CommandText = cmdText; } + /// public SqlCommand(string cmdText, SqlConnection connection) : this() { CommandText = cmdText; Connection = connection; } + /// public SqlCommand(string cmdText, SqlConnection connection, SqlTransaction transaction) : this() { CommandText = cmdText; @@ -326,6 +331,7 @@ public SqlCommand(string cmdText, SqlConnection connection, SqlTransaction trans Transaction = transaction; } + /// public SqlCommand(string cmdText, SqlConnection connection, SqlTransaction transaction, SqlCommandColumnEncryptionSetting columnEncryptionSetting) : this() { CommandText = cmdText; @@ -352,6 +358,7 @@ private SqlCommand(SqlCommand from) : this() } } + /// new public SqlConnection Connection { get @@ -404,6 +411,7 @@ private SqlCommand(SqlCommand from) : this() } } + /// override protected DbConnection DbConnection { get @@ -424,6 +432,7 @@ private SqlInternalConnectionTds InternalTdsConnection } } + /// public SqlNotificationRequest Notification { get @@ -453,6 +462,7 @@ internal SqlStatistics Statistics } } + /// new public SqlTransaction Transaction { get @@ -479,6 +489,7 @@ internal SqlStatistics Statistics } } + /// override protected DbTransaction DbTransaction { get @@ -491,6 +502,7 @@ override protected DbTransaction DbTransaction } } + /// override public string CommandText { get @@ -508,8 +520,10 @@ override public string CommandText } } + /// public SqlCommandColumnEncryptionSetting ColumnEncryptionSetting => _columnEncryptionSetting; + /// override public int CommandTimeout { get @@ -530,6 +544,7 @@ override public int CommandTimeout } } + /// public void ResetCommandTimeout() { if (ADP.DefaultCommandTimeout != _commandTimeout) @@ -539,6 +554,7 @@ public void ResetCommandTimeout() } } + /// override public CommandType CommandType { get @@ -570,6 +586,7 @@ override public CommandType CommandType // to limit the number of components that clutter the design surface, // when the DataAdapter design wizard generates the insert/update/delete commands it will // set the DesignTimeVisible property to false so that cmds won't appear as individual objects + /// public override bool DesignTimeVisible { get @@ -582,6 +599,7 @@ public override bool DesignTimeVisible } } + /// new public SqlParameterCollection Parameters { get @@ -596,6 +614,7 @@ public override bool DesignTimeVisible } } + /// override protected DbParameterCollection DbParameterCollection { get @@ -604,6 +623,7 @@ override protected DbParameterCollection DbParameterCollection } } + /// override public UpdateRowSource UpdatedRowSource { get @@ -626,6 +646,7 @@ override public UpdateRowSource UpdatedRowSource } } + /// public event StatementCompletedEventHandler StatementCompleted { add @@ -665,6 +686,7 @@ private void PropertyChanging() this.IsDirty = true; } + /// override public void Prepare() { // Reset _pendingCancel upon entry into any Execute - used to synchronize state @@ -782,7 +804,7 @@ internal void Unprepare() _cachedMetaData = null; } - + /// // Cancel is supposed to be multi-thread safe. // It doesn't make sense to verify the connection exists or that it is open during cancel // because immediately after checkin the connection can be closed or removed via another thread. @@ -868,16 +890,19 @@ override public void Cancel() } } + /// new public SqlParameter CreateParameter() { return new SqlParameter(); } + /// override protected DbParameter CreateDbParameter() { return CreateParameter(); } + /// override protected void Dispose(bool disposing) { if (disposing) @@ -888,6 +913,7 @@ override protected void Dispose(bool disposing) base.Dispose(disposing); } + /// override public object ExecuteScalar() { // Reset _pendingCancel upon entry into any Execute - used to synchronize state @@ -956,6 +982,7 @@ private object CompleteExecuteScalar(SqlDataReader ds, bool returnSqlValue) return retResult; } + /// override public int ExecuteNonQuery() { // Reset _pendingCancel upon entry into any Execute - used to synchronize state @@ -993,12 +1020,14 @@ override public int ExecuteNonQuery() } } + /// public IAsyncResult BeginExecuteNonQuery() { // BeginExecuteNonQuery will track ExecutionTime for us return BeginExecuteNonQuery(null, null); } + /// public IAsyncResult BeginExecuteNonQuery(AsyncCallback callback, object stateObject) { return BeginExecuteNonQueryInternal(0, callback, stateObject, 0, inRetry: false); @@ -1187,6 +1216,7 @@ private void WaitForAsyncResults(IAsyncResult asyncResult, bool isInternal) } } + /// public int EndExecuteNonQuery(IAsyncResult asyncResult) => EndExecuteNonQueryInternal(asyncResult); private void ThrowIfReconnectionHasBeenCanceled() @@ -1201,6 +1231,7 @@ private void ThrowIfReconnectionHasBeenCanceled() } } + /// public int EndExecuteNonQueryAsync(IAsyncResult asyncResult) { Debug.Assert(!_internalEndExecuteInitiated || _stateObj == null); @@ -1418,6 +1449,7 @@ private Task InternalExecuteNonQuery(TaskCompletionSource completion, bo return task; } + /// public XmlReader ExecuteXmlReader() { // Reset _pendingCancel upon entry into any Execute - used to synchronize state @@ -1458,12 +1490,14 @@ public XmlReader ExecuteXmlReader() } } + /// public IAsyncResult BeginExecuteXmlReader() { // BeginExecuteXmlReader will track executiontime return BeginExecuteXmlReader(null, null); } + /// public IAsyncResult BeginExecuteXmlReader(AsyncCallback callback, object stateObject) { return BeginExecuteXmlReaderInternal(CommandBehavior.SequentialAccess, callback, stateObject, 0, inRetry: false); @@ -1578,7 +1612,7 @@ private void BeginExecuteXmlReaderInternalReadStage(TaskCompletionSource } } - + /// public XmlReader EndExecuteXmlReader(IAsyncResult asyncResult) { return EndExecuteXmlReaderInternal(asyncResult); @@ -1665,20 +1699,28 @@ private XmlReader CompleteXmlReader(SqlDataReader ds, bool isAsync = false) } return xr; } - + + /// public IAsyncResult BeginExecuteReader() => BeginExecuteReader(null, null, CommandBehavior.Default); + /// public IAsyncResult BeginExecuteReader(AsyncCallback callback, object stateObject) => BeginExecuteReader(callback, stateObject, CommandBehavior.Default); + + + /// public IAsyncResult BeginExecuteReader(CommandBehavior behavior) => BeginExecuteReader(null, null, behavior); + /// public IAsyncResult BeginExecuteReader(AsyncCallback callback, object stateObject, CommandBehavior behavior) => BeginExecuteReaderInternal(behavior, callback, stateObject, 0, inRetry: false); + /// override protected DbDataReader ExecuteDbDataReader(CommandBehavior behavior) { return ExecuteReader(behavior); } + /// new public SqlDataReader ExecuteReader() { SqlStatistics statistics = null; @@ -1693,6 +1735,7 @@ override protected DbDataReader ExecuteDbDataReader(CommandBehavior behavior) } } + /// new public SqlDataReader ExecuteReader(CommandBehavior behavior) { // Reset _pendingCancel upon entry into any Execute - used to synchronize state @@ -1729,6 +1772,7 @@ override protected DbDataReader ExecuteDbDataReader(CommandBehavior behavior) } } + /// public SqlDataReader EndExecuteReader(IAsyncResult asyncResult) { return EndExecuteReaderInternal(asyncResult); @@ -2071,6 +2115,7 @@ private SqlDataReader InternalEndExecuteReader(IAsyncResult asyncResult, bool is return reader; } + /// public override Task ExecuteNonQueryAsync(CancellationToken cancellationToken) { Guid operationId = _diagnosticListener.WriteCommandBefore(this); @@ -2125,6 +2170,7 @@ public override Task ExecuteNonQueryAsync(CancellationToken cancellationTok return returnedTask; } + /// protected override Task ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { return ExecuteReaderAsync(behavior, cancellationToken).ContinueWith((result) => @@ -2137,21 +2183,25 @@ protected override Task ExecuteDbDataReaderAsync(CommandBehavior b }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled, TaskScheduler.Default); } + /// new public Task ExecuteReaderAsync() { return ExecuteReaderAsync(CommandBehavior.Default, CancellationToken.None); } + /// new public Task ExecuteReaderAsync(CommandBehavior behavior) { return ExecuteReaderAsync(behavior, CancellationToken.None); } + /// new public Task ExecuteReaderAsync(CancellationToken cancellationToken) { return ExecuteReaderAsync(CommandBehavior.Default, cancellationToken); } + /// new public Task ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { Guid operationId = default(Guid); @@ -2212,6 +2262,7 @@ protected override Task ExecuteDbDataReaderAsync(CommandBehavior b return returnedTask; } + /// public override Task ExecuteScalarAsync(CancellationToken cancellationToken) { _parentOperationStarted = true; @@ -2294,11 +2345,13 @@ public override Task ExecuteScalarAsync(CancellationToken cancellationTo }, TaskScheduler.Default).Unwrap(); } + /// public Task ExecuteXmlReaderAsync() { return ExecuteXmlReaderAsync(CancellationToken.None); } + /// public Task ExecuteXmlReaderAsync(CancellationToken cancellationToken) { Guid operationId = _diagnosticListener.WriteCommandBefore(this); @@ -3407,13 +3460,7 @@ private SqlParameter GetSqlParameterWithQueryText(string queryText) return sqlParam; } - /// - /// Constructs the sp_describe_parameter_encryption request with the values from the original RPC call. - /// Prototype for sp_describe_parameter_encryption is - /// exec sp_describe_parameter_encryption @tsql=N'[SQL Statement]', @params=N'@p1 varbinary(256)' - /// - /// Original RPC request - /// sp_describe_parameter_encryption request being built + private void PrepareDescribeParameterEncryptionRequest(_SqlRPC originalRpcRequest, ref _SqlRPC describeParameterEncryptionRequest, byte[] attestationParameters = null) { Debug.Assert(originalRpcRequest != null); @@ -3972,20 +4019,7 @@ internal SqlDataReader RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior } } - /// - /// RunExecuteReaderTds after Transparent Parameter Encryption is complete. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// + private SqlDataReader RunExecuteReaderTdsWithTransparentParameterEncryption( CommandBehavior cmdBehavior, RunBehavior runBehavior, @@ -5931,6 +5965,8 @@ private void NotifyDependency() object ICloneable.Clone() => Clone(); + + /// public SqlCommand Clone() => new SqlCommand(this); } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs index dfe8a95ecf..17da75c381 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs @@ -10,7 +10,7 @@ namespace Microsoft.Data.SqlClient { /// - /// Implements a global directory of all the encryption algorithms registered with client. + /// Implements a global directory of all the encryption algorithms registered with client. /// sealed internal class SqlClientEncryptionAlgorithmFactoryList { @@ -32,9 +32,9 @@ internal static SqlClientEncryptionAlgorithmFactoryList GetInstance() } /// - /// Get the registered list of algorithms as a comma seperated list with algorithm names - /// wrapped in single quotes. - /// + /// + /// + /// internal string GetRegisteredCipherAlgorithmNames() { StringBuilder builder = new StringBuilder(); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientLogger.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientLogger.cs index 8362d16059..c722a7ec61 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientLogger.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientLogger.cs @@ -4,40 +4,30 @@ namespace Microsoft.Data.SqlClient { - /// - /// Sql client logger. - /// + /// public class SqlClientLogger { internal enum LogLevel { Info = 0, Error, } - /// - /// Log info. - /// + /// public void LogInfo(string type, string method, string message) { Bid.Trace($"{message}\n"); } - /// - /// Log error. - /// + /// public void LogError(string type, string method, string message) { Bid.Trace($"{message}\n"); } - /// - /// Log message if value is not true. - /// + /// public bool LogAssert(bool value, string type, string method, string message) { if (!value) LogError(type, method, message); return value; } - /// - /// Whether bid tracing is enabled. - /// + /// public bool IsLoggingEnabled => Bid.TraceOn; } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientMetaDataCollectionNames.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientMetaDataCollectionNames.cs index c9e8c9a94c..be88d06424 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientMetaDataCollectionNames.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientMetaDataCollectionNames.cs @@ -4,22 +4,46 @@ namespace Microsoft.Data.SqlClient { - + /// public static class SqlClientMetaDataCollectionNames { - + /// public static readonly string Columns = "Columns"; + + /// public static readonly string Databases = "Databases"; + + /// public static readonly string ForeignKeys = "ForeignKeys"; + + /// public static readonly string IndexColumns = "IndexColumns"; + + /// public static readonly string Indexes = "Indexes"; + + /// public static readonly string Parameters = "Parameters"; + + /// public static readonly string ProcedureColumns = "ProcedureColumns"; + + /// public static readonly string Procedures = "Procedures"; + + /// public static readonly string Tables = "Tables"; + + /// public static readonly string UserDefinedTypes = "UserDefinedTypes"; + + /// public static readonly string Users = "Users"; + + /// public static readonly string ViewColumns = "ViewColumns"; + + /// public static readonly string Views = "Views"; } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientPermission.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientPermission.cs index be9f8c468c..3b2783b95e 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientPermission.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientPermission.cs @@ -15,20 +15,23 @@ namespace Microsoft.Data.SqlClient { - + /// [Serializable] public sealed class SqlClientPermission : System.Data.Common.DBDataPermission { + /// [Obsolete("SqlClientPermission() has been deprecated. Use the SqlClientPermission(PermissionState.None) constructor. http://go.microsoft.com/fwlink/?linkid=14202", true)] // MDAC 86034 public SqlClientPermission() : this(PermissionState.None) { } + /// public SqlClientPermission(PermissionState state) : base(state) { } + /// [Obsolete("SqlClientPermission(PermissionState state, Boolean allowBlankPassword) has been deprecated. Use the SqlClientPermission(PermissionState.None) constructor. http://go.microsoft.com/fwlink/?linkid=14202", true)] // MDAC 86034 public SqlClientPermission(PermissionState state, bool allowBlankPassword) : this(state) { @@ -58,12 +61,14 @@ internal SqlClientPermission(SqlConnectionString constr) : base(PermissionState. } } + /// public override void Add(string connectionString, string restrictions, KeyRestrictionBehavior behavior) { DBConnectionString constr = new DBConnectionString(connectionString, restrictions, behavior, SqlConnectionString.GetParseSynonyms(), false); AddPermissionEntry(constr); } + /// override public IPermission Copy() { return new SqlClientPermission(this); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCertificateStoreProvider.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCertificateStoreProvider.cs index 780a96d746..1879ccfa8a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCertificateStoreProvider.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCertificateStoreProvider.cs @@ -10,9 +10,7 @@ namespace Microsoft.Data.SqlClient { - /// - /// Certificate Key Store Provider class - /// + /// public class SqlColumnEncryptionCertificateStoreProvider : SqlColumnEncryptionKeyStoreProvider { // Constants @@ -20,9 +18,7 @@ public class SqlColumnEncryptionCertificateStoreProvider : SqlColumnEncryptionKe // Assumption: Certificate Locations (LocalMachine & CurrentUser), Certificate Store name "My" // Certificate provider name (CertificateStore) dont need to be localized. - /// - /// Name for the certificate key store provider. - /// + /// public const string ProviderName = @"MSSQL_CERTIFICATE_STORE"; /// @@ -60,14 +56,7 @@ public class SqlColumnEncryptionCertificateStoreProvider : SqlColumnEncryptionKe /// private readonly byte[] _version = new byte[] { 0x01 }; - /// - /// This function uses a certificate specified by the key path - /// and decrypts an encrypted CEK with RSA encryption algorithm. - /// - /// Complete path of a certificate - /// Asymmetric Key Encryption Algorithm - /// Encrypted Column Encryption Key - /// Plain text column encryption key + /// public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey) { // Validate the input parameters @@ -161,14 +150,7 @@ public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string e return RSADecrypt(cipherText, certificate); } - /// - /// This function uses a certificate specified by the key path - /// and encrypts CEK with RSA encryption algorithm. - /// - /// Complete path of a certificate - /// Asymmetric Key Encryption Algorithm - /// Plain text column encryption key - /// Encrypted column encryption key + /// public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey) { // Validate the input parameters @@ -258,13 +240,7 @@ public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string e return encryptedColumnEncryptionKey; } - /// - /// This function must be implemented by the corresponding Key Store providers. This function should use an asymmetric key identified by a key path - /// and sign the masterkey metadata consisting of (masterKeyPath, allowEnclaveComputations bit, providerName). - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Signature for master key metadata + /// public override byte[] SignColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations) { var hash = ComputeMasterKeyMetadataHash(masterKeyPath, allowEnclaveComputations, isSystemOp: false); @@ -277,14 +253,7 @@ public override byte[] SignColumnMasterKeyMetadata(string masterKeyPath, bool al return signature; } - /// - /// This function must be implemented by the corresponding Key Store providers. This function should use an asymmetric key identified by a key path - /// and verify the masterkey metadata consisting of (masterKeyPath, allowEnclaveComputations bit, providerName). - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Signature for the master key metadata - /// Boolean indicating whether the master key metadata can be verified based on the provided signature + /// public override bool VerifyColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations, byte[] signature) { var hash = ComputeMasterKeyMetadataHash(masterKeyPath, allowEnclaveComputations, isSystemOp: true); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.cs index 107d02c9d8..350023e4f0 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCngProvider.cs @@ -9,24 +9,10 @@ namespace Microsoft.Data.SqlClient { - /// - /// Provides implementation similar to certificate store provider. - /// A CEK encrypted with certificate provider should be decryptable by this provider and vice versa. - /// - /// Envolope Format for the encrypted column encryption key - /// version + keyPathLength + ciphertextLength + keyPath + ciphertext + signature - /// version: A single byte indicating the format version. - /// keyPathLength: Length of the keyPath. - /// ciphertextLength: ciphertext length - /// keyPath: keyPath used to encrypt the column encryption key. This is only used for troubleshooting purposes and is not verified during decryption. - /// ciphertext: Encrypted column encryption key - /// signature: Signature of the entire byte array. Signature is validated before decrypting the column encryption key. - /// + /// public class SqlColumnEncryptionCngProvider : SqlColumnEncryptionKeyStoreProvider { - /// - /// Name for the CNG key store provider. - /// + /// public const string ProviderName = @"MSSQL_CNG_STORE"; /// @@ -40,14 +26,7 @@ public class SqlColumnEncryptionCngProvider : SqlColumnEncryptionKeyStoreProvide /// private readonly byte[] _version = new byte[] { 0x01 }; - /// - /// This function uses the asymmetric key specified by the key path - /// and decrypts an encrypted CEK with RSA encryption algorithm. - /// - /// Complete path of an asymmetric key in CNG - /// Asymmetric Key Encryption Algorithm - /// Encrypted Column Encryption Key - /// Plain text column encryption key + /// public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey) { // Validate the input parameters @@ -141,14 +120,7 @@ public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string e return RSADecrypt(rsaCngProvider, cipherText); } - /// - /// This function uses the asymmetric key specified by the key path - /// and encrypts CEK with RSA encryption algorithm. - /// - /// Complete path of an asymmetric key in AKV - /// Asymmetric Key Encryption Algorithm - /// Plain text column encryption key - /// Encrypted column encryption key + /// public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey) { // Validate the input parameters @@ -238,24 +210,13 @@ public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string e return encryptedColumnEncryptionKey; } - /// - /// Throws NotSupportedException. In this version of .NET Framework this provider does not support signing column master key metadata. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Encrypted column encryption key + /// public override byte[] SignColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations) { throw new NotSupportedException(); } - /// - /// Throws NotSupportedException. In this version of .NET Framework this provider does not support verifying signatures of column master key metadata. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Signature for the master key metadata - /// Boolean indicating whether the master key metadata can be verified based on the provided signature + /// public override bool VerifyColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations, byte[] signature) { throw new NotSupportedException(); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCspProvider.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCspProvider.cs index f581a4287e..a89680a142 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCspProvider.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionCspProvider.cs @@ -10,24 +10,10 @@ namespace Microsoft.Data.SqlClient { - /// - /// Provides implementation similar to certificate store provider. - /// A CEK encrypted with certificate store provider should be decryptable by this provider and vice versa. - /// - /// Envolope Format for the encrypted column encryption key - /// version + keyPathLength + ciphertextLength + keyPath + ciphertext + signature - /// version: A single byte indicating the format version. - /// keyPathLength: Length of the keyPath. - /// ciphertextLength: ciphertext length - /// keyPath: keyPath used to encrypt the column encryption key. This is only used for troubleshooting purposes and is not verified during decryption. - /// ciphertext: Encrypted column encryption key - /// signature: Signature of the entire byte array. Signature is validated before decrypting the column encryption key. - /// + /// public class SqlColumnEncryptionCspProvider : SqlColumnEncryptionKeyStoreProvider { - /// - /// Name for the CSP key store provider. - /// + /// public const string ProviderName = @"MSSQL_CSP_PROVIDER"; /// @@ -36,9 +22,7 @@ public class SqlColumnEncryptionCspProvider : SqlColumnEncryptionKeyStoreProvide /// private const string RSAEncryptionAlgorithmWithOAEP = @"RSA_OAEP"; - /// - /// Hashing algoirthm used for signing - /// + private const string HashingAlgorithm = @"SHA256"; /// @@ -46,14 +30,7 @@ public class SqlColumnEncryptionCspProvider : SqlColumnEncryptionKeyStoreProvide /// private readonly byte[] _version = new byte[] { 0x01 }; - /// - /// This function uses the asymmetric key specified by the key path - /// and decrypts an encrypted CEK with RSA encryption algorithm. - /// - /// Complete path of an asymmetric key in CSP - /// Asymmetric Key Encryption Algorithm - /// Encrypted Column Encryption Key - /// Plain text column encryption key + /// public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey) { // Validate the input parameters @@ -147,14 +124,7 @@ public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string e return RSADecrypt(rsaProvider, cipherText); } - /// - /// This function uses the asymmetric key specified by the key path - /// and encrypts CEK with RSA encryption algorithm. - /// - /// Complete path of an asymmetric key in AKV - /// Asymmetric Key Encryption Algorithm - /// Plain text column encryption key - /// Encrypted column encryption key + /// public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey) { // Validate the input parameters @@ -244,24 +214,13 @@ public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string e return encryptedColumnEncryptionKey; } - /// - /// Throws NotSupportedException. In this version of .NET Framework this provider does not support signing column master key metadata. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Encrypted column encryption key + /// public override byte[] SignColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations) { throw new NotSupportedException(); } - /// - /// Throws NotSupportedException. In this version of .NET Framework this provider does not support verifying signatures of column master key metadata. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Signature for the master key metadata - /// Boolean indicating whether the master key metadata can be verified based on the provided signature + /// public override bool VerifyColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations, byte[] signature) { throw new NotSupportedException(); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionEnclaveProvider.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionEnclaveProvider.cs index 6476865c36..eaab03d7d1 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionEnclaveProvider.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionEnclaveProvider.cs @@ -6,42 +6,21 @@ namespace Microsoft.Data.SqlClient { - /// - /// The base class that defines the interface for enclave providers for Always Encrypted. An enclave is a protected region of memory inside SQL Server, used for computations on encrypted columns. An enclave provider encapsulates the client-side implementation details of the enclave attestation protocol as well as the logic for creating and caching enclave sessions. - /// + + /// public abstract class SqlColumnEncryptionEnclaveProvider { - /// - /// Looks up an existing enclave session information in the enclave session cache. If the enclave provider does not implement enclave session caching, this method is expected to return null. - /// - /// The name of the SQL Server instance containing the enclave. - /// The endpoint of an attestation service, SqlClient contacts to attest the enclave. - /// The requested enclave session or null if the provider does not implement session caching. - /// A counter that the enclave provider is expected to increment each time SqlClient retrieves the session from the cache. The purpose of this field is to prevent replay attacks. + /// public abstract void GetEnclaveSession(string serverName, string attestationUrl, out SqlEnclaveSession sqlEnclaveSession, out long counter); - /// - /// Returns the information SqlClient subsequently uses to initiate the process of attesting the enclave and to establish a secure session with the enclave. - /// - /// Enclave attestation parameters. + /// public abstract SqlEnclaveAttestationParameters GetAttestationParameters(); - /// Performs enclave attestation, generates a symmetric key for the session, creates a an enclave session and stores the session information in the cache. - /// The information the provider uses to attest the enclave and generate a symmetric key for the session. The format of this information is specific to the enclave attestation protocol. - /// A Diffie-Hellman algorithm object encapsulating a client-side key pair. - /// The endpoint of an attestation service for attesting the enclave. - /// The name of the SQL Server instance containing the enclave. - /// The requested enclave session or null if the provider does not implement session caching. - /// A counter that the enclave provider is expected to increment each time SqlClient retrieves the session from the cache. The purpose of this field is to prevent replay attacks. + /// public abstract void CreateEnclaveSession(byte[] enclaveAttestationInfo, ECDiffieHellmanCng clientDiffieHellmanKey, string attestationUrl, string servername, out SqlEnclaveSession sqlEnclaveSession, out long counter); - /// - /// Looks up and evicts an enclave session from the enclave session cache, if the provider implements session caching. - /// - /// The name of the SQL Server instance containing the enclave. - /// The endpoint of an attestation service, SqlClient contacts to attest the enclave. - /// The session to be invalidated. + /// public abstract void InvalidateEnclaveSession(string serverName, string enclaveAttestationUrl, SqlEnclaveSession enclaveSession); } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionKeyStoreProvider.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionKeyStoreProvider.cs index 9c3a14544d..b808678722 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionKeyStoreProvider.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlColumnEncryptionKeyStoreProvider.cs @@ -7,59 +7,22 @@ namespace Microsoft.Data.SqlClient { - /// - /// Abstract base class for all column encryption Key Store providers. It exposes two functions - /// 1. DecryptColumnEncryptionKey - This is the function used by SqlClient under the covers to decrypt encrypted column encryption key blob. - /// 2. EncryptColumnEncryptionKey - This will be used by client tools that generate DDL for customers - /// 3. SignColumnMasterKeyMetadata - This will be used by client tools that generate Column Master Keys (CMK) for customers - /// 4. VerifyColumnMasterKeyMetadata - This will be used by SqlClient under the covers to verify the CMKs received from SQL Server - /// + /// public abstract class SqlColumnEncryptionKeyStoreProvider { - /// - /// This function must be implemented by the corresponding Key Store providers. This function should use an asymmetric key identified by the key path - /// and decrypt an encrypted column encryption key with a given encryption algorithm. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Asymmetric Key Encryption Algorithm - /// Encrypted Column Encryption Key - /// Plain text column encryption key + /// public abstract byte[] DecryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] encryptedColumnEncryptionKey); - /// - /// This function must be implemented by the corresponding Key Store providers. This function should use an asymmetric key identified by a key path - /// and encrypt a plain text column encryption key with a given asymmetric key encryption algorithm. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Asymmetric Key Encryption Algorithm - /// Plain text column encryption key to be encrypted - /// Encrypted column encryption key + /// public abstract byte[] EncryptColumnEncryptionKey(string masterKeyPath, string encryptionAlgorithm, byte[] columnEncryptionKey); - /// - /// This function must be implemented by the corresponding Key Store providers that wish to use enclaves with Always Encrypted. - /// This function has a default implementation in the base class that throws NotImplementedException to ensure that - /// it does not break applications that rely on an old API - /// Digitally sign the specified column master key metadata: the key path and the property indicating whether column master key supports enclave computations. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Encrypted column encryption key + /// public virtual byte[] SignColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations) { throw new NotImplementedException(); } - /// - /// This function must be implemented by the corresponding Key Store providers that wish to use enclaves with Always Encrypted. - /// This function has a default implementation in the base class that throws NotImplementedException to ensure that - /// it does not break applications that rely on an old API - /// Verifies whether the specified signature is valid for the column master key with the specified metadata properties: the key path and the property indicating whether column master key supports enclave computations. - /// - /// Complete path of an asymmetric key. Path format is specific to a key store provider. - /// Boolean indicating whether this key can be sent to trusted enclave - /// Signature for the master key metadata - /// Boolean indicating whether the master key metadata can be verified based on the provided signature + /// public virtual bool VerifyColumnMasterKeyMetadata(string masterKeyPath, bool allowEnclaveComputations, byte[] signature) { throw new NotImplementedException(); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs index 7dfa08564f..bb0b087780 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -26,7 +26,8 @@ namespace Microsoft.Data.SqlClient { - + + /// [ DefaultEvent("RecordsAffected"), ToolboxItem(true), @@ -432,23 +433,27 @@ private SmiEventSink_DeferedProcessing OutParamEventSink } } - + + /// public SqlCommand() : base() { GC.SuppressFinalize(this); } + /// public SqlCommand(string cmdText) : this() { CommandText = cmdText; } + /// public SqlCommand(string cmdText, SqlConnection connection) : this() { CommandText = cmdText; Connection = connection; } + /// public SqlCommand(string cmdText, SqlConnection connection, SqlTransaction transaction) : this() { CommandText = cmdText; @@ -456,6 +461,7 @@ public SqlCommand(string cmdText, SqlConnection connection, SqlTransaction trans Transaction = transaction; } + /// public SqlCommand(string cmdText, SqlConnection connection, SqlTransaction transaction, SqlCommandColumnEncryptionSetting columnEncryptionSetting) : this() { CommandText = cmdText; @@ -482,6 +488,7 @@ private SqlCommand(SqlCommand from) : this() } } + /// [ DefaultValue(null), Editor("Microsoft.VSDesigner.Data.Design.DbConnectionEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing), @@ -526,14 +533,16 @@ private SqlCommand(SqlCommand from) : this() #if DEBUG TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #endif //DEBUG - // cleanup - Unprepare(); + // cleanup + Unprepare(); #if DEBUG } - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -611,6 +620,8 @@ private bool IsShiloh } } + + /// [ DefaultValue(true), ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Notification), @@ -628,6 +639,7 @@ public bool NotificationAutoEnlist } } + /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), // MDAC 90471 @@ -664,6 +676,7 @@ internal SqlStatistics Statistics } } + /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), @@ -709,6 +722,7 @@ override protected DbTransaction DbTransaction } } + /// [ DefaultValue(""), Editor("Microsoft.VSDesigner.Data.SQL.Design.SqlCommandTextEditor, " + AssemblyRef.MicrosoftVSDesigner, "System.Drawing.Design.UITypeEditor, " + AssemblyRef.SystemDrawing), @@ -739,6 +753,7 @@ override public string CommandText } } + /// [ Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), @@ -753,6 +768,7 @@ public SqlCommandColumnEncryptionSetting ColumnEncryptionSetting } } + /// [ ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Data), ResDescriptionAttribute(StringsHelper.ResourceNames.DbCommand_CommandTimeout), @@ -778,6 +794,7 @@ override public int CommandTimeout } } + /// public void ResetCommandTimeout() { // V1.2.3300 if (ADP.DefaultCommandTimeout != _commandTimeout) @@ -792,6 +809,7 @@ private bool ShouldSerializeCommandTimeout() return (ADP.DefaultCommandTimeout != _commandTimeout); } + /// [ DefaultValue(System.Data.CommandType.Text), RefreshProperties(RefreshProperties.All), @@ -826,6 +844,7 @@ override public CommandType CommandType } } + /// // @devnote: By default, the cmd object is visible on the design surface (i.e. VS7 Server Tray) // to limit the number of components that clutter the design surface, // when the DataAdapter design wizard generates the insert/update/delete commands it will @@ -849,6 +868,7 @@ public override bool DesignTimeVisible } } + /// [ DesignerSerializationVisibility(DesignerSerializationVisibility.Content), ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Data), @@ -868,6 +888,7 @@ public override bool DesignTimeVisible } } + /// override protected DbParameterCollection DbParameterCollection { // V1.2.3300 get @@ -893,6 +914,7 @@ internal void CancelIgnoreFailure() } } + /// [ DefaultValue(System.Data.UpdateRowSource.Both), ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update), @@ -920,6 +942,7 @@ override public UpdateRowSource UpdatedRowSource } } + /// [ ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_StatementCompleted), ResDescriptionAttribute(StringsHelper.ResourceNames.DbCommand_StatementCompleted), @@ -967,6 +990,7 @@ private void PropertyChanging() this.IsDirty = true; } + /// override public void Prepare() { SqlConnection.ExecutePermission.Demand(); @@ -1033,7 +1057,8 @@ override public void Prepare() #if DEBUG TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -1041,7 +1066,8 @@ override public void Prepare() InternalPrepare(); } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -1150,11 +1176,11 @@ internal void Unprepare() Bid.Trace(" %d#, Command unprepared.\n", ObjectID); } - // Cancel is supposed to be multi-thread safe. // It doesn't make sense to verify the connection exists or that it is open during cancel // because immediately after checkin the connection can be closed or removed via another thread. // + /// override public void Cancel() { IntPtr hscp; @@ -1219,7 +1245,8 @@ override public void Cancel() TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -1251,7 +1278,8 @@ override public void Cancel() } } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -1280,17 +1308,20 @@ override public void Cancel() Bid.ScopeLeave(ref hscp); } } - + + /// new public SqlParameter CreateParameter() { return new SqlParameter(); } + /// override protected DbParameter CreateDbParameter() { return CreateParameter(); } + /// override protected void Dispose(bool disposing) { if (disposing) @@ -1307,6 +1338,7 @@ override protected void Dispose(bool disposing) base.Dispose(disposing); } + /// override public object ExecuteScalar() { SqlConnection.ExecutePermission.Demand(); @@ -1375,6 +1407,7 @@ private object CompleteExecuteScalar(SqlDataReader ds, bool returnSqlValue) return retResult; } + /// override public int ExecuteNonQuery() { SqlConnection.ExecutePermission.Demand(); @@ -1437,6 +1470,7 @@ internal void ExecuteToPipe(SmiContext pipeContext) } } + /// [System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)] public IAsyncResult BeginExecuteNonQuery() { @@ -1444,6 +1478,7 @@ public IAsyncResult BeginExecuteNonQuery() return BeginExecuteNonQuery(null, null); } + /// [System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)] public IAsyncResult BeginExecuteNonQuery(AsyncCallback callback, object stateObject) { @@ -1452,6 +1487,7 @@ public IAsyncResult BeginExecuteNonQuery(AsyncCallback callback, object stateObj return BeginExecuteNonQueryInternal(0, callback, stateObject, 0, inRetry: false); } + /// private IAsyncResult BeginExecuteNonQueryAsync(AsyncCallback callback, object stateObject) { return BeginExecuteNonQueryInternal(0, callback, stateObject, CommandTimeout, inRetry: false, asyncWrite: true); @@ -1539,7 +1575,8 @@ private void BeginExecuteNonQueryInternalReadStage(TaskCompletionSource TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -1550,7 +1587,8 @@ private void BeginExecuteNonQueryInternalReadStage(TaskCompletionSource _stateObj.ReadSni(completion); } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -1661,6 +1699,7 @@ private void WaitForAsyncResults(IAsyncResult asyncResult, bool isInternal) } } + /// public int EndExecuteNonQuery(IAsyncResult asyncResult) { try @@ -1770,7 +1809,8 @@ private object InternalEndExecuteNonQuery(IAsyncResult asyncResult, string endMe TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -1854,7 +1894,8 @@ private object InternalEndExecuteNonQuery(IAsyncResult asyncResult, string endMe return _rowsAffected; } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -1893,7 +1934,8 @@ private Task InternalExecuteNonQuery(TaskCompletionSource completion, st TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -1962,7 +2004,8 @@ private Task InternalExecuteNonQuery(TaskCompletionSource completion, st return task; } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -1985,6 +2028,7 @@ private Task InternalExecuteNonQuery(TaskCompletionSource completion, st } } + /// public XmlReader ExecuteXmlReader() { SqlConnection.ExecutePermission.Demand(); @@ -2024,6 +2068,7 @@ public XmlReader ExecuteXmlReader() } } + /// [System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)] public IAsyncResult BeginExecuteXmlReader() { @@ -2031,6 +2076,7 @@ public IAsyncResult BeginExecuteXmlReader() return BeginExecuteXmlReader(null, null); } + /// [System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)] public IAsyncResult BeginExecuteXmlReader(AsyncCallback callback, object stateObject) { @@ -2128,7 +2174,8 @@ private void BeginExecuteXmlReaderInternalReadStage(TaskCompletionSource TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -2139,7 +2186,8 @@ private void BeginExecuteXmlReaderInternalReadStage(TaskCompletionSource _stateObj.ReadSni(completion); } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -2176,6 +2224,7 @@ private void BeginExecuteXmlReaderInternalReadStage(TaskCompletionSource } } + /// public XmlReader EndExecuteXmlReader(IAsyncResult asyncResult) { try @@ -2292,12 +2341,14 @@ private XmlReader CompleteXmlReader(SqlDataReader ds) return xr; } + /// [System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)] public IAsyncResult BeginExecuteReader() { return BeginExecuteReader(null, null, CommandBehavior.Default); } + /// [System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)] public IAsyncResult BeginExecuteReader(AsyncCallback callback, object stateObject) { @@ -2310,6 +2361,7 @@ override protected DbDataReader ExecuteDbDataReader(CommandBehavior behavior) return ExecuteReader(behavior, ADP.ExecuteReader); } + /// new public SqlDataReader ExecuteReader() { SqlStatistics statistics = null; @@ -2328,6 +2380,7 @@ override protected DbDataReader ExecuteDbDataReader(CommandBehavior behavior) } } + /// new public SqlDataReader ExecuteReader(CommandBehavior behavior) { IntPtr hscp; @@ -2343,12 +2396,14 @@ override protected DbDataReader ExecuteDbDataReader(CommandBehavior behavior) } } + /// [System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)] public IAsyncResult BeginExecuteReader(CommandBehavior behavior) { return BeginExecuteReader(null, null, behavior); } + /// [System.Security.Permissions.HostProtectionAttribute(ExternalThreading = true)] public IAsyncResult BeginExecuteReader(AsyncCallback callback, object stateObject, CommandBehavior behavior) { @@ -2378,7 +2433,8 @@ internal SqlDataReader ExecuteReader(CommandBehavior behavior, string method) TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -2390,7 +2446,8 @@ internal SqlDataReader ExecuteReader(CommandBehavior behavior, string method) return result; } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -2423,6 +2480,7 @@ internal SqlDataReader ExecuteReader(CommandBehavior behavior, string method) } } + /// public SqlDataReader EndExecuteReader(IAsyncResult asyncResult) { try @@ -2726,7 +2784,8 @@ private void BeginExecuteReaderInternalReadStage(TaskCompletionSource co TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -2737,7 +2796,8 @@ private void BeginExecuteReaderInternalReadStage(TaskCompletionSource co _stateObj.ReadSni(completion); } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -2797,7 +2857,8 @@ private SqlDataReader InternalEndExecuteReader(IAsyncResult asyncResult, string TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -2808,7 +2869,8 @@ private SqlDataReader InternalEndExecuteReader(IAsyncResult asyncResult, string return reader; } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -2831,6 +2893,7 @@ private SqlDataReader InternalEndExecuteReader(IAsyncResult asyncResult, string } } + /// public override Task ExecuteNonQueryAsync(CancellationToken cancellationToken) { @@ -2884,6 +2947,8 @@ public override Task ExecuteNonQueryAsync(CancellationToken cancellationTok return returnedTask; } + + /// protected override Task ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { return ExecuteReaderAsync(behavior, cancellationToken).ContinueWith((result) => @@ -2896,21 +2961,25 @@ protected override Task ExecuteDbDataReaderAsync(CommandBehavior b }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled, TaskScheduler.Default); } + /// new public Task ExecuteReaderAsync() { return ExecuteReaderAsync(CommandBehavior.Default, CancellationToken.None); } + /// new public Task ExecuteReaderAsync(CommandBehavior behavior) { return ExecuteReaderAsync(behavior, CancellationToken.None); } + /// new public Task ExecuteReaderAsync(CancellationToken cancellationToken) { return ExecuteReaderAsync(CommandBehavior.Default, cancellationToken); } + /// new public Task ExecuteReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken) { @@ -2964,6 +3033,7 @@ protected override Task ExecuteDbDataReaderAsync(CommandBehavior b return returnedTask; } + /// public override Task ExecuteScalarAsync(CancellationToken cancellationToken) { return ExecuteReaderAsync(cancellationToken).ContinueWith((executeTask) => @@ -3038,11 +3108,13 @@ public override Task ExecuteScalarAsync(CancellationToken cancellationTo }, TaskScheduler.Default).Unwrap(); } + /// public Task ExecuteXmlReaderAsync() { return ExecuteXmlReaderAsync(CancellationToken.None); } + /// public Task ExecuteXmlReaderAsync(CancellationToken cancellationToken) { @@ -3899,7 +3971,8 @@ private void PrepareForTransparentEncryption(CommandBehavior cmdBehavior, bool r TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -3959,35 +4032,38 @@ private void PrepareForTransparentEncryption(CommandBehavior cmdBehavior, bool r #if DEBUG TdsParser.ReliabilitySection tdsReliabilitySectionAsync = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySectionAsync.Start(); #endif //DEBUG - // Check for any exceptions on network write, before reading. - CheckThrowSNIException(); + // Check for any exceptions on network write, before reading. + CheckThrowSNIException(); - // If it is async, then TryFetchInputParameterEncryptionInfo-> RunExecuteReaderTds would have incremented the async count. - // Decrement it when we are about to complete async execute reader. - SqlInternalConnectionTds internalConnectionTds = _activeConnection.GetOpenTdsConnection(); - if (internalConnectionTds != null) - { - internalConnectionTds.DecrementAsyncCount(); - decrementAsyncCountInFinallyBlockAsync = false; - } + // If it is async, then TryFetchInputParameterEncryptionInfo-> RunExecuteReaderTds would have incremented the async count. + // Decrement it when we are about to complete async execute reader. + SqlInternalConnectionTds internalConnectionTds = _activeConnection.GetOpenTdsConnection(); + if (internalConnectionTds != null) + { + internalConnectionTds.DecrementAsyncCount(); + decrementAsyncCountInFinallyBlockAsync = false; + } - // Complete executereader. - describeParameterEncryptionDataReader = CompleteAsyncExecuteReader(forDescribeParameterEncryption: true); - Debug.Assert(null == _stateObj, "non-null state object in PrepareForTransparentEncryption."); + // Complete executereader. + describeParameterEncryptionDataReader = CompleteAsyncExecuteReader(forDescribeParameterEncryption: true); + Debug.Assert(null == _stateObj, "non-null state object in PrepareForTransparentEncryption."); - // Read the results of describe parameter encryption. - ReadDescribeEncryptionParameterResults(describeParameterEncryptionDataReader, describeParameterEncryptionRpcOriginalRpcMap); + // Read the results of describe parameter encryption. + ReadDescribeEncryptionParameterResults(describeParameterEncryptionDataReader, describeParameterEncryptionRpcOriginalRpcMap); #if DEBUG // Failpoint to force the thread to halt to simulate cancellation of SqlCommand. - if (_sleepAfterReadDescribeEncryptionParameterResults) { + if (_sleepAfterReadDescribeEncryptionParameterResults) + { Thread.Sleep(10000); } } - finally { + finally + { tdsReliabilitySectionAsync.Stop(); } #endif //DEBUG @@ -4038,41 +4114,44 @@ private void PrepareForTransparentEncryption(CommandBehavior cmdBehavior, bool r try { #if DEBUG - TdsParser.ReliabilitySection tdsReliabilitySectionAsync = new TdsParser.ReliabilitySection(); - RuntimeHelpers.PrepareConstrainedRegions(); - try { - tdsReliabilitySectionAsync.Start(); + TdsParser.ReliabilitySection tdsReliabilitySectionAsync = new TdsParser.ReliabilitySection(); + RuntimeHelpers.PrepareConstrainedRegions(); + try + { + tdsReliabilitySectionAsync.Start(); #endif //DEBUG - // Check for any exceptions on network write, before reading. - CheckThrowSNIException(); + // Check for any exceptions on network write, before reading. + CheckThrowSNIException(); - // If it is async, then TryFetchInputParameterEncryptionInfo-> RunExecuteReaderTds would have incremented the async count. - // Decrement it when we are about to complete async execute reader. - SqlInternalConnectionTds internalConnectionTds = _activeConnection.GetOpenTdsConnection(); - if (internalConnectionTds != null) - { - internalConnectionTds.DecrementAsyncCount(); - decrementAsyncCountInFinallyBlockAsync = false; - } + // If it is async, then TryFetchInputParameterEncryptionInfo-> RunExecuteReaderTds would have incremented the async count. + // Decrement it when we are about to complete async execute reader. + SqlInternalConnectionTds internalConnectionTds = _activeConnection.GetOpenTdsConnection(); + if (internalConnectionTds != null) + { + internalConnectionTds.DecrementAsyncCount(); + decrementAsyncCountInFinallyBlockAsync = false; + } - // Complete executereader. - describeParameterEncryptionDataReader = CompleteAsyncExecuteReader(forDescribeParameterEncryption: true); - Debug.Assert(null == _stateObj, "non-null state object in PrepareForTransparentEncryption."); + // Complete executereader. + describeParameterEncryptionDataReader = CompleteAsyncExecuteReader(forDescribeParameterEncryption: true); + Debug.Assert(null == _stateObj, "non-null state object in PrepareForTransparentEncryption."); - // Read the results of describe parameter encryption. - ReadDescribeEncryptionParameterResults(describeParameterEncryptionDataReader, describeParameterEncryptionRpcOriginalRpcMap); + // Read the results of describe parameter encryption. + ReadDescribeEncryptionParameterResults(describeParameterEncryptionDataReader, describeParameterEncryptionRpcOriginalRpcMap); #if DEBUG - // Failpoint to force the thread to halt to simulate cancellation of SqlCommand. - if (_sleepAfterReadDescribeEncryptionParameterResults) { - Thread.Sleep(10000); - } + // Failpoint to force the thread to halt to simulate cancellation of SqlCommand. + if (_sleepAfterReadDescribeEncryptionParameterResults) + { + Thread.Sleep(10000); + } #endif #if DEBUG - } - finally { - tdsReliabilitySectionAsync.Stop(); - } + } + finally + { + tdsReliabilitySectionAsync.Stop(); + } #endif //DEBUG } catch (Exception e) @@ -4101,7 +4180,8 @@ private void PrepareForTransparentEncryption(CommandBehavior cmdBehavior, bool r #if DEBUG // Failpoint to force the thread to halt to simulate cancellation of SqlCommand. - if (_sleepAfterReadDescribeEncryptionParameterResults) { + if (_sleepAfterReadDescribeEncryptionParameterResults) + { Thread.Sleep(10000); } #endif @@ -4125,7 +4205,8 @@ private void PrepareForTransparentEncryption(CommandBehavior cmdBehavior, bool r } } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -4281,7 +4362,8 @@ private SqlDataReader TryFetchInputParameterEncryptionInfo(int timeout, #if DEBUG // Failpoint to force the thread to halt to simulate cancellation of SqlCommand. - if (_sleepDuringTryFetchInputParameterEncryptionInfo) { + if (_sleepDuringTryFetchInputParameterEncryptionInfo) + { Thread.Sleep(10000); } #endif @@ -4317,13 +4399,7 @@ private SqlParameter GetSqlParameterWithQueryText(string queryText) return sqlParam; } - /// - /// Constructs the sp_describe_parameter_encryption request with the values from the original RPC call. - /// Prototype for is - /// exec sp_describe_parameter_encryption @tsql=N'[SQL Statement]', @params=N'@p1 varbinary(256)' - /// - /// Original RPC request - /// sp_describe_parameter_encryption request being built + private void PrepareDescribeParameterEncryptionRequest(_SqlRPC originalRpcRequest, ref _SqlRPC describeParameterEncryptionRequest, byte[] attestationParameters = null) { Debug.Assert(originalRpcRequest != null); @@ -4690,7 +4766,7 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi } #if DEBUG - Debug.Assert( (rowsAffected== 0) || (rowsAffected == RowsAffectedByDescribeParameterEncryption), + Debug.Assert((rowsAffected == 0) || (rowsAffected == RowsAffectedByDescribeParameterEncryption), "number of rows received (if received) for describe parameter encryption should be equal to rows affected by describe parameter encryption."); #endif @@ -4799,7 +4875,8 @@ internal SqlDataReader RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -4909,7 +4986,8 @@ internal SqlDataReader RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -5132,7 +5210,8 @@ private SqlDataReader RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavi if (describeParameterEncryptionRequest) { #if DEBUG - if (_sleepDuringRunExecuteReaderTdsForSpDescribeParameterEncryption) { + if (_sleepDuringRunExecuteReaderTdsForSpDescribeParameterEncryption) + { Thread.Sleep(10000); } #endif @@ -5559,7 +5638,8 @@ private void NotifyDependency() _sqlDep.StartTimer(Notification); } } - + + /// public SqlCommand Clone() { SqlCommand clone = new SqlCommand(this); @@ -5637,7 +5717,8 @@ private void ValidateCommand(string method, bool async) TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -5649,7 +5730,8 @@ private void ValidateCommand(string method, bool async) } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -5773,7 +5855,8 @@ private void ReliablePutStateObject() TdsParser.ReliabilitySection tdsReliabilitySection = new TdsParser.ReliabilitySection(); RuntimeHelpers.PrepareConstrainedRegions(); - try { + try + { tdsReliabilitySection.Start(); #else { @@ -5783,7 +5866,8 @@ private void ReliablePutStateObject() } #if DEBUG - finally { + finally + { tdsReliabilitySection.Stop(); } #endif //DEBUG @@ -7400,32 +7484,42 @@ private void WriteEndExecuteEvent(bool success, int? sqlExceptionNumber, bool sy } #if DEBUG - internal void CompletePendingReadWithSuccess(bool resetForcePendingReadsToWait) { + internal void CompletePendingReadWithSuccess(bool resetForcePendingReadsToWait) + { var stateObj = _stateObj; - if (stateObj != null) { + if (stateObj != null) + { stateObj.CompletePendingReadWithSuccess(resetForcePendingReadsToWait); } - else { + else + { var tempCachedAsyncState = cachedAsyncState; - if (tempCachedAsyncState != null) { + if (tempCachedAsyncState != null) + { var reader = tempCachedAsyncState.CachedAsyncReader; - if (reader != null) { + if (reader != null) + { reader.CompletePendingReadWithSuccess(resetForcePendingReadsToWait); } } } } - internal void CompletePendingReadWithFailure(int errorCode, bool resetForcePendingReadsToWait) { + internal void CompletePendingReadWithFailure(int errorCode, bool resetForcePendingReadsToWait) + { var stateObj = _stateObj; - if (stateObj != null) { + if (stateObj != null) + { stateObj.CompletePendingReadWithFailure(errorCode, resetForcePendingReadsToWait); } - else { + else + { var tempCachedAsyncState = _cachedAsyncState; - if (tempCachedAsyncState != null) { + if (tempCachedAsyncState != null) + { var reader = tempCachedAsyncState.CachedAsyncReader; - if (reader != null) { + if (reader != null) + { reader.CompletePendingReadWithFailure(errorCode, resetForcePendingReadsToWait); } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs index 7a59d3a645..dbbea38502 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -2475,7 +2475,7 @@ public static void ChangePassword(string connectionString, string newPassword) } } - /// + /// public static void ChangePassword(string connectionString, SqlCredential credential, SecureString newSecurePassword) { IntPtr hscp; @@ -2758,6 +2758,7 @@ internal byte[] GetBytes(object o, out Format format, out int maxSize) // You must not change the guid for this coclass // or the iid for the ISQLDebug interface // + /// [ ComVisible(true), ClassInterface(ClassInterfaceType.None), From 310f91e0040a38a06aa1e1a3c77b67a257aa475f Mon Sep 17 00:00:00 2001 From: Javad Date: Thu, 19 Sep 2019 11:59:14 -0700 Subject: [PATCH 3/9] Documentation's sample files formatted. --- doc/samples/DataTableReader_GetValues.cs | 2 +- doc/samples/IDbCommand_CommandTimeout.cs | 23 ++++---- doc/samples/SqlBulkCopy_ColumnMapping.cs | 6 +- .../SqlBulkCopy_ColumnMappingColNameIndex.cs | 6 +- .../SqlBulkCopy_ColumnMappingCollection.cs | 6 +- ...BulkCopy_ColumnMappingCollectionOrdinal.cs | 6 +- .../SqlBulkCopy_ColumnMappingIndexColName.cs | 6 +- .../SqlBulkCopy_ColumnMappingOrdersDetails.cs | 8 +-- .../SqlBulkCopy_ColumnMappingRemove.cs | 8 +-- .../SqlBulkCopy_ColumnMappingRemoveAt.cs | 22 ++++---- doc/samples/SqlBulkCopy_KeepIdentity.cs | 6 +- .../SqlClientFactory_DataSourceEnumerator.cs | 2 +- ...qlCommand.BeginExecuteReaderAsyncSimple.cs | 2 +- doc/samples/SqlCommand.Cancel.cs | 2 +- .../SqlCommand_BeginExecuteNonQuery.cs | 20 +++---- .../SqlCommand_BeginExecuteNonQueryForm.cs | 2 +- ...Command_BeginExecuteReaderAsyncBehavior.cs | 2 +- .../SqlCommand_BeginExecuteXmlReader.cs | 2 +- .../SqlCommand_BeginExecuteXmlReaderAsync.cs | 6 +- doc/samples/SqlCommand_CommandText.cs | 24 ++++---- doc/samples/SqlCommand_Connection.cs | 4 +- doc/samples/SqlCommand_ExecuteReader.cs | 4 +- doc/samples/SqlCommand_ExecuteReader2.cs | 4 +- doc/samples/SqlCommand_SqlCommand1.cs | 24 ++++---- doc/samples/SqlConnectionStringBuilder.cs | 2 +- doc/samples/SqlConnectionStringBuilder2.cs | 4 +- doc/samples/SqlConnectionStringBuilder3.cs | 6 +- ...ConnectionStringBuilder_ApplicationName.cs | 6 +- ...ionStringBuilder_AsynchronousProcessing.cs | 6 +- ...onnectionStringBuilder_AttachDBFilename.cs | 2 +- .../SqlConnectionStringBuilder_Clear.cs | 2 +- ...lConnectionStringBuilder_ConnectTimeout.cs | 2 +- .../SqlConnectionStringBuilder_ContainsKey.cs | 2 +- .../SqlConnectionStringBuilder_DataSource.cs | 2 +- ...lConnectionStringBuilder_InitialCatalog.cs | 8 +-- ...nectionStringBuilder_IntegratedSecurity.cs | 6 +- .../SqlConnectionStringBuilder_Keys.cs | 2 +- ...nStringBuilder_MultipleActiveResultSets.cs | 2 +- .../SqlConnectionStringBuilder_Password.cs | 38 +++++++------ .../SqlConnectionStringBuilder_Remove.cs | 2 +- .../SqlConnectionStringBuilder_TryGetValue.cs | 2 +- .../SqlConnectionStringBuilder_Values.cs | 4 +- doc/samples/SqlConnection_BeginTransaction.cs | 2 +- .../SqlConnection_BeginTransaction1.cs | 2 +- .../SqlConnection_BeginTransaction2.cs | 2 +- .../SqlConnection_BeginTransaction3.cs | 2 +- doc/samples/SqlConnection_ConnectionString.cs | 2 +- .../SqlConnection_ConnectionString1.cs | 4 +- .../SqlConnection_ConnectionTimeout.cs | 2 +- doc/samples/SqlConnection_CreateCommand.cs | 25 +++++---- doc/samples/SqlConnection_DataSource.cs | 2 +- doc/samples/SqlConnection_Database.cs | 2 +- doc/samples/SqlConnection_Open.cs | 2 +- doc/samples/SqlConnection_PacketSize.cs | 2 +- doc/samples/SqlConnection_ServerVersion.cs | 4 +- doc/samples/SqlConnection_SqlConnection.cs | 2 +- doc/samples/SqlConnection_SqlConnection1.cs | 2 +- doc/samples/SqlConnection_WorkstationId.cs | 2 +- doc/samples/SqlDataAdapter.cs | 2 +- doc/samples/SqlDataAdapter_RowUpdated.cs | 56 +++++++++---------- doc/samples/SqlDataAdapter_SelectCommand.cs | 2 +- doc/samples/SqlDataAdapter_SqlDataAdapter.cs | 2 +- doc/samples/SqlDataAdapter_SqlDataAdapter1.cs | 14 ++--- doc/samples/SqlDataAdapter_SqlDataAdapter2.cs | 2 +- doc/samples/SqlDataAdapter_SqlDataAdapter3.cs | 2 +- doc/samples/SqlDataReader_Close.cs | 2 +- doc/samples/SqlDataReader_GetOrdinal.cs | 2 +- doc/samples/SqlDataReader_IsDBNull.cs | 2 +- doc/samples/SqlDataReader_Read.cs | 2 +- doc/samples/SqlError_State.cs | 2 +- doc/samples/SqlError_ToString.cs | 2 +- doc/samples/SqlException_Errors1.cs | 2 +- doc/samples/SqlException_Errors2.cs | 4 +- doc/samples/SqlParameter.cs | 2 +- doc/samples/SqlParameter_IsNullable.cs | 2 +- doc/samples/SqlParameter_ParameterName.cs | 2 +- 76 files changed, 232 insertions(+), 226 deletions(-) diff --git a/doc/samples/DataTableReader_GetValues.cs b/doc/samples/DataTableReader_GetValues.cs index 184ff94c3d..48def74cb6 100644 --- a/doc/samples/DataTableReader_GetValues.cs +++ b/doc/samples/DataTableReader_GetValues.cs @@ -72,4 +72,4 @@ private static void TestGetValues(SqlDataReader reader) Console.WriteLine(values[i]); } // -} \ No newline at end of file +} diff --git a/doc/samples/IDbCommand_CommandTimeout.cs b/doc/samples/IDbCommand_CommandTimeout.cs index 74a5372a42..8da5dd7c49 100644 --- a/doc/samples/IDbCommand_CommandTimeout.cs +++ b/doc/samples/IDbCommand_CommandTimeout.cs @@ -6,18 +6,17 @@ using System.Data.Common; using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { - protected DataSet DataSet1; - protected DataGrid dataGrid1; + protected DataSet DataSet1; + protected DataGrid dataGrid1; - public void CreateSqlCommand() - { - SqlCommand command = new SqlCommand(); - command.CommandTimeout = 15; - command.CommandType = CommandType.Text; - } -// - -} \ No newline at end of file + public void CreateSqlCommand() + { + SqlCommand command = new SqlCommand(); + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + } + // +} diff --git a/doc/samples/SqlBulkCopy_ColumnMapping.cs b/doc/samples/SqlBulkCopy_ColumnMapping.cs index 5a35ffdfde..0578f13d02 100644 --- a/doc/samples/SqlBulkCopy_ColumnMapping.cs +++ b/doc/samples/SqlBulkCopy_ColumnMapping.cs @@ -81,12 +81,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the sourceConnection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingColNameIndex.cs b/doc/samples/SqlBulkCopy_ColumnMappingColNameIndex.cs index ac4f3f3cad..9c1e797bc8 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingColNameIndex.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingColNameIndex.cs @@ -74,12 +74,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the sourceConnection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs b/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs index 81880874fa..4cf90008c6 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingCollection.cs @@ -74,12 +74,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the sourceConnection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs b/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs index 53f6b55edc..fa0db0ef4c 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingCollectionOrdinal.cs @@ -74,12 +74,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the sourceConnection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs b/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs index 53f6b55edc..fa0db0ef4c 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingIndexColName.cs @@ -74,12 +74,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the sourceConnection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingOrdersDetails.cs b/doc/samples/SqlBulkCopy_ColumnMappingOrdersDetails.cs index ce2742d250..a488c621bc 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingOrdersDetails.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingOrdersDetails.cs @@ -113,7 +113,7 @@ static void Main() } // Set up the order details destination. - bulkCopy.DestinationTableName ="dbo.BulkCopyDemoOrderDetail"; + bulkCopy.DestinationTableName = "dbo.BulkCopyDemoOrderDetail"; // Clear the ColumnMappingCollection. bulkCopy.ColumnMappings.Clear(); @@ -157,12 +157,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the connection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs b/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs index f5e7fa8e7f..f5dc29e254 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingRemove.cs @@ -113,7 +113,7 @@ static void Main() } // Set up the order details destination. - bulkCopy.DestinationTableName ="dbo.BulkCopyDemoOrderDetail"; + bulkCopy.DestinationTableName = "dbo.BulkCopyDemoOrderDetail"; // Clear the ColumnMappingCollection. bulkCopy.ColumnMappings.Clear(); @@ -157,12 +157,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the connection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingRemoveAt.cs b/doc/samples/SqlBulkCopy_ColumnMappingRemoveAt.cs index 0d6c51fc1d..9d8091965d 100644 --- a/doc/samples/SqlBulkCopy_ColumnMappingRemoveAt.cs +++ b/doc/samples/SqlBulkCopy_ColumnMappingRemoveAt.cs @@ -77,13 +77,13 @@ static void Main() "[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID] " + "WHERE [AccountNumber] = @accountNumber;", connection2); - SqlParameter accountDetail = new SqlParameter(); - accountDetail.ParameterName = "@accountNumber"; - accountDetail.SqlDbType = SqlDbType.NVarChar; - accountDetail.Direction = ParameterDirection.Input; - accountDetail.Value = "10-4020-000034"; - sourceDetailData.Parameters.Add(accountDetail); - SqlDataReader readerDetail = sourceDetailData.ExecuteReader(); + SqlParameter accountDetail = new SqlParameter(); + accountDetail.ParameterName = "@accountNumber"; + accountDetail.SqlDbType = SqlDbType.NVarChar; + accountDetail.Direction = ParameterDirection.Input; + accountDetail.Value = "10-4020-000034"; + sourceDetailData.Parameters.Add(accountDetail); + SqlDataReader readerDetail = sourceDetailData.ExecuteReader(); // Create the SqlBulkCopy object. using (SqlBulkCopy bulkCopy = @@ -113,7 +113,7 @@ static void Main() } // Set up the order details destination. - bulkCopy.DestinationTableName ="dbo.BulkCopyDemoOrderDetail"; + bulkCopy.DestinationTableName = "dbo.BulkCopyDemoOrderDetail"; // Rather than clearing mappings that are not necessary // for the next bulk copyo peration, the unneeded mappings @@ -160,12 +160,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the connection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlBulkCopy_KeepIdentity.cs b/doc/samples/SqlBulkCopy_KeepIdentity.cs index 20b13bf5ab..da85715725 100644 --- a/doc/samples/SqlBulkCopy_KeepIdentity.cs +++ b/doc/samples/SqlBulkCopy_KeepIdentity.cs @@ -71,12 +71,12 @@ static void Main() } private static string GetConnectionString() - // To avoid storing the sourceConnection string in your code, - // you can retrieve it from a configuration file. + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. { return "Data Source=(local); " + " Integrated Security=true;" + "Initial Catalog=AdventureWorks;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlClientFactory_DataSourceEnumerator.cs b/doc/samples/SqlClientFactory_DataSourceEnumerator.cs index 3429ea4e4c..f1e1a09992 100644 --- a/doc/samples/SqlClientFactory_DataSourceEnumerator.cs +++ b/doc/samples/SqlClientFactory_DataSourceEnumerator.cs @@ -36,4 +36,4 @@ private static void ListServers(DbProviderFactory factory) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs b/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs index 0079c6abe7..c010b16c06 100644 --- a/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs +++ b/doc/samples/SqlCommand.BeginExecuteReaderAsyncSimple.cs @@ -99,4 +99,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlCommand.Cancel.cs b/doc/samples/SqlCommand.Cancel.cs index 7d631829a5..6b15101662 100644 --- a/doc/samples/SqlCommand.Cancel.cs +++ b/doc/samples/SqlCommand.Cancel.cs @@ -66,4 +66,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlCommand_BeginExecuteNonQuery.cs b/doc/samples/SqlCommand_BeginExecuteNonQuery.cs index 05cfb37a4c..4598ffcd38 100644 --- a/doc/samples/SqlCommand_BeginExecuteNonQuery.cs +++ b/doc/samples/SqlCommand_BeginExecuteNonQuery.cs @@ -11,12 +11,12 @@ static void Main() // BeginExecuteNonQuery functionality. // The WAITFOR statement simply adds enough time to prove the // asynchronous nature of the command. - - string commandText = - "UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 " + - "WHERE ReorderPoint Is Not Null;" + - "WAITFOR DELAY '0:0:3';" + - "UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 " + + + string commandText = + "UPDATE Production.Product SET ReorderPoint = ReorderPoint + 1 " + + "WHERE ReorderPoint Is Not Null;" + + "WAITFOR DELAY '0:0:3';" + + "UPDATE Production.Product SET ReorderPoint = ReorderPoint - 1 " + "WHERE ReorderPoint Is Not Null"; RunCommandAsynchronously(commandText, GetConnectionString()); @@ -32,7 +32,7 @@ private static void RunCommandAsynchronously( // the specified command against the connection. For this example, // the code displays an indicator as it is working, verifying the // asynchronous behavior. - using (SqlConnection connection = + using (SqlConnection connection = new SqlConnection(connectionString)) { try @@ -50,7 +50,7 @@ private static void RunCommandAsynchronously( // on the main thread. System.Threading.Thread.Sleep(100); } - Console.WriteLine("Command complete. Affected {0} rows.", + Console.WriteLine("Command complete. Affected {0} rows.", command.EndExecuteNonQuery(result)); } catch (SqlException ex) @@ -80,6 +80,6 @@ private static string GetConnectionString() // to execute asynchronously. return "Data Source=(local);Integrated Security=SSPI;" + "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; - } + } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs b/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs index d8e4019899..5bc740978a 100644 --- a/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs +++ b/doc/samples/SqlCommand_BeginExecuteNonQueryForm.cs @@ -190,4 +190,4 @@ private void HandleCallback(IAsyncResult result) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs b/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs index 4d4e670cd2..830bf36be7 100644 --- a/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs +++ b/doc/samples/SqlCommand_BeginExecuteReaderAsyncBehavior.cs @@ -186,4 +186,4 @@ void Form1_FormClosing(object sender, FormClosingEventArgs e) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlCommand_BeginExecuteXmlReader.cs b/doc/samples/SqlCommand_BeginExecuteXmlReader.cs index 83c800183a..9f99c070a9 100644 --- a/doc/samples/SqlCommand_BeginExecuteXmlReader.cs +++ b/doc/samples/SqlCommand_BeginExecuteXmlReader.cs @@ -82,4 +82,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs b/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs index e5e3785ed3..b3ba1902ae 100644 --- a/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs +++ b/doc/samples/SqlCommand_BeginExecuteXmlReaderAsync.cs @@ -69,7 +69,7 @@ private void DisplayProductInfo(XmlReader reader) DisplayStatus("Ready"); } - private void Form1_FormClosing(object sender, + private void Form1_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e) { if (isExecuting) @@ -84,7 +84,7 @@ private void button1_Click(object sender, System.EventArgs e) { if (isExecuting) { - MessageBox.Show(this, + MessageBox.Show(this, "Already executing. Please wait until the current query " + "has completed."); } @@ -189,4 +189,4 @@ private void Form1_Load(object sender, System.EventArgs e) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlCommand_CommandText.cs b/doc/samples/SqlCommand_CommandText.cs index 77cb7343da..b86ad952c3 100644 --- a/doc/samples/SqlCommand_CommandText.cs +++ b/doc/samples/SqlCommand_CommandText.cs @@ -6,18 +6,18 @@ using System.Data.Common; using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { - protected DataSet DataSet1; - protected DataGrid dataGrid1; + protected DataSet DataSet1; + protected DataGrid dataGrid1; -public void CreateCommand() - { - SqlCommand command = new SqlCommand(); - command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"; - command.CommandTimeout = 15; - command.CommandType = CommandType.Text; - } -// + public void CreateCommand() + { + SqlCommand command = new SqlCommand(); + command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"; + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + } + // -} \ No newline at end of file +} diff --git a/doc/samples/SqlCommand_Connection.cs b/doc/samples/SqlCommand_Connection.cs index 54a20aa4e4..c939012b0d 100644 --- a/doc/samples/SqlCommand_Connection.cs +++ b/doc/samples/SqlCommand_Connection.cs @@ -1,4 +1,4 @@ - // +// using System; using System.Data; using Microsoft.Data.SqlClient; @@ -39,4 +39,4 @@ private static void CreateCommand(string queryString, } // } -} \ No newline at end of file +} diff --git a/doc/samples/SqlCommand_ExecuteReader.cs b/doc/samples/SqlCommand_ExecuteReader.cs index cad1726171..2632ef138d 100644 --- a/doc/samples/SqlCommand_ExecuteReader.cs +++ b/doc/samples/SqlCommand_ExecuteReader.cs @@ -1,4 +1,4 @@ - // +// using System; using System.Data; using Microsoft.Data.SqlClient; @@ -32,4 +32,4 @@ private static void CreateCommand(string queryString, } } // -} \ No newline at end of file +} diff --git a/doc/samples/SqlCommand_ExecuteReader2.cs b/doc/samples/SqlCommand_ExecuteReader2.cs index bf67077951..86c3f66a7a 100644 --- a/doc/samples/SqlCommand_ExecuteReader2.cs +++ b/doc/samples/SqlCommand_ExecuteReader2.cs @@ -1,4 +1,4 @@ - // +// using System; using System.Data; using Microsoft.Data.SqlClient; @@ -30,4 +30,4 @@ private static void CreateCommand(string queryString, } } // -} \ No newline at end of file +} diff --git a/doc/samples/SqlCommand_SqlCommand1.cs b/doc/samples/SqlCommand_SqlCommand1.cs index 7488723c89..3eac5a9c38 100644 --- a/doc/samples/SqlCommand_SqlCommand1.cs +++ b/doc/samples/SqlCommand_SqlCommand1.cs @@ -6,19 +6,19 @@ using System.Data.Common; using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { - protected DataSet DataSet1; - protected DataGrid dataGrid1; + protected DataSet DataSet1; + protected DataGrid dataGrid1; -public void CreateCommand() - { - string queryString = "SELECT * FROM Categories ORDER BY CategoryID"; - SqlCommand command = new SqlCommand(queryString); - command.CommandTimeout = 15; - command.CommandType = CommandType.Text; - } -// + public void CreateCommand() + { + string queryString = "SELECT * FROM Categories ORDER BY CategoryID"; + SqlCommand command = new SqlCommand(queryString); + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + } + // -} \ No newline at end of file +} diff --git a/doc/samples/SqlConnectionStringBuilder.cs b/doc/samples/SqlConnectionStringBuilder.cs index 483193d3cb..bb19d43b16 100644 --- a/doc/samples/SqlConnectionStringBuilder.cs +++ b/doc/samples/SqlConnectionStringBuilder.cs @@ -51,4 +51,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder2.cs b/doc/samples/SqlConnectionStringBuilder2.cs index fc2d827e1b..534f760c31 100644 --- a/doc/samples/SqlConnectionStringBuilder2.cs +++ b/doc/samples/SqlConnectionStringBuilder2.cs @@ -7,7 +7,7 @@ class Program { static void Main() { - SqlConnectionStringBuilder builder = + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); builder["Data Source"] = "(local)"; builder["Integrated Security"] = true; @@ -22,4 +22,4 @@ static void Main() Console.ReadLine(); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder3.cs b/doc/samples/SqlConnectionStringBuilder3.cs index 6026f888bd..3e0c253039 100644 --- a/doc/samples/SqlConnectionStringBuilder3.cs +++ b/doc/samples/SqlConnectionStringBuilder3.cs @@ -9,10 +9,10 @@ static void Main() { try { - string connectString = + string connectString = "Server=(local);Database=AdventureWorks;UID=ab;Pwd= a!Pass@@"; Console.WriteLine("Original: " + connectString); - SqlConnectionStringBuilder builder = + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString); Console.WriteLine("Modified: " + builder.ConnectionString); foreach (string key in builder.Keys) @@ -31,4 +31,4 @@ static void Main() } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_ApplicationName.cs b/doc/samples/SqlConnectionStringBuilder_ApplicationName.cs index d05941517a..c60bb282a2 100644 --- a/doc/samples/SqlConnectionStringBuilder_ApplicationName.cs +++ b/doc/samples/SqlConnectionStringBuilder_ApplicationName.cs @@ -9,9 +9,9 @@ static void Main() { try { - string connectString = "Server=(local);Initial Catalog=AdventureWorks;" + + string connectString = "Server=(local);Initial Catalog=AdventureWorks;" + "Integrated Security=true"; - SqlConnectionStringBuilder builder = + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString); Console.WriteLine("Original: " + builder.ConnectionString); Console.WriteLine("ApplicationName={0}", @@ -30,4 +30,4 @@ static void Main() } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_AsynchronousProcessing.cs b/doc/samples/SqlConnectionStringBuilder_AsynchronousProcessing.cs index 272a67cb49..b3706e86bd 100644 --- a/doc/samples/SqlConnectionStringBuilder_AsynchronousProcessing.cs +++ b/doc/samples/SqlConnectionStringBuilder_AsynchronousProcessing.cs @@ -38,7 +38,7 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks"; } - private static void RunCommandAsynchronously(string commandText, + private static void RunCommandAsynchronously(string commandText, string connectionString) { // Given command text and connection string, asynchronously execute @@ -69,7 +69,7 @@ private static void RunCommandAsynchronously(string commandText, catch (SqlException ex) { Console.WriteLine( - "Error {0}: Microsoft.Data.SqlClient.SqlConnectionStringBuilder", + "Error {0}: Microsoft.Data.SqlClient.SqlConnectionStringBuilder", ex.Number, ex.Message); } catch (InvalidOperationException ex) @@ -85,4 +85,4 @@ private static void RunCommandAsynchronously(string commandText, } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_AttachDBFilename.cs b/doc/samples/SqlConnectionStringBuilder_AttachDBFilename.cs index d56e69257c..0b0402b1ec 100644 --- a/doc/samples/SqlConnectionStringBuilder_AttachDBFilename.cs +++ b/doc/samples/SqlConnectionStringBuilder_AttachDBFilename.cs @@ -35,4 +35,4 @@ static void Main() } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_Clear.cs b/doc/samples/SqlConnectionStringBuilder_Clear.cs index 056463c1de..b91587ebe0 100644 --- a/doc/samples/SqlConnectionStringBuilder_Clear.cs +++ b/doc/samples/SqlConnectionStringBuilder_Clear.cs @@ -22,4 +22,4 @@ static void Main() Console.ReadLine(); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_ConnectTimeout.cs b/doc/samples/SqlConnectionStringBuilder_ConnectTimeout.cs index db9c06a8c8..7c700150bc 100644 --- a/doc/samples/SqlConnectionStringBuilder_ConnectTimeout.cs +++ b/doc/samples/SqlConnectionStringBuilder_ConnectTimeout.cs @@ -30,4 +30,4 @@ static void Main() } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_ContainsKey.cs b/doc/samples/SqlConnectionStringBuilder_ContainsKey.cs index 73f3b2a895..7a9fd3b13a 100644 --- a/doc/samples/SqlConnectionStringBuilder_ContainsKey.cs +++ b/doc/samples/SqlConnectionStringBuilder_ContainsKey.cs @@ -38,4 +38,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_DataSource.cs b/doc/samples/SqlConnectionStringBuilder_DataSource.cs index a5208443dc..14ef063e11 100644 --- a/doc/samples/SqlConnectionStringBuilder_DataSource.cs +++ b/doc/samples/SqlConnectionStringBuilder_DataSource.cs @@ -23,4 +23,4 @@ static void Main() Console.ReadLine(); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_InitialCatalog.cs b/doc/samples/SqlConnectionStringBuilder_InitialCatalog.cs index b2d3a1bc9b..9e057d44cb 100644 --- a/doc/samples/SqlConnectionStringBuilder_InitialCatalog.cs +++ b/doc/samples/SqlConnectionStringBuilder_InitialCatalog.cs @@ -12,7 +12,7 @@ static void Main() string connectString = "Data Source=(local);" + "Integrated Security=true"; - SqlConnectionStringBuilder builder = + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString); Console.WriteLine("Original: " + builder.ConnectionString); @@ -23,11 +23,11 @@ static void Main() // setting the value in this way results in the same // connection string: builder["Database"] = "AdventureWorks"; - Console.WriteLine("builder.InitialCatalog = " + Console.WriteLine("builder.InitialCatalog = " + builder.InitialCatalog); Console.WriteLine("Modified: " + builder.ConnectionString); - using (SqlConnection connection = + using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) { connection.Open(); @@ -45,4 +45,4 @@ static void Main() Console.ReadLine(); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_IntegratedSecurity.cs b/doc/samples/SqlConnectionStringBuilder_IntegratedSecurity.cs index b3a01a98ca..693298dd35 100644 --- a/doc/samples/SqlConnectionStringBuilder_IntegratedSecurity.cs +++ b/doc/samples/SqlConnectionStringBuilder_IntegratedSecurity.cs @@ -13,7 +13,7 @@ static void Main() "Data Source=(local);User ID=ab;Password=MyPassword;" + "Initial Catalog=AdventureWorks"; - SqlConnectionStringBuilder builder = + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectString); Console.WriteLine("Original: " + builder.ConnectionString); @@ -31,7 +31,7 @@ static void Main() Console.WriteLine("Modified: " + builder.ConnectionString); - using (SqlConnection connection = + using (SqlConnection connection = new SqlConnection(builder.ConnectionString)) { connection.Open(); @@ -49,4 +49,4 @@ static void Main() Console.ReadLine(); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_Keys.cs b/doc/samples/SqlConnectionStringBuilder_Keys.cs index ea85d8a5a0..1c31194cb1 100644 --- a/doc/samples/SqlConnectionStringBuilder_Keys.cs +++ b/doc/samples/SqlConnectionStringBuilder_Keys.cs @@ -23,4 +23,4 @@ static void Main() Console.ReadLine(); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_MultipleActiveResultSets.cs b/doc/samples/SqlConnectionStringBuilder_MultipleActiveResultSets.cs index dded117686..849951f4b1 100644 --- a/doc/samples/SqlConnectionStringBuilder_MultipleActiveResultSets.cs +++ b/doc/samples/SqlConnectionStringBuilder_MultipleActiveResultSets.cs @@ -26,4 +26,4 @@ static void Main() Console.ReadLine(); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_Password.cs b/doc/samples/SqlConnectionStringBuilder_Password.cs index ea31db3b06..5bc1d011b9 100644 --- a/doc/samples/SqlConnectionStringBuilder_Password.cs +++ b/doc/samples/SqlConnectionStringBuilder_Password.cs @@ -2,24 +2,28 @@ // using Microsoft.Data.SqlClient; -class Program { - public static void Main() { - SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); +class Program +{ + public static void Main() + { + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); - builder["Password"] = null; - string aa = builder.Password; - Console.WriteLine(aa.Length); + builder["Password"] = null; + string aa = builder.Password; + Console.WriteLine(aa.Length); - builder["Password"] = "??????"; - aa = builder.Password; - Console.WriteLine(aa.Length); + builder["Password"] = "??????"; + aa = builder.Password; + Console.WriteLine(aa.Length); - try { - builder.Password = null; - } - catch (ArgumentNullException e) { - Console.WriteLine("{0}", e); - } - } + try + { + builder.Password = null; + } + catch (ArgumentNullException e) + { + Console.WriteLine("{0}", e); + } + } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_Remove.cs b/doc/samples/SqlConnectionStringBuilder_Remove.cs index 8c640f35ea..7de94386a1 100644 --- a/doc/samples/SqlConnectionStringBuilder_Remove.cs +++ b/doc/samples/SqlConnectionStringBuilder_Remove.cs @@ -44,4 +44,4 @@ static void Main() Console.ReadLine(); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_TryGetValue.cs b/doc/samples/SqlConnectionStringBuilder_TryGetValue.cs index 4c447b1ce3..6724adeb94 100644 --- a/doc/samples/SqlConnectionStringBuilder_TryGetValue.cs +++ b/doc/samples/SqlConnectionStringBuilder_TryGetValue.cs @@ -58,4 +58,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnectionStringBuilder_Values.cs b/doc/samples/SqlConnectionStringBuilder_Values.cs index 9eab245e18..ae6f3b0f32 100644 --- a/doc/samples/SqlConnectionStringBuilder_Values.cs +++ b/doc/samples/SqlConnectionStringBuilder_Values.cs @@ -7,7 +7,7 @@ class Program { static void Main() { - SqlConnectionStringBuilder builder = + SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(GetConnectionString()); // Loop through each of the values, displaying the contents. @@ -26,4 +26,4 @@ private static string GetConnectionString() "Initial Catalog=AdventureWorks; Asynchronous Processing=true"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_BeginTransaction.cs b/doc/samples/SqlConnection_BeginTransaction.cs index f00ead429c..9665c33c12 100644 --- a/doc/samples/SqlConnection_BeginTransaction.cs +++ b/doc/samples/SqlConnection_BeginTransaction.cs @@ -67,4 +67,4 @@ private static void ExecuteSqlTransaction(string connectionString) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_BeginTransaction1.cs b/doc/samples/SqlConnection_BeginTransaction1.cs index 9148909d79..c7b7b6b651 100644 --- a/doc/samples/SqlConnection_BeginTransaction1.cs +++ b/doc/samples/SqlConnection_BeginTransaction1.cs @@ -62,4 +62,4 @@ private static void ExecuteSqlTransaction(string connectionString) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_BeginTransaction2.cs b/doc/samples/SqlConnection_BeginTransaction2.cs index f00ead429c..9665c33c12 100644 --- a/doc/samples/SqlConnection_BeginTransaction2.cs +++ b/doc/samples/SqlConnection_BeginTransaction2.cs @@ -67,4 +67,4 @@ private static void ExecuteSqlTransaction(string connectionString) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_BeginTransaction3.cs b/doc/samples/SqlConnection_BeginTransaction3.cs index ed4437f7c1..44eb020ff7 100644 --- a/doc/samples/SqlConnection_BeginTransaction3.cs +++ b/doc/samples/SqlConnection_BeginTransaction3.cs @@ -66,4 +66,4 @@ private static void ExecuteSqlTransaction(string connectionString) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_ConnectionString.cs b/doc/samples/SqlConnection_ConnectionString.cs index 996fb845a5..0b5ed5a00b 100644 --- a/doc/samples/SqlConnection_ConnectionString.cs +++ b/doc/samples/SqlConnection_ConnectionString.cs @@ -35,4 +35,4 @@ static private string GetConnectionString() + "Integrated Security=true;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_ConnectionString1.cs b/doc/samples/SqlConnection_ConnectionString1.cs index ee24b7c827..4af89c40da 100644 --- a/doc/samples/SqlConnection_ConnectionString1.cs +++ b/doc/samples/SqlConnection_ConnectionString1.cs @@ -50,7 +50,7 @@ private static void DemonstrateChangePassword() { // You must reset the password. connectionString = - ModifyConnectionString(connectionString, + ModifyConnectionString(connectionString, GetNewPassword()); } @@ -108,4 +108,4 @@ private static string GetConnectionString() return builder.ConnectionString; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_ConnectionTimeout.cs b/doc/samples/SqlConnection_ConnectionTimeout.cs index 9d0a64994f..0ad488ebde 100644 --- a/doc/samples/SqlConnection_ConnectionTimeout.cs +++ b/doc/samples/SqlConnection_ConnectionTimeout.cs @@ -32,4 +32,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;Connection Timeout=30"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_CreateCommand.cs b/doc/samples/SqlConnection_CreateCommand.cs index f8146a9917..0325c59058 100644 --- a/doc/samples/SqlConnection_CreateCommand.cs +++ b/doc/samples/SqlConnection_CreateCommand.cs @@ -1,15 +1,18 @@ using System.Data; // using Microsoft.Data.SqlClient; -public class A { - public static void Main() { - using (SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;")) { - connection.Open(); - SqlCommand command= connection.CreateCommand(); - command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"; - command.CommandTimeout = 15; - command.CommandType = CommandType.Text; - } - } +public class A +{ + public static void Main() + { + using (SqlConnection connection = new SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=SSPI;")) + { + connection.Open(); + SqlCommand command = connection.CreateCommand(); + command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"; + command.CommandTimeout = 15; + command.CommandType = CommandType.Text; + } + } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_DataSource.cs b/doc/samples/SqlConnection_DataSource.cs index c626b6e53e..779a5af14f 100644 --- a/doc/samples/SqlConnection_DataSource.cs +++ b/doc/samples/SqlConnection_DataSource.cs @@ -32,4 +32,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_Database.cs b/doc/samples/SqlConnection_Database.cs index bc9aec7ddc..4cedb11b22 100644 --- a/doc/samples/SqlConnection_Database.cs +++ b/doc/samples/SqlConnection_Database.cs @@ -37,4 +37,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_Open.cs b/doc/samples/SqlConnection_Open.cs index 8150eb2d39..932b17fe3f 100644 --- a/doc/samples/SqlConnection_Open.cs +++ b/doc/samples/SqlConnection_Open.cs @@ -32,4 +32,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_PacketSize.cs b/doc/samples/SqlConnection_PacketSize.cs index 160ad39685..7503818c30 100644 --- a/doc/samples/SqlConnection_PacketSize.cs +++ b/doc/samples/SqlConnection_PacketSize.cs @@ -31,4 +31,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;Packet Size=512"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_ServerVersion.cs b/doc/samples/SqlConnection_ServerVersion.cs index aed6aeb478..c057e63f56 100644 --- a/doc/samples/SqlConnection_ServerVersion.cs +++ b/doc/samples/SqlConnection_ServerVersion.cs @@ -20,9 +20,9 @@ private static void CreateSqlConnection(string connectionString) { connection.Open(); Console.WriteLine("ServerVersion: {0}", connection.ServerVersion); - Console.WriteLine("State: {0}", connection.State ); + Console.WriteLine("State: {0}", connection.State); } } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_SqlConnection.cs b/doc/samples/SqlConnection_SqlConnection.cs index decc295569..59e5587e5a 100644 --- a/doc/samples/SqlConnection_SqlConnection.cs +++ b/doc/samples/SqlConnection_SqlConnection.cs @@ -31,4 +31,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_SqlConnection1.cs b/doc/samples/SqlConnection_SqlConnection1.cs index c61438899f..19a9d5c5a5 100644 --- a/doc/samples/SqlConnection_SqlConnection1.cs +++ b/doc/samples/SqlConnection_SqlConnection1.cs @@ -34,4 +34,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlConnection_WorkstationId.cs b/doc/samples/SqlConnection_WorkstationId.cs index 1efc18d588..2edd6d878f 100644 --- a/doc/samples/SqlConnection_WorkstationId.cs +++ b/doc/samples/SqlConnection_WorkstationId.cs @@ -32,4 +32,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI;"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataAdapter.cs b/doc/samples/SqlDataAdapter.cs index 961ba545cf..aed3c92111 100644 --- a/doc/samples/SqlDataAdapter.cs +++ b/doc/samples/SqlDataAdapter.cs @@ -62,4 +62,4 @@ public static SqlDataAdapter CreateCustomerAdapter( return adapter; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataAdapter_RowUpdated.cs b/doc/samples/SqlDataAdapter_RowUpdated.cs index 7cbdb660f2..ea303f0e9d 100644 --- a/doc/samples/SqlDataAdapter_RowUpdated.cs +++ b/doc/samples/SqlDataAdapter_RowUpdated.cs @@ -6,72 +6,72 @@ using System.Data.Common; using System.Windows.Forms; -public class Form1: Form +public class Form1 : Form { private DataSet DataSet1; private DataGrid dataGrid1; // handler for RowUpdating event - private static void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e) + private static void OnRowUpdating(object sender, SqlRowUpdatingEventArgs e) { PrintEventArgs(e); } - + // handler for RowUpdated event - private static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs e) + private static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs e) { PrintEventArgs(e); } - - public static int Main() + + public static int Main() { - const string connectionString = + const string connectionString = "Integrated Security=SSPI;database=Northwind;server=MSSQL1"; const string queryString = "SELECT * FROMProducts"; - + // create DataAdapter SqlDataAdapter adapter = new SqlDataAdapter(queryString, connectionString); SqlCommandBuilder builder = new SqlCommandBuilder(adapter); - + // Create and fill DataSet (select only first 5 rows) DataSet dataSet = new DataSet(); adapter.Fill(dataSet, 0, 5, "Table"); - + // Modify DataSet DataTable table = dataSet.Tables["Table"]; table.Rows[0][1] = "new product"; - + // add handlers - adapter.RowUpdating += new SqlRowUpdatingEventHandler( OnRowUpdating ); - adapter.RowUpdated += new SqlRowUpdatedEventHandler( OnRowUpdated ); - + adapter.RowUpdating += new SqlRowUpdatingEventHandler(OnRowUpdating); + adapter.RowUpdated += new SqlRowUpdatedEventHandler(OnRowUpdated); + // update, this operation fires two events // (RowUpdating/RowUpdated) per changed row adapter.Update(dataSet, "Table"); - + // remove handlers - adapter.RowUpdating -= new SqlRowUpdatingEventHandler( OnRowUpdating ); - adapter.RowUpdated -= new SqlRowUpdatedEventHandler( OnRowUpdated ); + adapter.RowUpdating -= new SqlRowUpdatingEventHandler(OnRowUpdating); + adapter.RowUpdated -= new SqlRowUpdatedEventHandler(OnRowUpdated); return 0; } - - private static void PrintEventArgs(SqlRowUpdatingEventArgs args) + + private static void PrintEventArgs(SqlRowUpdatingEventArgs args) { Console.WriteLine("OnRowUpdating"); - Console.WriteLine(" event args: ("+ - " command=" + args.Command + - " commandType=" + args.StatementType + + Console.WriteLine(" event args: (" + + " command=" + args.Command + + " commandType=" + args.StatementType + " status=" + args.Status + ")"); } - - private static void PrintEventArgs(SqlRowUpdatedEventArgs args) + + private static void PrintEventArgs(SqlRowUpdatedEventArgs args) { Console.WriteLine("OnRowUpdated"); - Console.WriteLine( " event args: ("+ + Console.WriteLine(" event args: (" + " command=" + args.Command + - " commandType=" + args.StatementType + - " recordsAffected=" + args.RecordsAffected + + " commandType=" + args.StatementType + + " recordsAffected=" + args.RecordsAffected + " status=" + args.Status + ")"); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataAdapter_SelectCommand.cs b/doc/samples/SqlDataAdapter_SelectCommand.cs index 8532a06c2f..aecd1db331 100644 --- a/doc/samples/SqlDataAdapter_SelectCommand.cs +++ b/doc/samples/SqlDataAdapter_SelectCommand.cs @@ -25,4 +25,4 @@ private static DataSet SelectRows(DataSet dataset, } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataAdapter_SqlDataAdapter.cs b/doc/samples/SqlDataAdapter_SqlDataAdapter.cs index ff67e101f3..beb2486cbd 100644 --- a/doc/samples/SqlDataAdapter_SqlDataAdapter.cs +++ b/doc/samples/SqlDataAdapter_SqlDataAdapter.cs @@ -46,4 +46,4 @@ public static SqlDataAdapter CreateSqlDataAdapter(SqlConnection connection) return adapter; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataAdapter_SqlDataAdapter1.cs b/doc/samples/SqlDataAdapter_SqlDataAdapter1.cs index abac49f890..f8fd5a2015 100644 --- a/doc/samples/SqlDataAdapter_SqlDataAdapter1.cs +++ b/doc/samples/SqlDataAdapter_SqlDataAdapter1.cs @@ -27,22 +27,22 @@ public static SqlDataAdapter CreateSqlDataAdapter(SqlCommand selectCommand, "DELETE FROM Customers WHERE CustomerID = @CustomerID", connection); // Create the parameters. - adapter.InsertCommand.Parameters.Add("@CustomerID", + adapter.InsertCommand.Parameters.Add("@CustomerID", SqlDbType.Char, 5, "CustomerID"); - adapter.InsertCommand.Parameters.Add("@CompanyName", + adapter.InsertCommand.Parameters.Add("@CompanyName", SqlDbType.VarChar, 40, "CompanyName"); - adapter.UpdateCommand.Parameters.Add("@CustomerID", + adapter.UpdateCommand.Parameters.Add("@CustomerID", SqlDbType.Char, 5, "CustomerID"); - adapter.UpdateCommand.Parameters.Add("@CompanyName", + adapter.UpdateCommand.Parameters.Add("@CompanyName", SqlDbType.VarChar, 40, "CompanyName"); - adapter.UpdateCommand.Parameters.Add("@oldCustomerID", + adapter.UpdateCommand.Parameters.Add("@oldCustomerID", SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original; - adapter.DeleteCommand.Parameters.Add("@CustomerID", + adapter.DeleteCommand.Parameters.Add("@CustomerID", SqlDbType.Char, 5, "CustomerID").SourceVersion = DataRowVersion.Original; return adapter; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataAdapter_SqlDataAdapter2.cs b/doc/samples/SqlDataAdapter_SqlDataAdapter2.cs index dced33ff37..275dd4c02a 100644 --- a/doc/samples/SqlDataAdapter_SqlDataAdapter2.cs +++ b/doc/samples/SqlDataAdapter_SqlDataAdapter2.cs @@ -47,4 +47,4 @@ public static SqlDataAdapter CreateSqlDataAdapter(string commandText, return adapter; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataAdapter_SqlDataAdapter3.cs b/doc/samples/SqlDataAdapter_SqlDataAdapter3.cs index 33ff5161d0..721e9ef75b 100644 --- a/doc/samples/SqlDataAdapter_SqlDataAdapter3.cs +++ b/doc/samples/SqlDataAdapter_SqlDataAdapter3.cs @@ -46,4 +46,4 @@ public static SqlDataAdapter CreateSqlDataAdapter(string commandText, return adapter; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataReader_Close.cs b/doc/samples/SqlDataReader_Close.cs index c2499e5313..102fa6de85 100644 --- a/doc/samples/SqlDataReader_Close.cs +++ b/doc/samples/SqlDataReader_Close.cs @@ -40,4 +40,4 @@ private static void ReadOrderData(string connectionString) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataReader_GetOrdinal.cs b/doc/samples/SqlDataReader_GetOrdinal.cs index ae12f6bff2..ff69173616 100644 --- a/doc/samples/SqlDataReader_GetOrdinal.cs +++ b/doc/samples/SqlDataReader_GetOrdinal.cs @@ -38,4 +38,4 @@ private static void ReadGetOrdinal(string connectionString) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataReader_IsDBNull.cs b/doc/samples/SqlDataReader_IsDBNull.cs index 381b045661..903ac8f424 100644 --- a/doc/samples/SqlDataReader_IsDBNull.cs +++ b/doc/samples/SqlDataReader_IsDBNull.cs @@ -26,4 +26,4 @@ static void Main(string[] args) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlDataReader_Read.cs b/doc/samples/SqlDataReader_Read.cs index abecefe3c7..3a61b61cfd 100644 --- a/doc/samples/SqlDataReader_Read.cs +++ b/doc/samples/SqlDataReader_Read.cs @@ -43,4 +43,4 @@ private static void ReadSingleRow(IDataRecord record) } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlError_State.cs b/doc/samples/SqlError_State.cs index 7a79f8460e..f4f10738af 100644 --- a/doc/samples/SqlError_State.cs +++ b/doc/samples/SqlError_State.cs @@ -31,4 +31,4 @@ public void DisplaySqlErrors(SqlException exception) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlError_ToString.cs b/doc/samples/SqlError_ToString.cs index 2b7e8442e0..b6645049a2 100644 --- a/doc/samples/SqlError_ToString.cs +++ b/doc/samples/SqlError_ToString.cs @@ -49,4 +49,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlException_Errors1.cs b/doc/samples/SqlException_Errors1.cs index 470476bae6..30c54b08f2 100644 --- a/doc/samples/SqlException_Errors1.cs +++ b/doc/samples/SqlException_Errors1.cs @@ -48,4 +48,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlException_Errors2.cs b/doc/samples/SqlException_Errors2.cs index 125e7d3331..d72b6cd7c8 100644 --- a/doc/samples/SqlException_Errors2.cs +++ b/doc/samples/SqlException_Errors2.cs @@ -17,7 +17,7 @@ public static void ShowSqlException(string connectionString) { string queryString = "EXECUTE NonExistantStoredProcedure"; StringBuilder errorMessages = new StringBuilder(); - + using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = new SqlCommand(queryString, connection); @@ -50,4 +50,4 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameter.cs b/doc/samples/SqlParameter.cs index 4a8def986f..503f922349 100644 --- a/doc/samples/SqlParameter.cs +++ b/doc/samples/SqlParameter.cs @@ -88,4 +88,4 @@ static void CreateSqlParameterVersion() parameter.Value = "garden hose"; } // -} \ No newline at end of file +} diff --git a/doc/samples/SqlParameter_IsNullable.cs b/doc/samples/SqlParameter_IsNullable.cs index 518f4454eb..63f0e30401 100644 --- a/doc/samples/SqlParameter_IsNullable.cs +++ b/doc/samples/SqlParameter_IsNullable.cs @@ -30,4 +30,4 @@ private static void SetParameterToNull(IDataParameter parameter) } } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameter_ParameterName.cs b/doc/samples/SqlParameter_ParameterName.cs index 90c537def6..0796eb1c03 100644 --- a/doc/samples/SqlParameter_ParameterName.cs +++ b/doc/samples/SqlParameter_ParameterName.cs @@ -19,4 +19,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// \ No newline at end of file +// From 811ca5c26d5daef041554cbd91d2401cf0fa1ca2 Mon Sep 17 00:00:00 2001 From: Javad Date: Thu, 19 Sep 2019 14:51:23 -0700 Subject: [PATCH 4/9] Resolved issues. --- .../Microsoft.Data.SqlClient/ApplicationIntent.xml | 2 +- .../OnChangeEventHandler.xml | 2 +- .../PoolBlockingPeriod.xml | 2 +- .../Microsoft.Data.SqlClient/SQLDebugging.xml | 2 +- .../Microsoft.Data.SqlClient/SortOrder.xml | 2 +- .../SqlAuthenticationInitializer.xml | 2 +- .../SqlAuthenticationMethod.xml | 2 +- .../SqlAuthenticationParameters.xml | 2 +- .../SqlAuthenticationProvider.xml | 2 +- .../SqlAuthenticationToken.xml | 2 +- .../Microsoft.Data.SqlClient/SqlBulkCopy.xml | 2 +- .../SqlBulkCopyColumnMapping.xml | 2 +- .../SqlBulkCopyColumnMappingCollection.xml | 2 +- .../SqlBulkCopyOptions.xml | 10 +++++----- .../Microsoft.Data.SqlClient/SqlClientFactory.xml | 8 ++++---- .../Microsoft.Data.SqlClient/SqlClientLogger.xml | 2 +- .../SqlClientPermission.xml | 2 +- ...SqlColumnEncryptionCertificateStoreProvider.xml | 2 +- .../SqlColumnEncryptionCngProvider.xml | 8 ++++---- .../SqlColumnEncryptionCspProvider.xml | 2 +- .../SqlColumnEncryptionEnclaveProvider.xml | 2 +- .../SqlColumnEncryptionKeyStoreProvider.xml | 2 +- .../SqlCommand.SqlCommand2.cs | 2 +- .../Microsoft.Data.SqlClient/SqlCommand.xml | 2 +- .../Microsoft.Data.SqlClient/SqlCommandBuilder.xml | 14 +++++++------- .../Microsoft.Data.SqlClient/SqlParameter.xml | 2 +- .../src/Microsoft/Data/SqlClient/SqlCommand.cs | 9 ++++++++- .../src/Microsoft/Data/SqlClient/SqlConnection.cs | 2 +- 28 files changed, 51 insertions(+), 44 deletions(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/ApplicationIntent.xml b/doc/snippets/Microsoft.Data.SqlClient/ApplicationIntent.xml index 03de187fba..e4c32bb13d 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/ApplicationIntent.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/ApplicationIntent.xml @@ -17,4 +17,4 @@ 1 - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/OnChangeEventHandler.xml b/doc/snippets/Microsoft.Data.SqlClient/OnChangeEventHandler.xml index 66b64dee02..08ec017f90 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/OnChangeEventHandler.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/OnChangeEventHandler.xml @@ -14,4 +14,4 @@ - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml b/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml index 9da432467f..43f4046304 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/PoolBlockingPeriod.xml @@ -17,4 +17,4 @@ 2 - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml b/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml index c36ca88904..eb3a6e17ec 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SQLDebugging.xml @@ -7,4 +7,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SortOrder.xml b/doc/snippets/Microsoft.Data.SqlClient/SortOrder.xml index 0a80576703..7a6def3284 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SortOrder.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SortOrder.xml @@ -22,4 +22,4 @@ 1 - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml index 36a71053f7..969253b07f 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationInitializer.xml @@ -8,4 +8,4 @@ When overridden in a derived class, initializes the authentication initializer. This method is called by the constructor during startup. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml index da1c60cdc9..075ad38ec3 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationMethod.xml @@ -26,4 +26,4 @@ 4 - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml index 2b2820ca96..25541cf9be 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationParameters.xml @@ -57,4 +57,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml index f8c5094733..623b042c27 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationProvider.xml @@ -43,4 +43,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml index 088628fe6b..fcccd84837 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlAuthenticationToken.xml @@ -22,4 +22,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml index 19556eb2cb..73f56c69e2 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml @@ -846,4 +846,4 @@ - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml index 7a9d8d515d..21609560df 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml @@ -261,4 +261,4 @@ - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMappingCollection.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMappingCollection.xml index 01927b7276..530f21853e 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMappingCollection.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMappingCollection.xml @@ -324,4 +324,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyOptions.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyOptions.xml index 243e1f80dd..e7c6a723d2 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyOptions.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyOptions.xml @@ -1,13 +1,13 @@ - Bitwise flag that specifies one or more options to use with an instance of . + Bitwise flag that specifies one or more options to use with an instance of . enumeration when you construct a instance to change how the - methods for that instance behave. + You can use the enumeration when you construct a instance to change how the + methods for that instance behave. @@ -58,9 +58,9 @@ Obtain a bulk update lock for the duration of the bulk copy operation. When not specified, row locks are used. - When specified, each batch of the bulk-copy operation will occur within a transaction. If you indicate this option and also provide a + When specified, each batch of the bulk-copy operation will occur within a transaction. If you indicate this option and also provide a object to the constructor, an occurs. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml index b48d89c832..8979d43ad5 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml @@ -45,13 +45,13 @@ - Returns a strongly typed instance. - A new strongly typed instance of . + Returns a strongly typed instance. + A new strongly typed instance of . instance: + The following code fragment returns a strongly typed instance: ```csharp @@ -173,4 +173,4 @@ - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml index 27a134c954..229f5eee58 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientLogger.xml @@ -38,4 +38,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml index 799ae14b10..3e10e8920b 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientPermission.xml @@ -83,4 +83,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml index bf122d38e6..4755878cd0 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCertificateStoreProvider.xml @@ -51,4 +51,4 @@ - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml index 5a193981c0..3c2f528166 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCngProvider.xml @@ -14,7 +14,7 @@ - Initializes a new instance of the class. + Initializes a new instance of the class. To be added. @@ -48,8 +48,8 @@ method must be implemented by the corresponding key store providers. - should use an asymmetric key identified by a key path and sign the masterkey metadata consisting + The method must be implemented by the corresponding key store providers. + should use an asymmetric key identified by a key path and sign the masterkey metadata consisting of `masterKeyPath`, `allowEnclaveComputations`, and providerName. ]]> @@ -64,4 +64,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml index 77b18ae303..0538ceeccb 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionCspProvider.xml @@ -65,4 +65,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml index 1b81cd8bfa..09cad1d58a 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionEnclaveProvider.xml @@ -51,4 +51,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml index 4b788afbf2..1f08b6ef7c 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlColumnEncryptionKeyStoreProvider.xml @@ -60,4 +60,4 @@ To be added. - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs index 64460318f3..9315817979 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs @@ -37,4 +37,4 @@ private static void CreateCommand(string queryString, } // } -} \ No newline at end of file +} diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml index a4a5c33e16..1e563ab7e5 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml @@ -1897,4 +1897,4 @@ - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml index c7a0738e02..29ad8377c8 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml @@ -7,22 +7,22 @@ does not automatically generate the Transact-SQL statements required to reconcile changes made to a with the associated instance of SQL Server. However, you can create a object to automatically generate Transact-SQL statements for single-table updates if you set the property of the . Then, any additional Transact-SQL statements that you do not set are generated by the . + The does not automatically generate the Transact-SQL statements required to reconcile changes made to a with the associated instance of SQL Server. However, you can create a object to automatically generate Transact-SQL statements for single-table updates if you set the property of the . Then, any additional Transact-SQL statements that you do not set are generated by the . - The registers itself as a listener for events whenever you set the property. You can only associate one or object with each other at one time. + The registers itself as a listener for events whenever you set the property. You can only associate one or object with each other at one time. - To generate INSERT, UPDATE, or DELETE statements, the uses the property to retrieve a required set of metadata automatically. If you change the after the metadata has been retrieved, such as after the first update, you should call the method to update the metadata. + To generate INSERT, UPDATE, or DELETE statements, the uses the property to retrieve a required set of metadata automatically. If you change the after the metadata has been retrieved, such as after the first update, you should call the method to update the metadata. The `SelectCommand` must also return at least one primary key or unique column. If none are present, an **InvalidOperation** exception is generated, and the commands are not generated. - The also uses the , , and properties referenced by the . The user should call if one or more of these properties are modified, or if the itself is replaced. Otherwise the , , and properties retain their previous values. + The also uses the , , and properties referenced by the . The user should call if one or more of these properties are modified, or if the itself is replaced. Otherwise the , , and properties retain their previous values. - If you call , the is disassociated from the , and the generated commands are no longer used. + If you call , the is disassociated from the , and the generated commands are no longer used. ## Examples - The following example uses the , along and , to select rows from a data source. The example is passed a connection string, a query string that is a Transact-SQL SELECT statement, and a string that is the name of the database table. The example then creates a . + The following example uses the , along and , to select rows from a data source. The example is passed a connection string, a query string that is a Transact-SQL SELECT statement, and a string that is the name of the database table. The example then creates a . [!code-csharp[Classic WebData SqlCommandBuilder#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommandBuilder/CS/Source.cs#1)] @@ -34,4 +34,4 @@ - \ No newline at end of file + diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlParameter.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlParameter.xml index bd89b57a58..ecf9cc20f9 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlParameter.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlParameter.xml @@ -471,7 +471,7 @@ static void CreateSqlParameterLocaleId(){ ## Remarks is used by the to correctly generate update commands when dealing with nullable columns. Generally, use of is limited to developers inheriting from . - uses this property to determine whether the source column is nullable, and sets this property to `true` if it is nullable, and `false` if it is not. When is generating its Update statement, it examines the for each parameter. If the property is `true`, generates a WHERE clauses like the following (in this query expression, "FieldName" represents the name of the field): + uses this property to determine whether the source column is nullable, and sets this property to `true` if it is nullable, and `false` if it is not. When is generating its Update statement, it examines the for each parameter. If the property is `true`, generates a WHERE clauses like the following (in this query expression, "FieldName" represents the name of the field): ``` ((@IsNull_FieldName = 1 AND FieldName IS NULL) OR diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs index bb0b087780..e9026169da 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -4399,7 +4399,14 @@ private SqlParameter GetSqlParameterWithQueryText(string queryText) return sqlParam; } - + /// + /// Constructs the sp_describe_parameter_encryption request with the values from the original RPC call. + /// Prototype for is + /// exec sp_describe_parameter_encryption @tsql=N'[SQL Statement]', @params=N'@p1 varbinary(256)' + /// + /// + /// + /// private void PrepareDescribeParameterEncryptionRequest(_SqlRPC originalRpcRequest, ref _SqlRPC describeParameterEncryptionRequest, byte[] attestationParameters = null) { Debug.Assert(originalRpcRequest != null); diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs index dbbea38502..1c9feb4e3b 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnection.cs @@ -2475,7 +2475,7 @@ public static void ChangePassword(string connectionString, string newPassword) } } - /// + /// public static void ChangePassword(string connectionString, SqlCredential credential, SecureString newSecurePassword) { IntPtr hscp; From 0cea9982a5965c6b68dd9debd95054f1b4507e3a Mon Sep 17 00:00:00 2001 From: Javad Date: Thu, 19 Sep 2019 14:54:11 -0700 Subject: [PATCH 5/9] move sample class to correct location --- doc/samples/SqlCommand.SqlCommand2.cs | 39 +++++++++++++++++++ .../SqlCommand.SqlCommand2.cs | 6 +-- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 doc/samples/SqlCommand.SqlCommand2.cs diff --git a/doc/samples/SqlCommand.SqlCommand2.cs b/doc/samples/SqlCommand.SqlCommand2.cs new file mode 100644 index 0000000000..f564bc909f --- /dev/null +++ b/doc/samples/SqlCommand.SqlCommand2.cs @@ -0,0 +1,39 @@ +// +using System; +using System.Data; +using Microsoft.Data.SqlClient; + + +namespace SqlCommandCS +{ + class Program + { + static void Main() + { + string str = "Data Source=(local);Initial Catalog=Northwind;" + + "Integrated Security=SSPI"; + string qs = "SELECT OrderID, CustomerID FROM dbo.Orders;"; + CreateCommand(qs, str); + + } + + private static void CreateCommand(string queryString, + string connectionString) + { + using (SqlConnection connection = new SqlConnection( + connectionString)) + { + SqlCommand command = new SqlCommand( + queryString, connection); + connection.Open(); + SqlDataReader reader = command.ExecuteReader(); + while (reader.Read()) + { + Console.WriteLine(String.Format("{0}, {1}", + reader[0], reader[1])); + } + } + } + // + } +} diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs index 9315817979..e57fb938e4 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.SqlCommand2.cs @@ -1,5 +1,4 @@ - - +// using System; using System.Data; using Microsoft.Data.SqlClient; @@ -17,7 +16,7 @@ static void Main() CreateCommand(qs, str); } - // + private static void CreateCommand(string queryString, string connectionString) { @@ -38,3 +37,4 @@ private static void CreateCommand(string queryString, // } } + From c86e27853b2c2a67094cc3f0872475be507d358f Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 20 Sep 2019 10:10:36 -0700 Subject: [PATCH 6/9] adding missing samples --- doc/samples/SqlBulkCopy_ColumnMapping.cs | 4 +- ...BulkCopy_ColumnMappingDestinationColumn.cs | 95 ++++++++++++++ ...ulkCopy_ColumnMappingDestinationOrdinal.cs | 95 ++++++++++++++ .../SqlBulkCopy_ColumnMappingNameOrdinal.cs | 92 +++++++++++++ .../SqlBulkCopy_ColumnMappingOrdinal.cs | 92 +++++++++++++ .../SqlBulkCopy_ColumnMappingOrdinalName.cs | 92 +++++++++++++ doc/samples/SqlBulkCopy_ConnectionString.cs | 81 ++++++++++++ doc/samples/SqlBulkCopy_DataRowState.cs | 122 ++++++++++++++++++ doc/samples/SqlBulkCopy_NotifyAfter.cs | 91 +++++++++++++ doc/samples/SqlBulkCopy_Timeout.cs | 84 ++++++++++++ doc/samples/SqlCommand.cs | 41 ++++++ doc/samples/SqlCommandBuilder.cs | 45 +++++++ doc/samples/SqlCommand_ExecuteScalar.cs | 20 +++ doc/samples/SqlCommand_Prepare.cs | 48 +++++++ .../SqlParameterCollection_AddWithValue.cs | 4 +- .../Microsoft.Data.SqlClient/SqlBulkCopy.xml | 14 +- .../SqlBulkCopyColumnMapping.xml | 17 ++- .../SqlClientFactory.xml | 2 +- .../Microsoft.Data.SqlClient/SqlCommand.xml | 14 +- .../SqlCommandBuilder.xml | 2 +- 20 files changed, 1025 insertions(+), 30 deletions(-) create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingDestinationColumn.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingDestinationOrdinal.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingNameOrdinal.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingOrdinal.cs create mode 100644 doc/samples/SqlBulkCopy_ColumnMappingOrdinalName.cs create mode 100644 doc/samples/SqlBulkCopy_ConnectionString.cs create mode 100644 doc/samples/SqlBulkCopy_DataRowState.cs create mode 100644 doc/samples/SqlBulkCopy_NotifyAfter.cs create mode 100644 doc/samples/SqlBulkCopy_Timeout.cs create mode 100644 doc/samples/SqlCommand.cs create mode 100644 doc/samples/SqlCommandBuilder.cs create mode 100644 doc/samples/SqlCommand_ExecuteScalar.cs create mode 100644 doc/samples/SqlCommand_Prepare.cs diff --git a/doc/samples/SqlBulkCopy_ColumnMapping.cs b/doc/samples/SqlBulkCopy_ColumnMapping.cs index 0578f13d02..aef26274cd 100644 --- a/doc/samples/SqlBulkCopy_ColumnMapping.cs +++ b/doc/samples/SqlBulkCopy_ColumnMapping.cs @@ -1,7 +1,7 @@ -// using System; using System.Data; -using Microsoft..Data.SqlClient; +// +using Microsoft.Data.SqlClient; class Program { diff --git a/doc/samples/SqlBulkCopy_ColumnMappingDestinationColumn.cs b/doc/samples/SqlBulkCopy_ColumnMappingDestinationColumn.cs new file mode 100644 index 0000000000..d46a58a261 --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingDestinationColumn.cs @@ -0,0 +1,95 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // Set up the column mappings source and destination. + SqlBulkCopyColumnMapping mapID = new SqlBulkCopyColumnMapping(); + mapID.SourceColumn = "ProductID"; + mapID.DestinationColumn = "ProdID"; + bulkCopy.ColumnMappings.Add(mapID); + + SqlBulkCopyColumnMapping mapName = new SqlBulkCopyColumnMapping(); + mapName.SourceColumn = "Name"; + mapName.DestinationColumn = "ProdName"; + bulkCopy.ColumnMappings.Add(mapName); + + SqlBulkCopyColumnMapping mapNumber = new SqlBulkCopyColumnMapping(); + mapNumber.SourceColumn = "ProductNumber"; + mapNumber.DestinationColumn = "ProdNum"; + bulkCopy.ColumnMappings.Add(mapNumber); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingDestinationOrdinal.cs b/doc/samples/SqlBulkCopy_ColumnMappingDestinationOrdinal.cs new file mode 100644 index 0000000000..19e31f282d --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingDestinationOrdinal.cs @@ -0,0 +1,95 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // Set up the column mappings source and destination. + SqlBulkCopyColumnMapping mapID = new SqlBulkCopyColumnMapping(); + mapID.SourceOrdinal = 0; + mapID.DestinationOrdinal = 0; + bulkCopy.ColumnMappings.Add(mapID); + + SqlBulkCopyColumnMapping mapName = new SqlBulkCopyColumnMapping(); + mapName.SourceOrdinal = 1; + mapName.DestinationOrdinal = 2; + bulkCopy.ColumnMappings.Add(mapName); + + SqlBulkCopyColumnMapping mapNumber = new SqlBulkCopyColumnMapping(); + mapNumber.SourceOrdinal = 2; + mapNumber.DestinationOrdinal = 1; + bulkCopy.ColumnMappings.Add(mapNumber); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingNameOrdinal.cs b/doc/samples/SqlBulkCopy_ColumnMappingNameOrdinal.cs new file mode 100644 index 0000000000..bdda864974 --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingNameOrdinal.cs @@ -0,0 +1,92 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // Set up the column mappings by name and ordinal. + SqlBulkCopyColumnMapping columnMapID = + new SqlBulkCopyColumnMapping("ProductID", 0); + bulkCopy.ColumnMappings.Add(columnMapID); + + SqlBulkCopyColumnMapping columnMapName = + new SqlBulkCopyColumnMapping("Name", 2); + bulkCopy.ColumnMappings.Add(columnMapName); + + SqlBulkCopyColumnMapping columnMapNumber = + new SqlBulkCopyColumnMapping("ProductNumber", 1); + bulkCopy.ColumnMappings.Add(columnMapNumber); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingOrdinal.cs b/doc/samples/SqlBulkCopy_ColumnMappingOrdinal.cs new file mode 100644 index 0000000000..671383133f --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingOrdinal.cs @@ -0,0 +1,92 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // Set up the column mappings by ordinal. + SqlBulkCopyColumnMapping columnMapID = + new SqlBulkCopyColumnMapping(0, 0); + bulkCopy.ColumnMappings.Add(columnMapID); + + SqlBulkCopyColumnMapping columnMapName = + new SqlBulkCopyColumnMapping(1, 2); + bulkCopy.ColumnMappings.Add(columnMapName); + + SqlBulkCopyColumnMapping columnMapNumber = + new SqlBulkCopyColumnMapping(2, 1); + bulkCopy.ColumnMappings.Add(columnMapNumber); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_ColumnMappingOrdinalName.cs b/doc/samples/SqlBulkCopy_ColumnMappingOrdinalName.cs new file mode 100644 index 0000000000..8ca91ee00e --- /dev/null +++ b/doc/samples/SqlBulkCopy_ColumnMappingOrdinalName.cs @@ -0,0 +1,92 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoDifferentColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoDifferentColumns"; + + // Set up the column mappings by ordinal and name. + SqlBulkCopyColumnMapping columnMapID = + new SqlBulkCopyColumnMapping(0, "ProdID"); + bulkCopy.ColumnMappings.Add(columnMapID); + + SqlBulkCopyColumnMapping columnMapName = + new SqlBulkCopyColumnMapping(1, "ProdName"); + bulkCopy.ColumnMappings.Add(columnMapName); + + SqlBulkCopyColumnMapping columnMapNumber = + new SqlBulkCopyColumnMapping(2, "ProdNum"); + bulkCopy.ColumnMappings.Add(columnMapNumber); + + // Write from the source to the destination. + try + { + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_ConnectionString.cs b/doc/samples/SqlBulkCopy_ConnectionString.cs new file mode 100644 index 0000000000..50c3101369 --- /dev/null +++ b/doc/samples/SqlBulkCopy_ConnectionString.cs @@ -0,0 +1,81 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoMatchingColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Set up the bulk copy object using a connection string. + // In the real world you would not use SqlBulkCopy to move + // data from one table to the other in the same database. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoMatchingColumns"; + + try + { + // Write from the source to the destination. + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_DataRowState.cs b/doc/samples/SqlBulkCopy_DataRowState.cs new file mode 100644 index 0000000000..6e36e6a3e1 --- /dev/null +++ b/doc/samples/SqlBulkCopy_DataRowState.cs @@ -0,0 +1,122 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a connection to the AdventureWorks database. + using (SqlConnection connection = + new SqlConnection(connectionString)) + { + connection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoMatchingColumns;", + connection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Create a table with some rows. + DataTable newProducts = MakeTable(); + + // Make a change to one of the rows in the DataTable. + DataRow row = newProducts.Rows[0]; + row.BeginEdit(); + row["Name"] = "AAA"; + row.EndEdit(); + + // Create the SqlBulkCopy object. + // Note that the column positions in the source DataTable + // match the column positions in the destination table so + // there is no need to map columns. + using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoMatchingColumns"; + + try + { + // Write unchanged rows from the source to the destination. + bulkCopy.WriteToServer(newProducts, DataRowState.Unchanged); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static DataTable MakeTable() + // Create a new DataTable named NewProducts. + { + DataTable newProducts = new DataTable("NewProducts"); + + // Add three column objects to the table. + DataColumn productID = new DataColumn(); + productID.DataType = System.Type.GetType("System.Int32"); + productID.ColumnName = "ProductID"; + productID.AutoIncrement = true; + newProducts.Columns.Add(productID); + + DataColumn productName = new DataColumn(); + productName.DataType = System.Type.GetType("System.String"); + productName.ColumnName = "Name"; + newProducts.Columns.Add(productName); + + DataColumn productNumber = new DataColumn(); + productNumber.DataType = System.Type.GetType("System.String"); + productNumber.ColumnName = "ProductNumber"; + newProducts.Columns.Add(productNumber); + + // Create an array for DataColumn objects. + DataColumn[] keys = new DataColumn[1]; + keys[0] = productID; + newProducts.PrimaryKey = keys; + + // Add some new rows to the collection. + DataRow row = newProducts.NewRow(); + row["Name"] = "CC-101-WH"; + row["ProductNumber"] = "Cyclocomputer - White"; + + newProducts.Rows.Add(row); + row = newProducts.NewRow(); + row["Name"] = "CC-101-BK"; + row["ProductNumber"] = "Cyclocomputer - Black"; + + newProducts.Rows.Add(row); + row = newProducts.NewRow(); + row["Name"] = "CC-101-ST"; + row["ProductNumber"] = "Cyclocomputer - Stainless"; + newProducts.Rows.Add(row); + newProducts.AcceptChanges(); + + // Return the new DataTable. + return newProducts; + } + private static string GetConnectionString() + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_NotifyAfter.cs b/doc/samples/SqlBulkCopy_NotifyAfter.cs new file mode 100644 index 0000000000..bf64c6f69c --- /dev/null +++ b/doc/samples/SqlBulkCopy_NotifyAfter.cs @@ -0,0 +1,91 @@ +using System; +using System.Data; +// +using Microsoft..Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoMatchingColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("NotifyAfter Sample"); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Create the SqlBulkCopy object using a connection string. + // In the real world you would not use SqlBulkCopy to move + // data from one table to the other in the same database. + using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoMatchingColumns"; + + // Set up the event handler to notify after 50 rows. + bulkCopy.SqlRowsCopied += + new SqlRowsCopiedEventHandler(OnSqlRowsCopied); + bulkCopy.NotifyAfter = 50; + + try + { + // Write from the source to the destination. + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static void OnSqlRowsCopied( + object sender, SqlRowsCopiedEventArgs e) + { + Console.WriteLine("Copied {0} so far...", e.RowsCopied); + } + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_Timeout.cs b/doc/samples/SqlBulkCopy_Timeout.cs new file mode 100644 index 0000000000..b684e6879d --- /dev/null +++ b/doc/samples/SqlBulkCopy_Timeout.cs @@ -0,0 +1,84 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + + // Open a sourceConnection to the AdventureWorks database. + using (SqlConnection sourceConnection = + new SqlConnection(connectionString)) + { + sourceConnection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoMatchingColumns;", + sourceConnection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Get data from the source table as a SqlDataReader. + SqlCommand commandSourceData = new SqlCommand( + "SELECT ProductID, Name, " + + "ProductNumber " + + "FROM Production.Product;", sourceConnection); + SqlDataReader reader = + commandSourceData.ExecuteReader(); + + // Create the SqlBulkCopy object using a connection string. + // In the real world you would not use SqlBulkCopy to move + // data from one table to the other in the same database. + using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoMatchingColumns"; + + // Set the timeout. + bulkCopy.BulkCopyTimeout = 60; + + try + { + // Write from the source to the destination. + bulkCopy.WriteToServer(reader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + // Close the SqlDataReader. The SqlBulkCopy + // object is automatically closed at the end + // of the using block. + reader.Close(); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static string GetConnectionString() + // To avoid storing the sourceConnection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlCommand.cs b/doc/samples/SqlCommand.cs new file mode 100644 index 0000000000..abce0fab23 --- /dev/null +++ b/doc/samples/SqlCommand.cs @@ -0,0 +1,41 @@ +// +using System; +using System.Data; +using Microsoft.Data.SqlClient; + + +namespace SqlCommandCS +{ + class Program + { + static void Main() + { + string str = "Data Source=(local);Initial Catalog=Northwind;" + + "Integrated Security=SSPI"; + ReadOrderData(str); + + } + + private static void ReadOrderData(string connectionString) + { + string queryString = + "SELECT OrderID, CustomerID FROM dbo.Orders;"; + using (SqlConnection connection = new SqlConnection( + connectionString)) + { + SqlCommand command = new SqlCommand( + queryString, connection); + connection.Open(); + using (SqlDataReader reader = command.ExecuteReader()) + { + while (reader.Read()) + { + Console.WriteLine(String.Format("{0}, {1}", + reader[0], reader[1])); + } + } + } + } + // + } +} diff --git a/doc/samples/SqlCommandBuilder.cs b/doc/samples/SqlCommandBuilder.cs new file mode 100644 index 0000000000..bdde15518e --- /dev/null +++ b/doc/samples/SqlCommandBuilder.cs @@ -0,0 +1,45 @@ +// +using System; +using System.Data; +using Microsoft.Data.SqlClient; + +namespace SqlCommandBuilderCS +{ + class Program + { + static void Main() + { + string cnnst = ""; + string queryst = ""; + string tablen = ""; + DataSet ds = SelectSqlRows(cnnst, queryst, tablen); + + } + + public static DataSet SelectSqlRows(string connectionString, + string queryString, string tableName) + { + using (SqlConnection connection = new SqlConnection(connectionString)) + { + SqlDataAdapter adapter = new SqlDataAdapter(); + adapter.SelectCommand = new SqlCommand(queryString, connection); + SqlCommandBuilder builder = new SqlCommandBuilder(adapter); + + connection.Open(); + + DataSet dataSet = new DataSet(); + adapter.Fill(dataSet, tableName); + + //code to modify data in DataSet here + + builder.GetUpdateCommand(); + + //Without the SqlCommandBuilder this line would fail + adapter.Update(dataSet, tableName); + + return dataSet; + } + } + // + } +} diff --git a/doc/samples/SqlCommand_ExecuteScalar.cs b/doc/samples/SqlCommand_ExecuteScalar.cs new file mode 100644 index 0000000000..a6d81b71ef --- /dev/null +++ b/doc/samples/SqlCommand_ExecuteScalar.cs @@ -0,0 +1,20 @@ +// +using System; +using System.Data; +using Microsoft.Data.SqlClient; + +public class Sample +{ + + public void CreateSqlCommand( + string queryString, SqlConnection connection) + { + SqlCommand command = new + SqlCommand(queryString, connection); + command.Connection.Open(); + command.ExecuteScalar(); + connection.Close(); + } + // + +} diff --git a/doc/samples/SqlCommand_Prepare.cs b/doc/samples/SqlCommand_Prepare.cs new file mode 100644 index 0000000000..6812494a7f --- /dev/null +++ b/doc/samples/SqlCommand_Prepare.cs @@ -0,0 +1,48 @@ +// +using System; +using System.Data; +using Microsoft.Data.SqlClient; + +namespace SqlPrepareCS +{ + class Program + { + static void Main() + { + string connectionString = "Persist Security Info=False;Integrated Security=SSPI;database=Northwind;server=(local)"; + SqlCommandPrepareEx(connectionString); + Console.ReadLine(); + + } + private static void SqlCommandPrepareEx(string connectionString) + { + using (SqlConnection connection = new SqlConnection(connectionString)) + { + connection.Open(); + SqlCommand command = new SqlCommand(null, connection); + + // Create and prepare an SQL statement. + command.CommandText = + "INSERT INTO Region (RegionID, RegionDescription) " + + "VALUES (@id, @desc)"; + SqlParameter idParam = new SqlParameter("@id", SqlDbType.Int, 0); + SqlParameter descParam = + new SqlParameter("@desc", SqlDbType.Text, 100); + idParam.Value = 20; + descParam.Value = "First Region"; + command.Parameters.Add(idParam); + command.Parameters.Add(descParam); + + // Call Prepare after setting the Commandtext and Parameters. + command.Prepare(); + command.ExecuteNonQuery(); + + // Change parameter values and call ExecuteNonQuery. + command.Parameters[0].Value = 21; + command.Parameters[1].Value = "Second Region"; + command.ExecuteNonQuery(); + } + } + // + } +} diff --git a/doc/samples/SqlParameterCollection_AddWithValue.cs b/doc/samples/SqlParameterCollection_AddWithValue.cs index 1864e3d98c..1b836967c2 100644 --- a/doc/samples/SqlParameterCollection_AddWithValue.cs +++ b/doc/samples/SqlParameterCollection_AddWithValue.cs @@ -1,8 +1,9 @@ +// using System; using System.Data; -// using Microsoft.Data.SqlClient; + class Program { static void Main() @@ -52,4 +53,3 @@ static private string GetConnectionString() + "Integrated Security=SSPI"; } } -// \ No newline at end of file diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml index 73f56c69e2..7226a73218 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml @@ -181,7 +181,7 @@ to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.KeepIdentity#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.KeepIdentity/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.KeepIdentity#1](~/sqlClient/ SqlBulkCopy.KeepIdentity/CS/source.cs#1)] ]]> @@ -244,7 +244,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a [!INCLUDE[tsql](~/includes/tsql-md.md)]`INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.Timeout#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.Timeout/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.Timeout#1](~/sqlClient/doc/snippets/ SqlBulkCopy.Timeout/CS/source.cs#1)] ]]> @@ -342,7 +342,7 @@ demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.NotifyAfter#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.NotifyAfter/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.NotifyAfter#1](~/sqlClient/doc/snippets/ SqlBulkCopyNotifyAfter/CS/source.cs#1)] ]]> @@ -383,7 +383,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.NotifyAfter#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.NotifyAfter/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.NotifyAfter#1](~/sqlClient/doc/snippets/ SqlBulkCopy_NotifyAfter.cs)] ]]> @@ -447,7 +447,7 @@ to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ConnectionString#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ConnectionString/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.ConnectionString](~/sqlClient/doc/snippets/ SqlBulkCopy_ConnectionString.cs)] ]]> @@ -485,7 +485,7 @@ [!IMPORTANT] This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.DataRowState#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.DataRowState/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.DataRowState#1](~/sqlClient/doc/snippets/ SqlBulkCopy.DataRowState/CS/source.cs#1)] ]]> @@ -520,7 +520,7 @@ [!IMPORTANT] This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](~/docs/framework/data/adonet/sql/bulk-copy-example-setup.md). This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.DataRowState#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.DataRowState/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.DataRowState](~/sqlClient/doc/snippets/ SqlBulkCopy.DataRowState/CS/source.cs)] ]]> diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml index 21609560df..cddc42d37d 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopyColumnMapping.xml @@ -30,7 +30,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ColumnMapping#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMapping/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.ColumnMapping#1](~/sqlClient/doc/samples/ SqlBulkCopy.ColumnMapping/CS/source.cs)] ]]> @@ -57,7 +57,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ColumnMapping#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMapping/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.ColumnMapping#1](~/sqlClient/doc/samples/ SqlBulkCopy_ColumnMapping.cs)] ]]> @@ -79,8 +79,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingOrdinal#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingOrdinal/CS/source.cs#1)] - [!code-vb[DataWorks SqlBulkCopy.ColumnMappingOrdinal#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingOrdinal/VB/source.vb#1)] + [!code-csharp[SqlBulkCopy.ColumnMappingOrdinal#1](~/sqlClient/doc/snippets/ SqlBulkCopy-ColumnMappingOrdinal.cs)] ]]> @@ -103,7 +102,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingOrdinalName#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingOrdinalName/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.ColumnMappingOrdinalName#1](~/sqlClient/doc/snippets SqlBulkCopy.ColumnMappingOrdinalName.cs)] ]]> @@ -125,7 +124,7 @@ provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingNameOrdinal#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingNameOrdinal/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.ColumnMappingNameOrdinal#1](~/sqlClient/doc/snippets SqlBulkCopy.ColumnMappingNameOrdinal/CS/source.cs#1)] ]]> @@ -147,7 +146,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ColumnMapping#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMapping/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.ColumnMapping#1](~/sqlClient/doc/snippets SqlBulkCopy.ColumnMapping/CS/source.cs#1)] ]]> @@ -174,7 +173,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingDestinationColumn#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingDestinationColumn/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.ColumnMappingDestinationColumn#1](~/sqlClient/doc/snippets SqlBulkCopy.ColumnMappingDestinationColumn/CS/source.cs#1)] ]]> @@ -201,7 +200,7 @@ This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. - [!code-csharp[DataWorks SqlBulkCopy.ColumnMappingDestinationOrdinal#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlBulkCopy.ColumnMappingDestinationOrdinal/CS/source.cs#1)] + [!code-csharp[SqlBulkCopy.ColumnMappingDestinationOrdinal#1](~/sqlClient/doc/snippets SqlBulkCopy_ColumnMappingDestinationOrdinal.cs#1)] ]]> diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml index 8979d43ad5..09d2c1d6b0 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlClientFactory.xml @@ -21,7 +21,7 @@ ## Examples The following example displays a list of all available SQL Server data sources, using code that could enumerate data sources for any provider. - [!code-csharp[DataWorks SqlClientFactory_DataSourceEnumerator#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlClientFactory_DataSourceEnumerator/CS/source.cs#1)] + [!code-csharp[SqlClientFactory_DataSourceEnumerator](~/sqlClient/doc/samples/ SqlClientFactory_DataSourceEnumerator.cs)] ]]> diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml index 1e563ab7e5..100f395f20 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommand.xml @@ -32,7 +32,7 @@ ## Examples The following example creates a , a , and a . The example reads through the data, writing it to the console. Finally, the example closes the and then the as it exits the `Using` code blocks. - [!code-csharp[Classic WebData SqlCommand Example#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand Example/CS/source.cs#1)] + [!code-csharp[SqlCommand Example](~/sqlClient/doc/snippets SqlCommand.cs)] The following sample shows how to create and execute different types of SqlCommand objects. @@ -380,7 +380,7 @@ ## Examples The following example creates a and sets the `CommandTimeout` property. - [!code-csharp[Classic WebData IDbCommand_CommandTimeout.cs](~/sqlClient/doc/samples/ IDbCommand_CommandTimeout.cs)] + [!code-csharp[IDbCommand_CommandTimeout.cs](~/sqlClient/doc/samples/ IDbCommand_CommandTimeout.cs)] ]]> @@ -1570,8 +1570,7 @@ ## Examples The following example creates a and then executes it using . The example is passed a string representing a new value to be inserted into a table, and a string to use to connect to the data source. The function returns the new **Identity** column value if a new row was inserted, 0 on failure. - [!code-csharp[DataWorks SqlCommand.ExecuteScalar#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlCommand.ExecuteScalar/CS/source.cs#1)] - [!code-vb[DataWorks SqlCommand.ExecuteScalar#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/DataWorks SqlCommand.ExecuteScalar/VB/source.vb#1)] + [!code-csharp[DataWorks SqlCommand.ExecuteScalar#1](~/sqlClient/doc/samples SqlCommand.ExecuteScalar/CS/source.cs#1)] ]]> @@ -1659,8 +1658,7 @@ ## Examples The following example creates a and then executes it using . The example is passed a string that is a Transact-SQL FOR XML SELECT statement, and a string to use to connect to the data source. - [!code-csharp[Classic WebData SqlCommand.ExecuteXmlReader#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteXmlReader/CS/mysample.cs#1)] - [!code-vb[Classic WebData SqlCommand.ExecuteXmlReader#1](~/samples/snippets/visualbasic/VS_Snippets_ADO.NET/Classic WebData SqlCommand.ExecuteXmlReader/VB/mysample.vb#1)] + [!code-csharp[SqlCommand.ExecuteXmlReader](~/sqlClient/doc/samples SqlCommand_ExecuteXmlReader.cs)] ]]> @@ -1818,7 +1816,7 @@ ## Examples The following example demonstrates how to create a and add parameters to the . - [!code-csharp[DataWorks SqlParameterCollection.AddWithValue#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/DataWorks SqlParameterCollection.AddWithValue/CS/source.cs#1)] + [!code-csharp[SqlParameterCollection.AddWithValue](~/sqlClient/doc/snippets SqlParameterCollection.AddWithValue.cs)] ]]> @@ -1845,7 +1843,7 @@ ## Examples The following example demonstrates the use of the method. - [!code-csharp[Classic WebData SqlCommand.Prepare#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommand.Prepare/CS/Source.cs#1)] + [!code-csharp[SqlCommand.Prepare](~/sqlClient/doc/snippets SqlCommand_Prepare.cs)] ]]> diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml index 29ad8377c8..36ca36d0b8 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlCommandBuilder.xml @@ -24,7 +24,7 @@ ## Examples The following example uses the , along and , to select rows from a data source. The example is passed a connection string, a query string that is a Transact-SQL SELECT statement, and a string that is the name of the database table. The example then creates a . - [!code-csharp[Classic WebData SqlCommandBuilder#1](~/samples/snippets/csharp/VS_Snippets_ADO.NET/Classic WebData SqlCommandBuilder/CS/Source.cs#1)] + [!code-csharp[SqlCommandBuilder#1](~/sqlClient/doc/samples/ SqlCommandBuilder/CS/Source.cs)] ]]> From 3f99652d962e91727e1327751daed0f46c319c17 Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 20 Sep 2019 10:14:46 -0700 Subject: [PATCH 7/9] adding new line --- doc/samples/SqlParameterCollection_Add.cs | 2 +- doc/samples/SqlParameterCollection_Add1.cs | 2 +- doc/samples/SqlParameterCollection_Add3.cs | 2 +- doc/samples/SqlParameterCollection_Add5.cs | 2 +- doc/samples/SqlParameterCollection_Add6.cs | 2 +- doc/samples/SqlParameterCollection_Count.cs | 2 +- doc/samples/SqlParameterCollection_Remove.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/doc/samples/SqlParameterCollection_Add.cs b/doc/samples/SqlParameterCollection_Add.cs index 0a22a5eda9..cb03a57e27 100644 --- a/doc/samples/SqlParameterCollection_Add.cs +++ b/doc/samples/SqlParameterCollection_Add.cs @@ -10,4 +10,4 @@ public void AddSqlParameter(SqlCommand command) command.Parameters.Add(new SqlParameter("Description", "Beverages")); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameterCollection_Add1.cs b/doc/samples/SqlParameterCollection_Add1.cs index 1042727cef..6af67ef415 100644 --- a/doc/samples/SqlParameterCollection_Add1.cs +++ b/doc/samples/SqlParameterCollection_Add1.cs @@ -13,4 +13,4 @@ public void AddSqlParameter(SqlCommand command) command.Parameters.Add(param); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameterCollection_Add3.cs b/doc/samples/SqlParameterCollection_Add3.cs index d8e6a87877..9feff70a03 100644 --- a/doc/samples/SqlParameterCollection_Add3.cs +++ b/doc/samples/SqlParameterCollection_Add3.cs @@ -13,4 +13,4 @@ public void AddSqlParameter(SqlCommand command) param.Value = "Beverages"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameterCollection_Add5.cs b/doc/samples/SqlParameterCollection_Add5.cs index 8e246e31a7..661a665f36 100644 --- a/doc/samples/SqlParameterCollection_Add5.cs +++ b/doc/samples/SqlParameterCollection_Add5.cs @@ -10,4 +10,4 @@ public void AddSqlParameter(SqlCommand cmd) SqlParameter p1 = cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 16, "Description"); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameterCollection_Add6.cs b/doc/samples/SqlParameterCollection_Add6.cs index f2c8502551..8ce73cf5dc 100644 --- a/doc/samples/SqlParameterCollection_Add6.cs +++ b/doc/samples/SqlParameterCollection_Add6.cs @@ -27,4 +27,4 @@ public void AddSqlParameters() } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameterCollection_Count.cs b/doc/samples/SqlParameterCollection_Count.cs index 7f20fa7b32..e9e5224236 100644 --- a/doc/samples/SqlParameterCollection_Count.cs +++ b/doc/samples/SqlParameterCollection_Count.cs @@ -72,4 +72,4 @@ static private string GetConnectionString() "Integrated Security=SSPI"; } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameterCollection_Remove.cs b/doc/samples/SqlParameterCollection_Remove.cs index a5790ff631..f4fbc7f06d 100644 --- a/doc/samples/SqlParameterCollection_Remove.cs +++ b/doc/samples/SqlParameterCollection_Remove.cs @@ -22,4 +22,4 @@ public void SearchSqlParams() command.Parameters.Remove(param); } } -// \ No newline at end of file +// From 14216bc2eb6ea3b6cd592c2007370105e4acf8d1 Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 20 Sep 2019 10:20:05 -0700 Subject: [PATCH 8/9] edit --- doc/samples/SqlParameter_SqlParameter.cs | 2 +- doc/samples/SqlParameter_SqlParameter1.cs | 2 +- doc/samples/SqlParameter_SqlParameter2.cs | 2 +- doc/samples/SqlParameter_SqlParameter5.cs | 2 +- doc/samples/SqlParameter_SqlParameter6.cs | 4 ++-- doc/samples/SqlRowUpdatingEventArgs.cs | 2 +- doc/samples/TransactionIsolationLevels.cs | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/samples/SqlParameter_SqlParameter.cs b/doc/samples/SqlParameter_SqlParameter.cs index 8039855e3b..ed2b909323 100644 --- a/doc/samples/SqlParameter_SqlParameter.cs +++ b/doc/samples/SqlParameter_SqlParameter.cs @@ -20,4 +20,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameter_SqlParameter1.cs b/doc/samples/SqlParameter_SqlParameter1.cs index 9641778d52..7d3567364d 100644 --- a/doc/samples/SqlParameter_SqlParameter1.cs +++ b/doc/samples/SqlParameter_SqlParameter1.cs @@ -19,4 +19,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameter_SqlParameter2.cs b/doc/samples/SqlParameter_SqlParameter2.cs index a589f3dc8c..0519e133ba 100644 --- a/doc/samples/SqlParameter_SqlParameter2.cs +++ b/doc/samples/SqlParameter_SqlParameter2.cs @@ -19,4 +19,4 @@ private static void AddSqlParameter(SqlCommand command, string paramValue) command.Parameters.Add(parameter); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameter_SqlParameter5.cs b/doc/samples/SqlParameter_SqlParameter5.cs index 964723ba1d..153ff32d19 100644 --- a/doc/samples/SqlParameter_SqlParameter5.cs +++ b/doc/samples/SqlParameter_SqlParameter5.cs @@ -18,4 +18,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlParameter_SqlParameter6.cs b/doc/samples/SqlParameter_SqlParameter6.cs index 5034ad68d7..153ff32d19 100644 --- a/doc/samples/SqlParameter_SqlParameter6.cs +++ b/doc/samples/SqlParameter_SqlParameter6.cs @@ -10,7 +10,7 @@ static void Main() } private static void AddSqlParameter(SqlCommand command) { - SqlParameter parameter = new SqlParameter("@Description", + SqlParameter parameter = new SqlParameter("@Description", SqlDbType.VarChar, 88, "Description"); parameter.IsNullable = true; parameter.Direction = ParameterDirection.Output; @@ -18,4 +18,4 @@ private static void AddSqlParameter(SqlCommand command) command.Parameters.Add(parameter); } } -// \ No newline at end of file +// diff --git a/doc/samples/SqlRowUpdatingEventArgs.cs b/doc/samples/SqlRowUpdatingEventArgs.cs index b16f0c94f6..554adccc0a 100644 --- a/doc/samples/SqlRowUpdatingEventArgs.cs +++ b/doc/samples/SqlRowUpdatingEventArgs.cs @@ -72,4 +72,4 @@ private static void PrintEventArgs(SqlRowUpdatedEventArgs args) " status=" + args.Status + ")"); } } -// \ No newline at end of file +// diff --git a/doc/samples/TransactionIsolationLevels.cs b/doc/samples/TransactionIsolationLevels.cs index dc85d9447b..4cca4ab684 100644 --- a/doc/samples/TransactionIsolationLevels.cs +++ b/doc/samples/TransactionIsolationLevels.cs @@ -525,4 +525,4 @@ internal static void Main(string[] args) } } } -// \ No newline at end of file +// From f597659578b73ba44c2d56988cd9a0bacbcbe3d7 Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 20 Sep 2019 11:09:17 -0700 Subject: [PATCH 9/9] missing classes --- doc/samples/SqlBulkCopy_DataTable.cs | 116 +++++++++++++++++ doc/samples/SqlBulkCopy_OrdersDetails.cs | 154 +++++++++++++++++++++++ 2 files changed, 270 insertions(+) create mode 100644 doc/samples/SqlBulkCopy_DataTable.cs create mode 100644 doc/samples/SqlBulkCopy_OrdersDetails.cs diff --git a/doc/samples/SqlBulkCopy_DataTable.cs b/doc/samples/SqlBulkCopy_DataTable.cs new file mode 100644 index 0000000000..a3c8c98fae --- /dev/null +++ b/doc/samples/SqlBulkCopy_DataTable.cs @@ -0,0 +1,116 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a connection to the AdventureWorks database. + using (SqlConnection connection = + new SqlConnection(connectionString)) + { + connection.Open(); + + // Perform an initial count on the destination table. + SqlCommand commandRowCount = new SqlCommand( + "SELECT COUNT(*) FROM " + + "dbo.BulkCopyDemoMatchingColumns;", + connection); + long countStart = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Starting row count = {0}", countStart); + + // Create a table with some rows. + DataTable newProducts = MakeTable(); + + // Create the SqlBulkCopy object. + // Note that the column positions in the source DataTable + // match the column positions in the destination table so + // there is no need to map columns. + using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connection)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoMatchingColumns"; + + try + { + // Write from the source to the destination. + bulkCopy.WriteToServer(newProducts); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + // Perform a final count on the destination + // table to see how many rows were added. + long countEnd = System.Convert.ToInt32( + commandRowCount.ExecuteScalar()); + Console.WriteLine("Ending row count = {0}", countEnd); + Console.WriteLine("{0} rows were added.", countEnd - countStart); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + + private static DataTable MakeTable() + // Create a new DataTable named NewProducts. + { + DataTable newProducts = new DataTable("NewProducts"); + + // Add three column objects to the table. + DataColumn productID = new DataColumn(); + productID.DataType = System.Type.GetType("System.Int32"); + productID.ColumnName = "ProductID"; + productID.AutoIncrement = true; + newProducts.Columns.Add(productID); + + DataColumn productName = new DataColumn(); + productName.DataType = System.Type.GetType("System.String"); + productName.ColumnName = "Name"; + newProducts.Columns.Add(productName); + + DataColumn productNumber = new DataColumn(); + productNumber.DataType = System.Type.GetType("System.String"); + productNumber.ColumnName = "ProductNumber"; + newProducts.Columns.Add(productNumber); + + // Create an array for DataColumn objects. + DataColumn[] keys = new DataColumn[1]; + keys[0] = productID; + newProducts.PrimaryKey = keys; + + // Add some new rows to the collection. + DataRow row = newProducts.NewRow(); + row["Name"] = "CC-101-WH"; + row["ProductNumber"] = "Cyclocomputer - White"; + + newProducts.Rows.Add(row); + row = newProducts.NewRow(); + row["Name"] = "CC-101-BK"; + row["ProductNumber"] = "Cyclocomputer - Black"; + + newProducts.Rows.Add(row); + row = newProducts.NewRow(); + row["Name"] = "CC-101-ST"; + row["ProductNumber"] = "Cyclocomputer - Stainless"; + newProducts.Rows.Add(row); + newProducts.AcceptChanges(); + + // Return the new DataTable. + return newProducts; + } + private static string GetConnectionString() + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +// diff --git a/doc/samples/SqlBulkCopy_OrdersDetails.cs b/doc/samples/SqlBulkCopy_OrdersDetails.cs new file mode 100644 index 0000000000..9fd713a548 --- /dev/null +++ b/doc/samples/SqlBulkCopy_OrdersDetails.cs @@ -0,0 +1,154 @@ +using System; +using System.Data; +// +using Microsoft.Data.SqlClient; + +class Program +{ + static void Main() + { + string connectionString = GetConnectionString(); + // Open a connection to the AdventureWorks database. + using (SqlConnection connection = + new SqlConnection(connectionString)) + { + connection.Open(); + + // Empty the destination tables. + SqlCommand deleteHeader = new SqlCommand( + "DELETE FROM dbo.BulkCopyDemoOrderHeader;", + connection); + deleteHeader.ExecuteNonQuery(); + SqlCommand deleteDetail = new SqlCommand( + "DELETE FROM dbo.BulkCopyDemoOrderDetail;", + connection); + deleteDetail.ExecuteNonQuery(); + + // Perform an initial count on the destination + // table with matching columns. + SqlCommand countRowHeader = new SqlCommand( + "SELECT COUNT(*) FROM dbo.BulkCopyDemoOrderHeader;", + connection); + long countStartHeader = System.Convert.ToInt32( + countRowHeader.ExecuteScalar()); + Console.WriteLine( + "Starting row count for Header table = {0}", + countStartHeader); + + // Perform an initial count on the destination + // table with different column positions. + SqlCommand countRowDetail = new SqlCommand( + "SELECT COUNT(*) FROM dbo.BulkCopyDemoOrderDetail;", + connection); + long countStartDetail = System.Convert.ToInt32( + countRowDetail.ExecuteScalar()); + Console.WriteLine( + "Starting row count for Detail table = {0}", + countStartDetail); + + // Get data from the source table as a SqlDataReader. + // The Sales.SalesOrderHeader and Sales.SalesOrderDetail + // tables are quite large and could easily cause a timeout + // if all data from the tables is added to the destination. + // To keep the example simple and quick, a parameter is + // used to select only orders for a particular account + // as the source for the bulk insert. + SqlCommand headerData = new SqlCommand( + "SELECT [SalesOrderID], [OrderDate], " + + "[AccountNumber] FROM [Sales].[SalesOrderHeader] " + + "WHERE [AccountNumber] = @accountNumber;", + connection); + SqlParameter parameterAccount = new SqlParameter(); + parameterAccount.ParameterName = "@accountNumber"; + parameterAccount.SqlDbType = SqlDbType.NVarChar; + parameterAccount.Direction = ParameterDirection.Input; + parameterAccount.Value = "10-4020-000034"; + headerData.Parameters.Add(parameterAccount); + SqlDataReader readerHeader = headerData.ExecuteReader(); + + // Get the Detail data in a separate connection. + using (SqlConnection connection2 = new SqlConnection(connectionString)) + { + connection2.Open(); + SqlCommand sourceDetailData = new SqlCommand( + "SELECT [Sales].[SalesOrderDetail].[SalesOrderID], [SalesOrderDetailID], " + + "[OrderQty], [ProductID], [UnitPrice] FROM [Sales].[SalesOrderDetail] " + + "INNER JOIN [Sales].[SalesOrderHeader] ON [Sales].[SalesOrderDetail]." + + "[SalesOrderID] = [Sales].[SalesOrderHeader].[SalesOrderID] " + + "WHERE [AccountNumber] = @accountNumber;", connection2); + + SqlParameter accountDetail = new SqlParameter(); + accountDetail.ParameterName = "@accountNumber"; + accountDetail.SqlDbType = SqlDbType.NVarChar; + accountDetail.Direction = ParameterDirection.Input; + accountDetail.Value = "10-4020-000034"; + sourceDetailData.Parameters.Add(accountDetail); + SqlDataReader readerDetail = sourceDetailData.ExecuteReader(); + + // Create the SqlBulkCopy object. + using (SqlBulkCopy bulkCopy = + new SqlBulkCopy(connectionString)) + { + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoOrderHeader"; + + // Write readerHeader to the destination. + try + { + bulkCopy.WriteToServer(readerHeader); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + readerHeader.Close(); + } + + // Set up a different destination and + // map columns. + bulkCopy.DestinationTableName = + "dbo.BulkCopyDemoOrderDetail"; + + // Write readerDetail to the destination. + try + { + bulkCopy.WriteToServer(readerDetail); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + finally + { + readerDetail.Close(); + } + } + + // Perform a final count on the destination + // tables to see how many rows were added. + long countEndHeader = System.Convert.ToInt32( + countRowHeader.ExecuteScalar()); + Console.WriteLine("{0} rows were added to the Header table.", + countEndHeader - countStartHeader); + long countEndDetail = System.Convert.ToInt32( + countRowDetail.ExecuteScalar()); + Console.WriteLine("{0} rows were added to the Detail table.", + countEndDetail - countStartDetail); + Console.WriteLine("Press Enter to finish."); + Console.ReadLine(); + } + } + } + + private static string GetConnectionString() + // To avoid storing the connection string in your code, + // you can retrieve it from a configuration file. + { + return "Data Source=(local); " + + " Integrated Security=true;" + + "Initial Catalog=AdventureWorks;"; + } +} +//